From c16742291c9ee2264b81886fd8bbd4cad3bff611 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Thu, 19 Sep 2019 01:00:54 +0200 Subject: [PATCH] asdasasd --- Makefile | 25 +++++++++++++++++-------- sync.py | 6 +++--- templates/card_header.html.j2 | 5 +++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index bfb8a0a..f84ed5d 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ 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) +all: build/test_card.html build/test_card_rendered.html $(CARDS_DESTS) cards/build/all.html .PHONY: dev dev: @@ -23,29 +23,38 @@ build/test_card.html: build/card.xml build/style.xsl define PYTHON_MAKE_JINJA2_RENDERED_CARD from jinja2 import Environment, FileSystemLoader from markdown import markdown -import yaml, sys +import yaml, sys, glob with open("build/style.css") as f: css_data = f.read() -with open(sys.argv[1]) as f: data = f.read() with open(sys.argv[2], "w") as f: e = Environment(trim_blocks=True, lstrip_blocks=True, loader=FileSystemLoader('')) - css_data - header = e.get_template("templates/card_header.html.j2").render(css_data=css_data) + 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())) }) - f.write(header + "\n" + e.get_template('style.html.j2').render(card=yaml.load(data))) + for filename in ([sys.argv[1]] if sys.argv[1] != "ALL" else glob.glob("cards/*.yaml")): + if sys.argv[1] == "ALL": f.write(f"\n\n

{filename}

\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"
{ex}
" + f.write("\n" + data) endef export PYTHON_MAKE_JINJA2_RENDERED_CARD -build/test_card_rendered.html: test_card.yaml style.html.j2 +build/test_card_rendered.html: test_card.yaml style.html.j2 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 +cards/build/%.html: cards/%.yaml style.html.j2 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 templates/card_header.html.j2 + python3 -c "$$PYTHON_MAKE_JINJA2_RENDERED_CARD" ALL $@ + define PYTHON_MAKE_CARD_XML from jinja2 import Environment, FileSystemLoader diff --git a/sync.py b/sync.py index 5c8172a..ff012ca 100755 --- a/sync.py +++ b/sync.py @@ -74,10 +74,10 @@ def pull_all(): f.write(yaml_data + "\n") print(f"./cards/{card_id}.yaml written!") continue - - with open(f"cards/{card_id}.xml", "w") as f: + ftype = "xml" if data.strip() else "yaml" + with open(f"cards/{card_id}.{ftype}", "w") as f: f.write(data + "\n") - print(f"./cards/{card_id}.xml written!") + print(f"./cards/{card_id}.{ftype} written!") def push_all(): existing_card_ids = get_card_ids() diff --git a/templates/card_header.html.j2 b/templates/card_header.html.j2 index e3e524a..e08a434 100644 --- a/templates/card_header.html.j2 +++ b/templates/card_header.html.j2 @@ -1,5 +1,10 @@ {% set async = "media=\"none\" onload=\"if(media!='all')media='all'\"" -%} +{% if is_local %} + +{##} +{% endif %} +