Skip to content

Commit

Permalink
Implemented default globals
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Apr 4, 2017
1 parent 5072abd commit cfe3e83
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 46 deletions.
112 changes: 68 additions & 44 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,36 @@
include make.d/config.make

########################################################################
# Variables
# Globals
########################################################################

# Metadata directory
Metadata := .yummy

# Output directory
Destination := /tmp/jqt
# Load global parameters
-include $(Metadata)/globals.make

# Input files directories
Assets := ./assets
Blocks := ./blocks
Content := ./content
Data := ./data
Layouts := ./blocks
Styles := ./styles
# Defined in globals.make:
# __globals__
# Assets
# Blocks
# Content
# Data
# Destination
# Layouts
# Styles

# Files to build or publish
Home := index
Other := content data engine structure
Static := styles.css

# Target filenames
ManPage := ../jqt.1.gz
HomePage := $(Destination)/$(Home).html
OtherPages := $(foreach p,$(Other),$(Destination)/$(p).html)
Files := $(foreach f,$(Static),$(Destination)/$(f))
Pages := $(HomePage) $(OtherPages)
Targets := $(Pages) $(Files) $(ManPage)
# Include metadata
include make.d/metadata.make

########################################################################
# jqt command with options
########################################################################

ifdef __globals__

# jqt with options
JQTFLAGS := \
JQTFLAGS = \
-5 \
-I./ \
-iblocks/filters \
Expand All @@ -49,7 +43,7 @@ JQTFLAGS := \
JQT = jqt $(JQTFLAGS)

# gpp for the man page (to be build without calling jqt!)
GPP_MD_FLAGS := \
GPP_MD := gpp \
-U '<%' '>' '\B' '\B' '\W>' '<' '>' '$$' '' \
-M '<%' '>' '\B' '\B' '\W>' '<' '>' \
+sccc '&\n' '' '' \
Expand All @@ -62,19 +56,39 @@ GPP_MD_FLAGS := \
+ssss '\n```' '\n```' '' \
+ssss '\n~~~' '\n~~~' '' \
GPP_MD = gpp $(GPP_MD_FLAGS)

# hack to modify <detail> markup
DETAILS := sed \
-e 's/^<p><details><\/p>/<details>/' \
-e 's/^<p><\/details><\/p>/<\/details>/'\
-e 's/^<p><summary>/<summary>/' \
-e 's/<\/summary><\/p>/<\/summary>/'

endif # __globals__

########################################################################
# Extra dependencies
# Pages and other files to generate
########################################################################

ifdef __globals__

# Files to build or publish
Home := index
Other := content data engine structure
Static := styles.css
JQT_Man := jqt.1

# Target filenames
HomePage := $(Destination)/$(Home).html
OtherPages := $(foreach p,$(Other),$(Destination)/$(p).html)
Files := $(foreach f,$(Static),$(Destination)/$(f))
Pages := $(HomePage) $(OtherPages)
ManPage := ../$(JQT_Man).gz
Targets := $(Pages) $(Files) $(ManPage)

#
# Extra dependencies
#

$(Pages): \
$(Blocks)/*/markup.html \
$(Blocks)/filters.jq \
Expand All @@ -99,23 +113,26 @@ $(Destination)/styles.css: \
$(Styles)/*.m \
$(Styles)/milligram/*.css \

endif # __globals__

########################################################################
# Rules
########################################################################

all: $(Targets) cp_assets
ifdef __globals__

# Default target
all: $(Targets) static

# Destination directory
$(Destination):
$(info ==> $@)
mkdir $@ >/dev/null 2>&1 || true

# Copy assets
cp_assets: | $(Destination)
cp --verbose --recursive --update $(Assets)/* $(Destination)

# Include metadata
include make.d/metadata.make
static: | $(Destination)
cp --verbose --recursive --update $(Assets)/* $(Destination) \
| sed "s/^.*-> ./==> /;s/.$$//"

# Snippets
$(Metadata)/snippets.json: $(Content)/snippets.yaml \
Expand All @@ -140,27 +157,20 @@ $(Destination)/styles.css: $(Styles)/page.css
jqt -P CSS-min -I$(Styles) < $< > $@

# Man page: jqt(1)
$(ManPage): $(Content)/jqt.1.markdown
$(ManPage): $(Content)/$(JQT_Man).markdown
$(info ==> $@)
$(GPP_MD) -I$(Content) < $< \
| pandoc --standalone --from markdown --to man \
| gzip > $@

endif # __globals__

########################################################################
# Utilities
########################################################################

.PHONY: clean clobber build help valid lint

clean:
rm -rf $(Destination)/* $(ManPage)

clobber: clean
rm -rf $(Destination) $(Metadata)

build: clean all

# Show targets
.PHONY: help
help:
echo 'Targets:'; \
$(MAKE) --print-data-base --just-print 2>&1 \
Expand All @@ -170,6 +180,18 @@ help:
| sed 's/:\+$$//' \
| pr --omit-pagination --indent=4 --width=80 --columns=4

ifdef __globals__

.PHONY: clean clobber build valid lint

clean:
rm -rf $(Destination)/* $(ManPage)

clobber: clean
rm -rf $(Destination) $(Metadata)

build: clean all

# Validation using vnu.jar
VNU := /usr/local/vnu/vnu.jar
valid: all
Expand All @@ -189,4 +211,6 @@ lint: all
| sed '1,7b;/^$$/d;s/_\([A-Z]\+\)_/\1/g;/^[^A-Z]/s/^/ /' \
> $@

endif # __globals__

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make
21 changes: 21 additions & 0 deletions docs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,27 @@
# other elements, and is available in the .site top-level variable.
#

#
# Global parameters
#

# Default values:
#
# Destination: ./_site
# Assets: ./assets
# Blocks: ./blocks
# Content: ./content
# Data: ./data
# Layouts: ./layouts
# Styles: ./styles

# Changes from defaults
Destination: /tmp/jqt # fast RAM disk
Layouts: ./blocks # shared space

#
# Site parameters
#

title: jqt, the jq template engine
baseURL: https://fadado.github.com/jqt/
Expand All @@ -17,6 +37,7 @@ author:
- email: [email protected]
name: Joan Josep Ordinas Rosa

# TODO: instrospect
menu:
- URL: ./index.html
path: content/index.md
Expand Down
46 changes: 44 additions & 2 deletions docs/make.d/metadata.make
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ $(Metadata):
$(info ==> $@)
mkdir $@ >/dev/null 2>&1 || true

#
# Configuration files
#

# Members to mix with config.yaml when converted to JSON
define JSON_GLOBALS :=
. + { \
Destination: (.Destination // "./_site"), \
Assets: (.Assets // "./assets"), \
Blocks: (.Blocks // "./blocks"), \
Content: (.Content // "./content"), \
Data: (.Data // "./data"), \
Layouts: (.Layouts // "./layouts"), \
Styles: (.Styles // "./styles") \
}
endef

# Main configuration file.
# Must be named config.yaml or config.json and must exist.
ifeq (config.yaml, $(wildcard config.yaml))
Expand All @@ -18,18 +35,43 @@ ifeq (config.yaml, $(wildcard config.yaml))
$(Metadata)/config.json: config.yaml \
| $(Metadata)
$(info ==> $@)
yaml2json < $< > $@
yaml2json < $< \
| jq --sort-keys '$(JSON_GLOBALS)' > $@

else ifeq (config.json, $(wildcard config.json))

# Convert config.json to $(Metadata)/config.json
$(Metadata)/config.json: config.json \
| $(Metadata)
$(info ==> $@)
jqt -Pjson < $< > $@
jqt -Pjson < $< \
| jq --sort-keys '$(JSON_GLOBALS)' > $@

else
$(error Configuration file not found)
endif

# Variables to define in globals.make
define MAKE_GLOBALS :=
"# vim:syntax=make", \
"", \
"__globals__ := 1", \
"Destination := " + .Destination, \
"Assets := " + .Assets, \
"Blocks := " + .Blocks, \
"Content := " + .Content, \
"Data := " + .Data, \
"Layouts := " + .Layouts, \
"Styles := " + .Styles, \
""
endef

# Create makefile with globals
$(Metadata)/globals.make: $(Metadata)/config.json
$(info ==> $@)
jq --sort-keys \
--raw-output \
'$(MAKE_GLOBALS)' \
< $< > $@

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make

0 comments on commit cfe3e83

Please sign in to comment.