RPGs3_card_insanity/Makefile

86 lines
2.2 KiB
Makefile

CARDS := $(wildcard cards/*.xml)
CARDS_DESTS := $(patsubst cards/%.xml,cards/build/%.html,$(CARDS))
.PHONY: style
style: build/test_card.html
.PHONY: cards
cards: cards/build/all.html
.PHONY: dev
dev:
git ls-files | entr bash -c "make style"
.PHONY: dev_cards
dev_cards:
git ls-files | entr bash -c "make cards"
.PHONY: clean
clean:
rm -v build/* cards/build/*
build/test_card.html: test_card.xml build/style.xsl build
xsltproc \
-o build/test_card.html \
build/style.xsl \
test_card.xml
cards/build/%.html: cards/%.xml build/style.xsl cards/build
xsltproc -o $@ build/style.xsl $<
define PYTHON_MAKE_IFRAME_HELL
from jinja2 import Environment, FileSystemLoader
import sys, os
env = Environment(
trim_blocks = True,
lstrip_blocks = True,
loader = FileSystemLoader('templates'))
with open("cards/build/all.html", "w") as f:
f.write(env.get_template('all.html.j2').render(cards=map(os.path.basename, sys.argv[1:])))
endef
export PYTHON_MAKE_IFRAME_HELL
cards/build/all.html: $(CARDS_DESTS) templates/all.html.j2
python3 -c "$$PYTHON_MAKE_IFRAME_HELL" $(CARDS_DESTS)
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 build
python3 -c "$$PYTHON_MAKE_STYLE_XSL"
define PYTHON_MAKE_SASS
import sass # libsass
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 build
python3 -c "$$PYTHON_MAKE_SASS"
build:
mkdir -p build
cards/build:
mkdir -p cards/build