Skip to content

Commit

Permalink
Automatized data files
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Apr 20, 2017
1 parent da8282c commit e2381d7
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 91 deletions.
20 changes: 12 additions & 8 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
# Make configuration
include make.d/prelude.make

# Metadata directory
Metadata := .meta

# jqt version
Version := 0.5.1

# Metadata directory
Metadata := .meta

# Do not build to clobber immediately
ifeq (clobber,$(MAKECMDGOALS))
ifeq (,$(wildcard $(Metadata)))
Expand Down Expand Up @@ -61,10 +61,14 @@ ifdef __phase_1

# ======================================================================
-include $(Metadata)/phase2.make
include make.d/pathnames.make
include make.d/data.make
#
# Variables defined in phase2.make:
# __phase_2
# DataCSV
# DataJSON
# DataMD
# DataYAML
# DestinationPages
# DestinationPaths
# MetadataPages
Expand All @@ -76,6 +80,8 @@ ifdef __phase_1
# $(MetadataPages)
# $(Metadata)/pages.json
# $(Metadata)/sections.json
# Defined targets:
# init
# ======================================================================

ifdef __phase_2
Expand All @@ -84,8 +90,7 @@ ifdef __phase_2
-include $(Metadata)/phase3.make
include make.d/pages.make
#
# Load rules for pages and nodes. If not exists is built when restarting with
# rule defined in `pages.make`.
# Load rules for pages and nodes.
#
# Variables defined in phase3.make:
# __phase_3
Expand All @@ -98,7 +103,6 @@ ifdef __phase_2
# clean
# clobber
# fresh
# init
# touch
# ======================================================================

Expand All @@ -122,7 +126,7 @@ include make.d/tools.make
# ======================================================================

########################################################################
include jqt.make
include project.make
#
# Project specific makefile. All the previous modules are expected to be
# independent, valid for any project without any change.
Expand Down
58 changes: 54 additions & 4 deletions docs/make.d/pathnames.make → docs/make.d/data.make
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
########################################################################
# pathnames.make
# data.make
#
# Build metadata from filesystem introspection.
#
# Variables defined in phase2.make:
# __phase_2
# DataCSV
# DataJSON
# DataMD
# DataYAML
# DestinationPages
# DestinationPaths
# MetadataPages
Expand All @@ -16,13 +20,16 @@
# $(MetadataPages)
# $(Metadata)/pages.json
# $(Metadata)/sections.json
# $(DataFiles)
# Targets:
# init

########################################################################
# Create makefile defining global variables about pathnames and rules to
# generate JSON metadata files for each page.
########################################################################

$(Metadata)/phase2.make: make.d/pathnames.make make.d/phase2.jq $(Metadata)/phase1.make
$(Metadata)/phase2.make: make.d/data.make make.d/phase2.jq $(Metadata)/phase1.make
$(info ==> $@)
@find $(Content) -type f -a \
-name '[!_]*.md' -o \
Expand All @@ -34,6 +41,7 @@ $(Metadata)/phase2.make: make.d/pathnames.make make.d/phase2.jq $(Metadata)/phas
--from-file make.d/phase2.jq \
--arg DF "$$(find $(Data) -name '*.*')" \
--arg Content $(Content) \
--arg Data $(Data) \
--arg Destination $(Destination) \
--arg Metadata $(Metadata) \
> $@
Expand Down Expand Up @@ -68,10 +76,9 @@ endef

$(DestinationPages): $(Destination)/%.html : $(Metadata)/pages/%.json
$(DestinationPages): $(Layouts)/default.html
$(DestinationPages): | $$(dir $$@)

$(MetadataPages): $(Metadata)/config.json

$(DestinationPages): | $$(dir $$@)
$(MetadataPages): | $$(dir $$@)

########################################################################
Expand Down Expand Up @@ -100,6 +107,49 @@ $(Metadata)/sections.json: $(Metadata)/pages.json
$(info ==> $@)
@jq '[.[].section] | unique | map(select(.))' < $< > $@

########################################################################
# Files derived from $(Data)/*
########################################################################

ifneq (,$(DataMD))
$(DataMD): $(Metadata)/%.json : $(Data)/%.md | $(Metadata)
$(info ==> $@)
@jqt -T < $< | yaml2json > $@
endif

ifneq (,$(DataYAML))
$(DataYAML): $(Metadata)/%.json : $(Data)/%.yaml | $(Metadata)
$(info ==> $@)
@yaml2json > $@
endif

ifneq (,$(DataJSON))
$(DataJSON): $(Metadata)/%.json : $(Data)/%.yaml | $(Metadata)
$(info ==> $@)
@jqt -P json < $< > $@
endif

ifneq (,$(DataCSV))
$(DataCSV): $(Metadata)/%.json : $(Data)/%.yaml | $(Metadata)
$(info ==> $@)
@csv2json < $< > $@
endif

DataFiles := $(DataMD) $(DataYAML) $(DataJSON) $(DataCSV)

########################################################################

$(DestinationPages): $(DataFiles)

# make all metadata and data files
init::
ifdef MAKE_RESTARTS
@$(MAKE) -s $(DataFiles)
else
@rm -rf $(Metadata)
@$(MAKE) -s $(DataFiles)
endif

endif # __phase_2

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make
14 changes: 2 additions & 12 deletions docs/make.d/pages.make
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# clean
# clobber
# fresh
# init
# touch

########################################################################
Expand All @@ -28,6 +27,8 @@ $(Metadata)/phase3.make: $(Metadata)/pages.json make.d/pages.make make.d/phase3.
--from-file make.d/phase3.jq \
< $< > $@

ifdef __phase_3

#
# Variables used in $(Metadata)/phase3.make.
#
Expand All @@ -47,8 +48,6 @@ define DETAILS :=
-e 's/<\/summary><\/p>/<\/summary>/'
endef

ifdef __phase_3

########################################################################
# Standard targets
########################################################################
Expand Down Expand Up @@ -89,15 +88,6 @@ touch:
fresh: clobber
@$(MAKE) -s all

# make all metadata except files derived from $(Data)
init::
ifdef MAKE_RESTARTS
@:
else
@rm -rf $(Metadata)
@$(MAKE) -s $(Metadata)/phase3.make
endif

endif # __phase_3

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make
23 changes: 17 additions & 6 deletions docs/make.d/phase2.jq
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# phase2.jq --arg Content $(Content) --arg Destination $(Destination) --arg Metadata $(Metadata) --arg DF "$$(find $(Data) -name '*.*')
# phase2.jq --arg ...
#
# Generate phase2.make from `find` output.

Expand Down Expand Up @@ -50,12 +50,23 @@ def mpages($documents):


def data($files):
def d2m($x):
sub("\\."+$x+"$"; ".json")
| sub("^"+$Data; $Metadata)
;
($files / "\n") as $names
| [($names[] | select(test(".md$")))] as $DataMD
| [($names[] | select(test(".yaml$")))] as $DataYAML
| [($names[] | select(test(".json$")))] as $DataJSON
| [($names[] | select(test(".csv$")))] as $DataCSV
| ""
| [$names[] | select(test(".md$"))] as $DataMD
| [$names[] | select(test(".yaml$"))] as $DataYAML
| [$names[] | select(test(".json$"))] as $DataJSON
| [$names[] | select(test(".csv$"))] as $DataCSV
| if ($DataMD|length) == 0 then "DataMD :=\n"
else "DataMD := " + ($DataMD | map(d2m("md")) | join(" ")) + "\n" end
+ if ($DataYAML|length) == 0 then "DataYAML :=\n"
else "DataYAML := " + ($DataYAML | map(d2m("yaml")) | join(" ")) + "\n" end
+ if ($DataJSON|length) == 0 then "DataJSON :=\n"
else "DataJSON := " + ($DataJSON | map(d2m("json")) | join(" ")) + "\n" end
+ if ($DataCSV|length) == 0 then "DataCSV :=\n"
else "DataCSV := " + ($DataCSV | map(d2m("csv")) | join(" ")) + "\n" end
;

########################################################################
Expand Down
65 changes: 4 additions & 61 deletions docs/jqt.make → docs/project.make
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,21 @@
# Specific makefile for this web site
#
# Defined rules for:
# $(Metadata)/snippets.json
# $(ManPage)
# /tmp/help
# Defined targets:
# all
# clean
# clobber
# init

########################################################################
# Data files
# Build pages options
########################################################################

# Declare explicitly modules with -m, -M or -j; this must be decided by a
# human!
JQTFLAGS += -msnippets:$(Metadata)/snippets.json

# To define in phase2.make from
# find $(Data) -name '*.*'

DataMD := $(Metadata)/snippets.json
DataYAML :=
DataJSON :=
DataCSV :=

# =========================
# To move to pathnames.make
# =========================

#
# Files derived from $(Data)/*
#

ifneq (,$(DataMD))
$(DataMD): $(Metadata)/%.json : $(Data)/%.md | $(Metadata)
$(info ==> $@)
@jqt -T < $< | yaml2json > $@
endif

ifneq (,$(DataYAML))
$(DataYAML): $(Metadata)/%.json : $(Data)/%.yaml | $(Metadata)
$(info ==> $@)
@yaml2json > $@
endif

ifneq (,$(DataJSON))
$(DataJSON): $(Metadata)/%.json : $(Data)/%.yaml | $(Metadata)
$(info ==> $@)
@jqt -P json < $< > $@
endif

ifneq (,$(DataCSV))
$(DataCSV): $(Metadata)/%.json : $(Data)/%.yaml | $(Metadata)
$(info ==> $@)
@csv2json < $< > $@
endif

DataFiles := $(DataMD) $(DataYAML) $(DataJSON) $(DataCSV)

ifneq (,$(DataFiles))

$(DestinationPages): $(DataFiles)

init::
@$(MAKE) -s $(DataFiles)

endif

########################################################################
# Build pages options
########################################################################

# Extra dependencies
#?$(DestinationPages): $(Blocks)/filters.jq $(Blocks)/*/*.html $(Blocks)/*/*/*.html

# Options for `jqt`.
JQTFLAGS += \
-5 \
Expand All @@ -87,6 +27,9 @@ JQTFLAGS += \
# only for derived nodes?
# -msections:$(Metadata)/sections.json \
# Extra dependencies
#?$(DestinationPages): $(Blocks)/filters.jq $(Blocks)/*/*.html $(Blocks)/*/*/*.html

########################################################################
# Generate man page for jqt
########################################################################
Expand Down

0 comments on commit e2381d7

Please sign in to comment.