RPGs3_card_insanity/Makefile
2019-09-11 05:09:42 +02:00

79 lines
2.2 KiB
Makefile

all: build/card.html build/card_rendered.html
.PHONY: dev
dev:
git ls-files | entr bash -c "make all"
.PHONY: clean
clean:
rm build/*
build/card.html: build/card.xml build/style.xsl
xsltproc \
-o build/card.html \
build/style.xsl \
build/card.xml
define PYTHON_MAKE_RENDERED_CARD
from jinja2 import Environment, FileSystemLoader
from markdown import markdown
import yaml
with open("card.yaml") as f: data = f.read()
with open("build/card_rendered.html", "w") as f:
e = Environment(trim_blocks=True, lstrip_blocks=True, loader=FileSystemLoader(''))
e.filters.update({
"markdown":markdown,
"any":any,
"all":all,
"cull_whitespace":(lambda x: " ".join(x.split())) })
f.write(e.get_template('style.html.j2').render(card=yaml.load(data)))
endef
export PYTHON_MAKE_RENDERED_CARD
build/card_rendered.html: card.yaml style.html.j2
python3 -c "$$PYTHON_MAKE_RENDERED_CARD"
define PYTHON_MAKE_CARD_XML
from jinja2 import Environment, FileSystemLoader
with open("card.yaml") as f: data = f.read()
with open("build/card.xml", "w") as f:
f.write(Environment(
loader=FileSystemLoader('templates'))
.get_template('card.xml.j2')
.render(data=data))
endef
export PYTHON_MAKE_CARD_XML
build/card.xml: card.yaml templates/card.xml.j2
python3 -c "$$PYTHON_MAKE_CARD_XML"
define PYTHON_MAKE_STYLE_XSL
from jinja2 import Environment, FileSystemLoader
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()
with open("build/style.xsl", "w") as f:
f.write(Environment(
trim_blocks=True,
lstrip_blocks=True,
loader=FileSystemLoader('templates'))
.get_template('style.xsl.j2')
.render( css_data=css_data, jinja_data=jinja_data, js_data=js_data))
endef
export PYTHON_MAKE_STYLE_XSL
build/style.xsl: build/style.css templates/style.xsl.j2 style.html.j2 style.js
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"