RPGs3_card_insanity/Makefile

134 lines
4.5 KiB
Makefile
Raw Normal View History

2019-09-08 23:07:26 +02:00
CARDS_YAML := $(wildcard cards/*.yaml)
CARDS_XML := $(wildcard cards/*.xml)
CARDS := $(CARDS_YAML) $(CARDS_XML)
CARDS_DESTS_YAML := $(patsubst cards/%.yaml,cards/build/%.html,$(CARDS))
CARDS_DESTS_XML := $(patsubst cards/%.xml,cards/build/%.x.html,$(CARDS))
CARDS_DESTS := $(CARDS_DESTS_YAML) $(CARDS_DESTS_XML)
2019-09-18 22:46:23 +02:00
2019-10-14 21:40:50 +02:00
.PHONY: style
style: build/test_card.html build/test_card_rendered.html cards/build/all.html
.PHONY: cards
cards: $(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-14 21:40:50 +02:00
git ls-files | entr bash -c "make style"
2019-10-06 21:43:37 +02:00
.PHONY: dev_all
dev_cards:
git ls-files | entr bash -c "make cards"
2019-09-09 19:29:27 +02:00
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
build/test_card.html: build/test_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 \
build/test_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-10-14 21:40:50 +02:00
import yaml, sys, glob, traceback
import xmltodict
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,
2019-10-14 21:40:50 +02:00
"split":str.split,
"startswith":str.startswith,
"tail": lambda x: x[1:],
2019-09-11 05:09:42 +02:00
"cull_whitespace":(lambda x: " ".join(x.split())) })
for filename in ([sys.argv[1]] if sys.argv[1] != "ALL" else sorted(glob.glob("cards/*.yaml") + glob.glob("cards/*.xml"))):
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:
if filename.endswith("yaml"):
yaml_data = yaml.load(f2.read())
xml_data = {}
elif filename.endswith("xml"):
xml = xmltodict.parse(f2.read())
xml_data = xml.get("ability_card", {})
yaml_data = yaml.load(xml_data.get("yaml_data", ""))
2019-09-19 01:00:54 +02:00
try:
2019-10-14 21:40:50 +02:00
data = e.get_template('style.html.j2').render(yaml=yaml_data, xml=xml_data)
2019-09-19 01:00:54 +02:00
except Exception as ex:
data = f"<pre style=\"color:red;\">{ex}</pre>"
2019-10-14 21:40:50 +02:00
traceback.print_exc()
2019-09-19 01:00:54 +02:00
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
build/test_card_rendered.html: build/test_card.xml style.html.j2 build/style.css templates/card_header.html.j2
python3 -c "$$PYTHON_MAKE_JINJA2_RENDERED_CARD" "build/test_card.xml" "build/test_card_rendered.html"
2019-09-18 22:46:23 +02:00
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
export PYTHON_MAKE_JINJA2_RENDERED_CARD
cards/build/%.x.html: cards/%.xml style.html.j2 build/style.css templates/card_header.html.j2
python3 -c "$$PYTHON_MAKE_JINJA2_RENDERED_CARD" $< $@
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()
with open("build/test_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
build/test_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"