This commit is contained in:
Peder Bergebakken Sundt 2019-09-10 17:54:18 +02:00
parent 96978e2f22
commit da1e53b190
5 changed files with 33 additions and 17 deletions

View File

@ -26,7 +26,7 @@ with open("build/card.xml", "w") as f:
endef
export PYTHON_MAKE_CARD_XML
build/card.xml: card.yaml
build/card.xml: card.yaml templates/card.xml.j2
python3 -c "$$PYTHON_MAKE_CARD_XML"
@ -37,6 +37,8 @@ with open("style.html.j2") as f: jinja_data = f.read()
with open("style.js") as f: js_data = f.read()
with open("build/style.xsl", "w") as f:
f.write(Environment(
trim_blocks=True,
lstrip_blocks=True,
loader=FileSystemLoader('templates'))
.get_template('style.xsl.j2')
.render( css_data=css_data, jinja_data=jinja_data, js_data=js_data))

View File

@ -34,7 +34,7 @@
</div>
{%- endmacro -%}
<div class="{{ card.template }}">
<div class="fjomp_card">
<header>{{ card.title }}</header>
<figure>
{% for figure in card.figures -%}

View File

@ -28,4 +28,4 @@ env.addFilter('all', function(iterable) {
rendered = env.renderString(jinja_template, context);
console.log(rendered);
document.getElementById("my_card").innerHTML = rendered;
document.write(rendered);

View File

@ -1,3 +1,3 @@
<ability_card><yaml_data>
{{ data }}
{{ data.strip() }}
</yaml_data></ability_card>

View File

@ -1,16 +1,21 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" indent="yes" />
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:template match="/*">
<xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE html&gt;
</xsl:text>
{% set newline = "<xsl:text disable-output-escaping='yes'>\n</xsl:text>" %}
{% set async = "media=\"none\" onload=\"if(media!='all')media='all'\"" %}
{% filter replace("\n", newline) %}
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.13.1/js-yaml.min.js"/>
<script type="text/javascript" src="http://mozilla.github.io/nunjucks/files/nunjucks.min.js"/>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/9.1.0/markdown-it.min.js"/>
<html>
{% filter replace(">", ">foobarhuehuehue")
| replace("<", "<xsl:text disable-output-escaping='yes'>&lt;</xsl:text>")
| replace(">foobarhuehuehue", "<xsl:text disable-output-escaping='yes'>&gt;</xsl:text>")
| replace("\n", newline) %}
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.13.1/js-yaml.min.js"></script>
<script type="text/javascript" src="https://mozilla.github.io/nunjucks/files/nunjucks.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/9.1.0/markdown-it.min.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" {{async}}/>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" {{async}}/>
@ -20,33 +25,42 @@
<title>Status Card</title>
</head>
{% endfilter %}
<body content_type="html5">
<style type="text/css">
{{ css_data }}
{{ css_data.strip() }}
</style>
{{ newline*2 }}
<script type="text/html" id="yaml_data">---
<script type="text/html" id="yaml_data">
<xsl:value-of select="yaml_data"/>
</script>
{{ newline*2 }}
<script type="text/javascript">
var jinja_template = {{ jinja_data | tojson }};
var jinja_template =
{{ jinja_data.strip() | tojson | replace("\\n", "\\n\" +\n\"") }};
</script>
{{ newline*2 }}
<div id="my_card"></div>
<script type="text/javascript">
{{ js_data
{{ js_data.strip()
| replace(">", ">foobarhuehuehue")
| replace("<", "<xsl:text disable-output-escaping='yes'>&lt;</xsl:text>")
| replace(">foobarhuehuehue", "<xsl:text disable-output-escaping='yes'>&gt;</xsl:text>") }}
</script>
{{ newline*2 }}
</body>
{{ newline }}
</html>
</xsl:template>
</xsl:stylesheet>