Remove the support for yaml files and rendering of cards with jinja2
This commit is contained in:
parent
3ed09663b9
commit
c3538928f3
124
Makefile
124
Makefile
|
@ -1,19 +1,11 @@
|
|||
|
||||
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)
|
||||
CARDS := $(wildcard cards/*.xml)
|
||||
CARDS_DESTS := $(patsubst cards/%.xml,cards/build/%.html,$(CARDS))
|
||||
|
||||
.PHONY: style
|
||||
style: build/test_card.html build/test_card_rendered.html cards/build/all.html
|
||||
style: build/test_card.html
|
||||
|
||||
.PHONY: cards
|
||||
cards: $(CARDS_DESTS) cards/build/all.html
|
||||
|
||||
.PHONY: style
|
||||
style: build/style.xsl
|
||||
cards: cards/build/all.html
|
||||
|
||||
.PHONY: dev
|
||||
dev:
|
||||
|
@ -23,87 +15,35 @@ dev:
|
|||
dev_cards:
|
||||
git ls-files | entr bash -c "make cards"
|
||||
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -v build/* cards/build/*
|
||||
|
||||
build/test_card.html: build/test_card.xml build/style.xsl
|
||||
|
||||
build/test_card.html: test_card.xml build/style.xsl build
|
||||
xsltproc \
|
||||
-o build/test_card.html \
|
||||
build/style.xsl \
|
||||
build/test_card.xml
|
||||
test_card.xml
|
||||
|
||||
|
||||
define PYTHON_MAKE_JINJA2_RENDERED_CARD
|
||||
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
|
||||
from markdown import markdown
|
||||
import yaml, sys, glob, traceback
|
||||
import xmltodict
|
||||
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({
|
||||
"is_number":lambda x: str(x).isnumeric(),
|
||||
"is_string":lambda x: isinstance(x, str),
|
||||
"markdown":markdown,
|
||||
"any":any,
|
||||
"all":all,
|
||||
"split":str.split,
|
||||
"startswith":str.startswith,
|
||||
"tail": lambda x: x[1:],
|
||||
"cull_whitespace":(lambda x: " ".join(x.split())) })
|
||||
for n, filename in enumerate([sys.argv[1]] if sys.argv[1] != "ALL" else sorted(glob.glob("cards/*.yaml") + glob.glob("cards/*.xml"))):
|
||||
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", ""))
|
||||
try:
|
||||
data = e.get_template('style.html.j2').render(yaml=yaml_data, xml=xml_data)
|
||||
except Exception as ex:
|
||||
data = f"<pre style=\"color:red;\">{ex}</pre>"
|
||||
traceback.print_exc()
|
||||
if sys.argv[1] == "ALL":
|
||||
f.write(f"\n\n<div id='card_container_{n}'>\n<h1>{filename}</h1>\n\n{data}\n</div>")
|
||||
else:
|
||||
f.write(f"\n<div id='card_container_{n}'>\n{data}\n</div>")
|
||||
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_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"
|
||||
|
||||
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/%.x.html: cards/%.xml 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("test_card.xml") as f: xml_data = f.read()
|
||||
with open("build/test_card.xml", "w") as f:
|
||||
f.write(Environment(
|
||||
loader=FileSystemLoader('templates'))
|
||||
.get_template('card.xml.j2')
|
||||
.render(data=data, xml_data=xml_data))
|
||||
endef
|
||||
export PYTHON_MAKE_CARD_XML
|
||||
build/test_card.xml: test_card.yaml test_card.xml templates/card.xml.j2
|
||||
python3 -c "$$PYTHON_MAKE_CARD_XML"
|
||||
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
|
||||
|
@ -112,9 +52,9 @@ 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'))
|
||||
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(
|
||||
|
@ -122,16 +62,24 @@ with open("build/style.xsl", "w") as f:
|
|||
.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/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
|
||||
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/style.css: style.scss build
|
||||
python3 -c "$$PYTHON_MAKE_SASS"
|
||||
|
||||
|
||||
build:
|
||||
mkdir -p build
|
||||
|
||||
|
||||
cards/build:
|
||||
mkdir -p cards/build
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<style>
|
||||
|
||||
@page
|
||||
{
|
||||
size: auto;
|
||||
margin: 0.5cm;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: white;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
-webkit-print-color-adjust: exact;
|
||||
}
|
||||
|
||||
.card_wrapper {
|
||||
width: 2.5in;
|
||||
height: 3.5in;
|
||||
float: left;
|
||||
border: 1px solid transparent;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
iframe {
|
||||
margin: 0px;
|
||||
padding: none;
|
||||
border: none;
|
||||
width:2.5in;
|
||||
height:3.5in;
|
||||
overflow: hidden;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<div>
|
||||
{% for cardname in cards %}
|
||||
<div class="card_wrapper">
|
||||
<iframe src="{{ cardname }}" scrolling=no></iframe>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
|
@ -1,5 +0,0 @@
|
|||
<ability_card><yaml_data>
|
||||
{{ data.strip() }}
|
||||
</yaml_data>
|
||||
{{ xml_data }}
|
||||
</ability_card>
|
|
@ -1,6 +1,5 @@
|
|||
{% set async = "media=\"none\" onload=\"if(media!='all')media='all'\"" -%}
|
||||
|
||||
|
||||
{% if is_local %}
|
||||
{#
|
||||
<meta http-equiv="refresh" content="1.0">
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
</head>
|
||||
{% endfilter %}
|
||||
|
||||
<body content_type="html5">
|
||||
<body content_type="html5" style="margin:0px;">
|
||||
|
||||
<style type="text/css">
|
||||
{{ css_data.strip() }}
|
||||
|
|
|
@ -1,5 +1,37 @@
|
|||
<ability_card><yaml_data>
|
||||
|
||||
name: Hit enemy
|
||||
#style: item
|
||||
tags:
|
||||
- combat
|
||||
playcost:
|
||||
- 'Element: fire'
|
||||
- 'BODY+5 POWER'
|
||||
#flavor: Enemies sure are squishy
|
||||
#description: Perform an attack
|
||||
#steps:
|
||||
#- Do A
|
||||
#- Do A
|
||||
#- Do A
|
||||
#- Then B
|
||||
figures:
|
||||
- name: piuy/chicken
|
||||
source: img
|
||||
scale: 2
|
||||
notes: ''
|
||||
|
||||
</yaml_data>
|
||||
|
||||
<name>Mega Fireball</name>
|
||||
<description>Attack an enemy in range 5.
|
||||
<description>
|
||||
| | |
|
||||
| ----:|----|
|
||||
| asd | asd |
|
||||
| asd | asd |
|
||||
|
||||
# asd
|
||||
|
||||
Attack an enemy in range 5.
|
||||
|
||||
Roll MAG hit dice. Deal that amount of FIRE damage to the target.</description>
|
||||
<image>https://freepngimg.com/download/fireball/27487-2-fireball-clipart.png</image>
|
||||
|
@ -15,6 +47,7 @@ Not Silenced,
|
|||
Equipment has Catalyst property</playcost>
|
||||
<artistic_value>-1</artistic_value>
|
||||
|
||||
<component x="11" y="3" db_entry="🧩 Mastery"/>
|
||||
<component x="7" y="1" db_entry="🧩 Set Ability Name"/>
|
||||
<component x="9" y="1" db_entry="🧩 Set Image"/>
|
||||
<component x="11" y="1" db_entry="🧩 Play Cost"/>
|
||||
|
@ -26,3 +59,5 @@ Equipment has Catalyst property</playcost>
|
|||
<component x="12" y="5" db_entry="🧩 Range"/>
|
||||
<component x="8" y="2" db_entry="🧩 Set Description"/>
|
||||
<component x="3" y="3" db_entry="🎺 Repertoire Card: Filler"/>
|
||||
|
||||
</ability_card>
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
name: Hit enemy
|
||||
#style: item
|
||||
tags:
|
||||
- combat
|
||||
playcost:
|
||||
- 'Element: fire'
|
||||
- BODY+5 POWER
|
||||
#flavor: Enemies sure are squishy
|
||||
description: Perform an attack
|
||||
#steps:
|
||||
#- Do A
|
||||
#- Do A
|
||||
#- Do A
|
||||
#- Then B
|
||||
figures:
|
||||
- name: piuy/chicken
|
||||
source: img
|
||||
scale: 2
|
||||
notes: ''
|
Loading…
Reference in New Issue