diff --git a/Makefile b/Makefile index e166a83..5367c2f 100644 --- a/Makefile +++ b/Makefile @@ -146,9 +146,9 @@ define TestJQT test-$(1)-%.jqt: echo "==> jqt: $$(subst test-,,$$(basename $$@))" if test -e tests/jqt/$$(subst test-,,$$(basename $$@)).json; then \ - jqt -ifilters -Ltests/jqt/filters -Mtop:tests/jqt/$$(subst test-,,$$(basename $$@)).json -dtests/jqt/md-00.md tests/jqt/$$(subst test-,,$$@) tests/jqt/generated/$$(subst test-,,$$(basename $$@)).txt; \ + jqt -ifilters -Ltests/jqt/filters -Mtop:tests/jqt/$$(subst test-,,$$(basename $$@)).json -w tests/jqt/$$(subst test-,,$$@) tests/jqt/generated/$$(subst test-,,$$(basename $$@)).txt; \ else \ - jqt -ifilters -Ltests/jqt/filters -dtests/jqt/md-00.md tests/jqt/$$(subst test-,,$$@) tests/jqt/generated/$$(subst test-,,$$(basename $$@)).txt; \ + jqt -ifilters -Ltests/jqt/filters -w tests/jqt/$$(subst test-,,$$@) tests/jqt/generated/$$(subst test-,,$$(basename $$@)).txt; \ fi diff tests/jqt/expected/$$(subst test-,,$$(basename $$@)).txt tests/jqt/generated/$$(subst test-,,$$(basename $$@)).txt # Run one example named without file suffix diff --git a/bin/jqt b/bin/jqt index ecbf3c9..56f225c 100755 --- a/bin/jqt +++ b/bin/jqt @@ -451,19 +451,28 @@ declare -A JSON_DATA_DOT=() YAML_DATA_DOT=() # < stdin > stdout function merge { - local front_matter=$1 - local key + local front_matter key id + local -i without_document=0 + if [[ $1 == '-w' ]]; then + without_document=1 + else + front_matter=$1 + fi local -r script=$(mkpipe) - local id=${DOCUMENT//\//-} - id=${id#-} - id=${id%.*} + { if (( without_document )); then + echo '{}' # dummy object + else + id=${DOCUMENT//\//-} + id=${id#-} + id=${id%.*} + # split . + echo '(. / "") as [$body, $toc, $css] |' + # page + echo "{ $DOCUMENT_METADATA_NAME: ("; yaml2json < $front_matter + echo "+ { _id: \"$id\", _path: \"${DOCUMENT}\", "'_content: $body, _toc: $toc, _highlight: $css })}' + fi - { # split . - echo '(. / "") as [$body, $toc, $css] |' - # page - echo "{ $DOCUMENT_METADATA_NAME: ("; yaml2json < $FRONT_MATTER - echo "+ { _id: \"$id\", _path: \"${DOCUMENT}\", "'_content: $body, _toc: $toc, _highlight: $css })}' # additional data for key in "${!YAML_DATA[@]}"; do echo "+{ $key:" @@ -490,9 +499,14 @@ function merge done } > $script & - jq --raw-input \ - --slurp \ - --from-file $script + if (( without_document )); then + jq --null-input \ + --from-file $script + else + jq --raw-input \ + --slurp \ + --from-file $script + fi } ######################################################################## @@ -624,12 +638,12 @@ EOF ######################################################################## declare -i flagS=0 flagH=0 flagC=0 -declare -i extract=0 remove=0 front_matter=0 snippets=0 +declare -i extract=0 remove=0 front_matter=0 snippets=0 without_document=0 declare expand='' declare opt key filename -while getopts :hVD:I:P:L:i:j:45d:eprtn:m:M:T:CHS-: opt; do +while getopts :hVD:I:P:L:i:j:45d:weprtn:m:M:T:CHS-: opt; do case $opt in # Generic options h) help @@ -674,6 +688,8 @@ while getopts :hVD:I:P:L:i:j:45d:eprtn:m:M:T:CHS-: opt; do ;; t) front_matter=1 ;; + w) without_document=1 + ;; # Data options m|M)[[ $OPTARG == *:* ]] || usage "Bad format in data specification; expected 'key:filename'" key=${OPTARG%:*} filename=${OPTARG#*:} @@ -803,7 +819,7 @@ elif (( flagH )); then expand_md | markup elif (( flagC )); then declare -r FRONT_MATTER=$(mkpipe) expand_md | fork_yaml $FRONT_MATTER | markup | merge $FRONT_MATTER -elif [[ $DOCUMENT == '(standard input)' ]]; then +elif (( !without_document )) && [[ $DOCUMENT == '(standard input)' ]]; then # equivalent to flagH expand_md | markup else @@ -813,14 +829,18 @@ else | convert \ > $RENDER_SCRIPT & - # process document - declare -r FRONT_MATTER=$(mkpipe) - < $DOCUMENT \ - expand_md \ - | fork_yaml $FRONT_MATTER \ - | markup \ - | merge $FRONT_MATTER \ - | render $RENDER_SCRIPT + if (( without_document )); then + merge -w | render $RENDER_SCRIPT + else + # process document + declare -r FRONT_MATTER=$(mkpipe) + < $DOCUMENT \ + expand_md \ + | fork_yaml $FRONT_MATTER \ + | markup \ + | merge $FRONT_MATTER \ + | render $RENDER_SCRIPT + fi fi exit 0 diff --git a/docs/content/engine.md b/docs/content/engine.md index a23f838..639e822 100644 --- a/docs/content/engine.md +++ b/docs/content/engine.md @@ -102,6 +102,7 @@ arguments. The usage possibilities are: <%include content/opt/T.txt> <%include content/opt/t.txt> <%include content/opt/V.txt> +<%include content/opt/w.txt> ## Preprocessing diff --git a/docs/content/help.markdown b/docs/content/help.markdown index 0c9ce9c..b3f1933 100644 --- a/docs/content/help.markdown +++ b/docs/content/help.markdown @@ -21,6 +21,7 @@ Document options: <%include content/opt/4.txt> <%include content/opt/d.txt> +<%include content/opt/w.txt> Data options: diff --git a/docs/content/jqt.1.markdown b/docs/content/jqt.1.markdown index 42ae332..06c89c7 100644 --- a/docs/content/jqt.1.markdown +++ b/docs/content/jqt.1.markdown @@ -42,6 +42,7 @@ where HTML is mixed with **jq** snippets to implement the transformation logic. <%include content/opt/T.txt> <%include content/opt/t.txt> <%include content/opt/V.txt> +<%include content/opt/w.txt> # FILES diff --git a/docs/content/opt/w.txt b/docs/content/opt/w.txt new file mode 100644 index 0000000..4da8957 --- /dev/null +++ b/docs/content/opt/w.txt @@ -0,0 +1,5 @@ +-w +: Build the data model without input document, only from JSON and YAML input files. +<# +vim:ts=4:sw=4:ai:et:fileencoding=utf8:syntax=markdown +#> diff --git a/tests/jqt/expected/macros-00.txt b/tests/jqt/expected/macros-00.txt index 4f7a1a3..48192ce 100644 --- a/tests/jqt/expected/macros-00.txt +++ b/tests/jqt/expected/macros-00.txt @@ -3,13 +3,13 @@ height="315" frameborder="0"> - +/*]]>*/