Skip to content

Commit

Permalink
Changed top level object name
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Apr 12, 2017
1 parent 9c45136 commit f6cbc71
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 75 deletions.
30 changes: 10 additions & 20 deletions bin/jqt
Original file line number Diff line number Diff line change
Expand Up @@ -427,23 +427,20 @@ s/tr class="even"/tr/
# Merge document and all data
########################################################################

declare DOCUMENT_METADATA_NAME='page' # front matter and etc.

declare -A JSON_DATA=() YAML_DATA=() YAML_SNIPPETS=()
declare -A JSON_DATA_DOT=() YAML_DATA_DOT=()

# Global objects available in jq scripts:
# .page ...
# .page._content
# .page._highlight
# .page._id
# .page._source
# .page._toc
# ._content
# ._highlight
# ._source
# ._toc
# ._front_matter

# < stdin > stdout
function merge
{
local front_matter key id
local front_matter key
local -i without_document=0
if [[ $1 == '-w' ]]; then
without_document=1
Expand All @@ -455,14 +452,9 @@ function merge
{ 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\", _source: \"${DOCUMENT}\", "'_content: $body, _toc: $toc, _highlight: $css })}'
echo '(. / "<!--JQT-->") as [$body, $toc, $css] | { _front_matter: ('
yaml2json < $front_matter
echo ")} + { _source: \"${DOCUMENT}\", "'_content: $body, _toc: $toc, _highlight: $css }'
fi

# additional data
Expand Down Expand Up @@ -609,7 +601,7 @@ declare expand=''

declare opt key filename

while getopts :hVD:I:P:L:i:j:45d:weprtn:m:M:T:CHS-: opt; do
while getopts :hVD:I:P:L:i:j:45d:weprt:m:M:T:CHS-: opt; do
case $opt in
# Generic options
h) help
Expand Down Expand Up @@ -676,8 +668,6 @@ while getopts :hVD:I:P:L:i:j:45d:weprtn:m:M:T:CHS-: opt; do
fi
fi
;;
n) DOCUMENT_METADATA_NAME=$OPTARG
;;
T) if [[ -z $OPTARG ]]; then
snippets=1
elif [[ $OPTARG == '--' ]]; then
Expand Down
13 changes: 6 additions & 7 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,17 @@ ifdef __html__

# Options for `jqt`.
JQTFLAGS += \
-n document \
-5 \
-I./ \
-j'$$'pages:$(Metadata)/pages \
-msite:$(Metadata)/config.json \
-mpages:$(Metadata)/pages.json \
-msections:$(Metadata)/sections.json \
-5 \
-iblocks/filters \
-msnippets:$(Metadata)/snippets.json \
--toc-depth=4 \
-msnippets:$(Metadata)/snippets.json \

# Snippets
$(Metadata)/snippets.json: $(Content)/snippets.yaml \
$(Metadata)/snippets.json: $(Data)/snippets.yaml \
| $(Metadata)
$(info ==> $@)
@jqt -T < $< | yaml2json > $@
Expand Down Expand Up @@ -230,7 +229,7 @@ GPP_MD := gpp \
ManPage := ../jqt.1.gz

# Man page: jqt(1)
$(ManPage): $(Content)/jqt.1.markdown
$(ManPage): $(Content)/jqt.1.text
$(info ==> $@)
@$(GPP_MD) -I$(Content) < $< \
| pandoc --standalone --from markdown --to man \
Expand All @@ -250,7 +249,7 @@ clobber::
# Independent target: helps generating text for `jqt -h`
# Needs explicit call: `make /tmp/help`
#
/tmp/help: $(Content)/help.markdown
/tmp/help: $(Content)/help.text
$(info ==> $@)
@jqt -P MarkDown -I$(Content) < $< \
| pandoc --from markdown --to plain - \
Expand Down
2 changes: 1 addition & 1 deletion docs/blocks/content/markup.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Content
######################################################################>&
<article class="$content">
{{.document._content}}
{{._content}}
</article>
<#
vim:ts=2:sw=2:ai:et:fileencoding=utf8:syntax=html
Expand Down
4 changes: 2 additions & 2 deletions docs/blocks/default.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<# Top-level page markup #>&
<!DOCTYPE html>
<!-- this document uses polyglot markup (well formed XHTML5) -->
<html id="{{.document._id}}" xmlns="http://www.w3.org/1999/xhtml" lang="{{.page.lang//.site.lang}}" xml:lang="{{.page.lang//.site.lang}}">
<html id="{{.page.id}}" xmlns="http://www.w3.org/1999/xhtml" lang="{{.page.lang//.site.lang}}" xml:lang="{{.page.lang//.site.lang}}">
<head>
<#
# Meta elements
Expand All @@ -19,7 +19,7 @@
<link rel="shortcut icon" href="favicon.ico"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<link rel="stylesheet" type="text/css" href="styles.css"/>
{{.document._highlight}}
{{._highlight}}
</head>
<#
# Document body
Expand Down
4 changes: 2 additions & 2 deletions docs/blocks/menu-bar/markup.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Menu Bar
######################################################################>&
<ol class="menu-bar">
{% .site.menu[] %}
{% $pages::pages[0] as $pages | .site.menu[] %}
<li class='menu-bar__item {{if .==$M.page.id then "menu-bar__item_current" else "" end}}'>
{% (. as $id | $M.pages[] | select($id == .id)) as $page %}
{% (. as $id | $pages[] | select($id == .id)) as $page %}
<a href="{{$page.url}}">{{$page.name}}</a>
{% end %}
</li>
Expand Down
2 changes: 1 addition & 1 deletion docs/blocks/toc/markup.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
######################################################################>&
<nav class="#panel -side-right toc">
<p class="toc__title">{{.snippets."toc-title"}}</p>
{{.document._toc}}
{{._toc}}
</nav>
<#
vim:ts=2:sw=2:ai:et:fileencoding=utf8:syntax=html
Expand Down
10 changes: 5 additions & 5 deletions docs/content/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ Document files contain MarkDown text preceded by an optional YAML front matter.
### Front matter

<%cite jqt> extracts the YAML front matter, located at the very beginning of the file,
and injects it into the render stage under a global JSON object named `.page`.
and injects it into the render stage under a global JSON object named `._front_matter`.

### Body

Pandoc translates the document body to HTML,
and <%cite jqt> injects it into the render stage under the global JSON scalar
`.page._content`. If the document contains fenced code blocks specifying the language of
the code block, the related highlight CSS code will be in the scalar `.page._highlight`. Also, the
HTML table of contents is available in the scalar `.page._toc`, and the path to the document
file in the scalar `.page._source`.
`._content`. If the document contains fenced code blocks specifying the language of
the code block, the related highlight CSS code will be in the scalar `._highlight`. Also, the
HTML table of contents is available in the scalar `._toc`, and the path to the document
file in the scalar `._source`.

### MarkDown snippets

Expand Down
14 changes: 7 additions & 7 deletions docs/content/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ data and influence JSON preprocessing:
<%include content/opt/I.txt>
<%include content/opt/M.txt>
<%include content/opt/m.txt>
<%include content/opt/n.txt>
<%include content/opt/T.txt>

</details>
Expand All @@ -54,14 +53,15 @@ Documents front matter metadata and additional input YAML files are converted to
JSON and merged to be the `jq` input in the render stage. No preprocessing is
applied to YAML data.

The front matter content is available in the global object `.page`. The object
member names prefixed with the underline character (`_`) are reserved, and the following
The front matter content is available in the global object `._front_matter`.
Reserved global names are prefixed with the underline character (`_`), and the following
are provided:

* `.page._content`: the rendered input document.
* `.page._highlight`: CSS styles for highlighted code.
* `.page._source`: the input document pathname as provided to `jqt`.
* `.page._toc`: the rendered input document table of contents.
* `._content`: the rendered input document.
* `._front_matter`: the document front-matter.
* `._highlight`: CSS styles for highlighted code.
* `._source`: the input document pathname as provided to `jqt`.
* `._toc`: the rendered input document table of contents.

Additional JSON files can be provided and are merged with front matter metadata
to be the `jq` input in the render stage.
Expand Down
1 change: 0 additions & 1 deletion docs/content/engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ arguments. The usage possibilities are:
<%include content/opt/L.txt>
<%include content/opt/M.txt>
<%include content/opt/m.txt>
<%include content/opt/n.txt>
<%include content/opt/P.txt>
<%include content/opt/p.txt>
<%include content/opt/r.txt>
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion docs/content/jqt.1.markdown → docs/content/jqt.1.text
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ where HTML is mixed with **jq** snippets to implement the transformation logic.
<%include content/opt/L.txt>
<%include content/opt/M.txt>
<%include content/opt/m.txt>
<%include content/opt/n.txt>
<%include content/opt/P.txt>
<%include content/opt/p.txt>
<%include content/opt/r.txt>
Expand Down
5 changes: 0 additions & 5 deletions docs/content/opt/n.txt

This file was deleted.

Empty file removed docs/data/.gitignore
Empty file.
File renamed without changes.
18 changes: 9 additions & 9 deletions docs/make.d/front-matter.make
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ endef
# Add members to user defined front-matter at `.`.
#
# Defined by jqt:
# .page._id
# .page._content
# .page._highlight
# .page._toc
# .page._source == $1
# Defined here:
# ._content
# ._highlight
# ._toc
# ._source
# ._front_matter
# Defined here (front-matter plus...):
# .page.base
# .page.filename
# .page.id
Expand Down Expand Up @@ -119,15 +119,15 @@ endef
define f_NODE_JSON.jq =
{ \
base: "$(call f_page_base,$1)", \
date: (now | todateiso8601), \
filename: "$(call f_page_name,$1)", \
id: "$(call f_node_id,$1)", \
isnode: true, \
ispage: false, \
path: "$(call f_page_path,$1)", \
section: "$(call f_page_section,$1)", \
url: "$(call f_page_url,$1)", \
date: (now | todateiso8601), \
title: "$(call f_page_name,$1)" \
title: "$(call f_page_name,$1)", \
url: "$(call f_page_url,$1)" \
} as $$node | \
reduce .defaults[] as $$d \
({}; if "$(call f_node_id,$1)" | test("^" + $$d.idprefix) \
Expand Down
23 changes: 14 additions & 9 deletions docs/make.d/pages.make
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
########################################################################
# pages.make
#
# Define rules for HTML pages and nodes.
# Define standard rules and rules for HTML pages and nodes.
#
# Imported variables:
Expand All @@ -16,14 +15,14 @@
# build
# clean
# clobber
# xbuild
# xxbuild
# touch
# fresh

########################################################################
# Standard targets
########################################################################

.PHONY: clean clobber build xbuild xxbuild
.PHONY: clean clobber build touch fresh

# Copy Assets
all:: | $(Destination)
Expand Down Expand Up @@ -51,14 +50,18 @@ define p_test_and_touch.sh
fi
endef

xbuild:
touch:
@$(p_test_and_touch.sh)
@$(MAKE) -s all

# Clobber and build again
xxbuild: clobber
fresh: clobber
@$(MAKE) -s all

init:
@rm -rf $(Metadata)
@$(MAKE) -s $(Metadata)/html.make

########################################################################
# Create makefile containing rules for all HTML files
########################################################################
Expand All @@ -79,14 +82,16 @@ define p_recipe :=
"\t$$(info ==> $$@)\n\t@$$(JQT) -mpage:$(Metadata)/pages/"+.id+".json -d $$< $(Layouts)/"+.layout+".html | $$(p_DETAILS) > $$@"
endef

define p_layouts :=
$(Layouts)/default.html $(Layouts)/"+.layout+".html | $$$$(dir $$$$@)"
endef

# . is $(Metadata)/pages.json
define p_PAGES_D_MAKE.jq :=
"__html__ := 1", \
(.[] | ( \
"$(Destination)/"+.url+": "+(.use|join(" ")), \
"$(Destination)/"+.url+": $(Layouts)/default.html", \
"$(Destination)/"+.url+": $(Layouts)/"+.layout+".html", \
"$(Destination)/"+.url+": | $$$$(dir $$$$@)", \
"$(Destination)/"+.url+": $(p_layouts), \
"$(Destination)/"+.url+": "+.source+"\n"+$(p_recipe) \
)), "# vim:syntax=make"
endef
Expand Down
6 changes: 5 additions & 1 deletion docs/make.d/pathnames.make
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
########################################################################

# Markdown documents found in the filesystem (only `.md` extensions).
i_documents := $(sort $(shell find $(Content) -type f -a -name '*.md'))
#i_suffixes := -name '*.md' -o -name '*.mkd' -o -name '*.markdown'
i_suffixes := -name '*.md'
i_documents := $(sort $(shell find $(Content) -type f -a $(i_suffixes)))

# Unique paths to documents directories.
i_paths := $(sort $(dir $(i_documents)))
Expand Down Expand Up @@ -112,6 +114,8 @@ all:: $(Pages)
@echo 'Destination: $(Destination)'
@echo
@echo 'i_documents: $(i_documents)'
@echo 'i_doc_mkd: $(i_doc_mkd)'
@echo 'i_doc_markdown: $(i_doc_markdown)'
@echo 'i_paths: $(i_paths)'
@echo
@echo 'i_paths_destination: $(i_paths_destination)'
Expand Down
5 changes: 3 additions & 2 deletions docs/make.d/prelude.make
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
########################################################################
# prelude.make
#
# The project prelude: common module available in all makefile modules
########################################################################

#
# Exported macros:
# comma
# empty
Expand Down
1 change: 0 additions & 1 deletion docs/make.d/styles.make
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
########################################################################
# styles.make
########################################################################
#
# Generate main CSS stylesheet.
#
Expand Down
1 change: 0 additions & 1 deletion docs/make.d/tools.make
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
########################################################################
# tools.make
########################################################################
#
# Tools independent of any target.
#
Expand Down

0 comments on commit f6cbc71

Please sign in to comment.