2019-09-08 23:07:26 +02:00
|
|
|
|
2019-09-18 22:46:23 +02:00
|
|
|
CARDS := $(wildcard cards/*.yaml)
|
|
|
|
CARDS_DESTS := $(patsubst cards/%.yaml,cards/build/%.html,$(CARDS))
|
|
|
|
|
|
|
|
.PHONY: all
|
2019-09-19 01:00:54 +02:00
|
|
|
all: build/test_card.html build/test_card_rendered.html $(CARDS_DESTS) cards/build/all.html
|
2019-09-08 23:07:26 +02:00
|
|
|
|
2019-10-06 21:43:37 +02:00
|
|
|
.PHONY: style
|
|
|
|
style: build/style.xsl
|
|
|
|
|
2019-09-09 19:07:05 +02:00
|
|
|
.PHONY: dev
|
|
|
|
dev:
|
2019-10-06 21:43:37 +02:00
|
|
|
git ls-files | entr bash -c "make build/test_card.html build/test_card_rendered.html"
|
|
|
|
|
|
|
|
.PHONY: dev_all
|
|
|
|
dev_all:
|
2019-09-09 19:29:27 +02:00
|
|
|
git ls-files | entr bash -c "make all"
|
|
|
|
|
2019-10-06 12:58:50 +02:00
|
|
|
|
2019-09-09 19:07:05 +02:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2019-10-06 21:43:37 +02:00
|
|
|
rm -v build/* cards/build/*
|
2019-09-09 19:07:05 +02:00
|
|
|
|
2019-09-18 22:46:23 +02:00
|
|
|
build/test_card.html: build/card.xml build/style.xsl
|
2019-09-08 23:07:26 +02:00
|
|
|
xsltproc \
|
2019-09-18 22:46:23 +02:00
|
|
|
-o build/test_card.html \
|
2019-09-09 19:07:05 +02:00
|
|
|
build/style.xsl \
|
2019-09-09 18:48:15 +02:00
|
|
|
build/card.xml
|
2019-09-08 23:07:26 +02:00
|
|
|
|
2019-09-11 05:09:42 +02:00
|
|
|
|
2019-09-18 22:46:23 +02:00
|
|
|
define PYTHON_MAKE_JINJA2_RENDERED_CARD
|
2019-09-11 05:09:42 +02:00
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
from markdown import markdown
|
2019-09-19 01:00:54 +02:00
|
|
|
import yaml, sys, glob
|
2019-09-18 22:46:23 +02:00
|
|
|
with open("build/style.css") as f: css_data = f.read()
|
|
|
|
with open(sys.argv[2], "w") as f:
|
2019-09-11 05:09:42 +02:00
|
|
|
e = Environment(trim_blocks=True, lstrip_blocks=True, loader=FileSystemLoader(''))
|
2019-09-19 01:00:54 +02:00
|
|
|
f.write(e.get_template("templates/card_header.html.j2").render(is_local=True, css_data=css_data))
|
2019-09-11 05:09:42 +02:00
|
|
|
e.filters.update({
|
|
|
|
"markdown":markdown,
|
|
|
|
"any":any,
|
|
|
|
"all":all,
|
|
|
|
"cull_whitespace":(lambda x: " ".join(x.split())) })
|
2019-09-19 01:28:13 +02:00
|
|
|
for filename in ([sys.argv[1]] if sys.argv[1] != "ALL" else sorted(glob.glob("cards/*.yaml"))):
|
2019-09-19 01:00:54 +02:00
|
|
|
if sys.argv[1] == "ALL": f.write(f"\n\n<h1>{filename}</h1>\n")
|
|
|
|
with open(filename) as f2: data = f2.read()
|
|
|
|
try:
|
2019-10-06 21:43:37 +02:00
|
|
|
data = e.get_template('style.html.j2').render(card=yaml.load(data), xml={})
|
2019-09-19 01:00:54 +02:00
|
|
|
except Exception as ex:
|
|
|
|
data = f"<pre style=\"color:red;\">{ex}</pre>"
|
|
|
|
f.write("\n" + data)
|
2019-09-11 05:09:42 +02:00
|
|
|
endef
|
2019-09-18 22:46:23 +02:00
|
|
|
|
|
|
|
export PYTHON_MAKE_JINJA2_RENDERED_CARD
|
2019-09-19 02:43:21 +02:00
|
|
|
build/test_card_rendered.html: test_card.yaml style.html.j2 build/style.css templates/card_header.html.j2
|
2019-09-18 22:46:23 +02:00
|
|
|
python3 -c "$$PYTHON_MAKE_JINJA2_RENDERED_CARD" "test_card.yaml" "build/test_card_rendered.html"
|
|
|
|
|
|
|
|
export PYTHON_MAKE_JINJA2_RENDERED_CARD
|
2019-09-19 02:43:21 +02:00
|
|
|
cards/build/%.html: cards/%.yaml style.html.j2 build/style.css templates/card_header.html.j2
|
2019-09-18 22:46:23 +02:00
|
|
|
python3 -c "$$PYTHON_MAKE_JINJA2_RENDERED_CARD" $< $@
|
2019-09-11 05:09:42 +02:00
|
|
|
|
2019-09-19 01:00:54 +02:00
|
|
|
export PYTHON_MAKE_JINJA2_RENDERED_CARD
|
2019-09-19 02:43:21 +02:00
|
|
|
cards/build/all.html: $(CARDS) style.html.j2 build/style.css templates/card_header.html.j2
|
2019-09-19 01:00:54 +02:00
|
|
|
python3 -c "$$PYTHON_MAKE_JINJA2_RENDERED_CARD" ALL $@
|
|
|
|
|
2019-09-11 05:09:42 +02:00
|
|
|
|
2019-09-09 19:07:05 +02:00
|
|
|
define PYTHON_MAKE_CARD_XML
|
2019-09-08 23:07:26 +02:00
|
|
|
from jinja2 import Environment, FileSystemLoader
|
2019-09-18 22:46:23 +02:00
|
|
|
with open("test_card.yaml") as f: data = f.read()
|
2019-10-06 21:43:37 +02:00
|
|
|
with open("test_card.xml") as f: xml_data = f.read()
|
2019-09-09 19:07:05 +02:00
|
|
|
with open("build/card.xml", "w") as f:
|
2019-09-09 23:02:17 +02:00
|
|
|
f.write(Environment(
|
|
|
|
loader=FileSystemLoader('templates'))
|
|
|
|
.get_template('card.xml.j2')
|
2019-10-06 21:43:37 +02:00
|
|
|
.render(data=data, xml_data=xml_data))
|
2019-09-09 19:07:05 +02:00
|
|
|
endef
|
|
|
|
export PYTHON_MAKE_CARD_XML
|
2019-10-06 21:43:37 +02:00
|
|
|
build/card.xml: test_card.yaml test_card.xml templates/card.xml.j2
|
2019-09-09 23:02:17 +02:00
|
|
|
python3 -c "$$PYTHON_MAKE_CARD_XML"
|
2019-09-08 23:07:26 +02:00
|
|
|
|
|
|
|
|
2019-09-09 19:07:05 +02:00
|
|
|
define PYTHON_MAKE_STYLE_XSL
|
|
|
|
from jinja2 import Environment, FileSystemLoader
|
2019-09-09 23:02:17 +02:00
|
|
|
with open("build/style.css") as f: css_data = f.read()
|
|
|
|
with open("style.html.j2") as f: jinja_data = f.read()
|
|
|
|
with open("style.js") as f: js_data = f.read()
|
2019-09-18 22:46:23 +02:00
|
|
|
env = Environment(
|
|
|
|
trim_blocks=True,
|
|
|
|
lstrip_blocks=True,
|
|
|
|
loader=FileSystemLoader('templates'))
|
|
|
|
card_header = env.get_template('card_header.html.j2').render()
|
2019-09-09 19:29:27 +02:00
|
|
|
with open("build/style.xsl", "w") as f:
|
2019-09-18 22:46:23 +02:00
|
|
|
f.write(
|
|
|
|
env.get_template('style.xsl.j2')
|
|
|
|
.render( css_data=css_data, jinja_data=jinja_data, js_data=js_data, card_header=card_header))
|
2019-09-08 23:07:26 +02:00
|
|
|
endef
|
2019-09-09 19:07:05 +02:00
|
|
|
export PYTHON_MAKE_STYLE_XSL
|
2019-09-18 22:46:23 +02:00
|
|
|
build/style.xsl: build/style.css templates/style.xsl.j2 templates/card_header.html.j2 style.html.j2 style.js
|
2019-09-09 23:02:17 +02:00
|
|
|
python3 -c "$$PYTHON_MAKE_STYLE_XSL"
|
|
|
|
|
|
|
|
|
|
|
|
define PYTHON_MAKE_SASS
|
|
|
|
import sass
|
|
|
|
with open("style.scss") as f:
|
|
|
|
with open("build/style.css", "w") as of:
|
|
|
|
of.write(sass.compile(string=f.read(), output_style="expanded"))
|
|
|
|
endef
|
|
|
|
export PYTHON_MAKE_SASS
|
|
|
|
build/style.css: style.scss
|
|
|
|
python3 -c "$$PYTHON_MAKE_SASS"
|