RPGs3_card_insanity/Makefile

102 lines
3.4 KiB
Makefile

CARDS := $(wildcard cards/*.yaml)
CARDS_DESTS := $(patsubst cards/%.yaml,cards/build/%.html,$(CARDS))
.PHONY: all
all: build/test_card.html build/test_card_rendered.html $(CARDS_DESTS) cards/build/all.html
.PHONY: dev
dev:
git ls-files | entr bash -c "make all"
.PHONY: clean
clean:
rm build/* cards/build/*
build/test_card.html: build/card.xml build/style.xsl
xsltproc \
-o build/test_card.html \
build/style.xsl \
build/card.xml
define PYTHON_MAKE_JINJA2_RENDERED_CARD
from jinja2 import Environment, FileSystemLoader
from markdown import markdown
import yaml, sys, glob
with open("build/style.css") as f: css_data = f.read()
with open(sys.argv[2], "w") as f:
e = Environment(trim_blocks=True, lstrip_blocks=True, loader=FileSystemLoader(''))
f.write(e.get_template("templates/card_header.html.j2").render(is_local=True, css_data=css_data))
e.filters.update({
"markdown":markdown,
"any":any,
"all":all,
"cull_whitespace":(lambda x: " ".join(x.split())) })
for filename in ([sys.argv[1]] if sys.argv[1] != "ALL" else sorted(glob.glob("cards/*.yaml"))):
if sys.argv[1] == "ALL": f.write(f"\n\n<h1>{filename}</h1>\n")
with open(filename) as f2: data = f2.read()
try:
data = e.get_template('style.html.j2').render(card=yaml.load(data))
except Exception as ex:
data = f"<pre style=\"color:red;\">{ex}</pre>"
f.write("\n" + data)
endef
export PYTHON_MAKE_JINJA2_RENDERED_CARD
build/test_card_rendered.html: test_card.yaml style.html.j2 build/style.css templates/card_header.html.j2
python3 -c "$$PYTHON_MAKE_JINJA2_RENDERED_CARD" "test_card.yaml" "build/test_card_rendered.html"
export PYTHON_MAKE_JINJA2_RENDERED_CARD
cards/build/%.html: cards/%.yaml style.html.j2 build/style.css templates/card_header.html.j2
python3 -c "$$PYTHON_MAKE_JINJA2_RENDERED_CARD" $< $@
export PYTHON_MAKE_JINJA2_RENDERED_CARD
cards/build/all.html: $(CARDS) style.html.j2 build/style.css templates/card_header.html.j2
python3 -c "$$PYTHON_MAKE_JINJA2_RENDERED_CARD" ALL $@
define PYTHON_MAKE_CARD_XML
from jinja2 import Environment, FileSystemLoader
with open("test_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: test_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()
env = Environment(
trim_blocks=True,
lstrip_blocks=True,
loader=FileSystemLoader('templates'))
card_header = env.get_template('card_header.html.j2').render()
with open("build/style.xsl", "w") as f:
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))
endef
export PYTHON_MAKE_STYLE_XSL
build/style.xsl: build/style.css templates/style.xsl.j2 templates/card_header.html.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"