Skip to content

Commit

Permalink
Implemented -w
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Oct 3, 2016
1 parent afa1f59 commit b607e5d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
68 changes: 44 additions & 24 deletions bin/jqt
Original file line number Diff line number Diff line change
Expand Up @@ -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 '(. / "<!--JQT-->") 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 '(. / "<!--JQT-->") 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:"
Expand All @@ -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
}

########################################################################
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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#*:}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/content/engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions docs/content/help.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Document options:

<%include content/opt/4.txt>
<%include content/opt/d.txt>
<%include content/opt/w.txt>

Data options:

Expand Down
1 change: 1 addition & 0 deletions docs/content/jqt.1.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions docs/content/opt/w.txt
Original file line number Diff line number Diff line change
@@ -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
#>
4 changes: 2 additions & 2 deletions tests/jqt/expected/macros-00.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
height="315"
frameborder="0"></iframe>

<script type="text/javascript">
<script type="text/javascript">/*<![CDATA[*/
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-8673551-2', 'auto');
ga('send', 'pageview');
</script>
/*]]>*/</script>


0 comments on commit b607e5d

Please sign in to comment.