add ability to edit many cards locally
This commit is contained in:
parent
ced3388b60
commit
c035af41a0
56
Makefile
56
Makefile
|
@ -1,5 +1,9 @@
|
|||
|
||||
all: build/card.html build/card_rendered.html
|
||||
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)
|
||||
|
||||
.PHONY: dev
|
||||
dev:
|
||||
|
@ -7,37 +11,45 @@ dev:
|
|||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm build/*
|
||||
rm build/* cards/build/*
|
||||
|
||||
build/card.html: build/card.xml build/style.xsl
|
||||
build/test_card.html: build/card.xml build/style.xsl
|
||||
xsltproc \
|
||||
-o build/card.html \
|
||||
-o build/test_card.html \
|
||||
build/style.xsl \
|
||||
build/card.xml
|
||||
|
||||
|
||||
define PYTHON_MAKE_RENDERED_CARD
|
||||
define PYTHON_MAKE_JINJA2_RENDERED_CARD
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
from markdown import markdown
|
||||
import yaml
|
||||
with open("card.yaml") as f: data = f.read()
|
||||
with open("build/card_rendered.html", "w") as f:
|
||||
import yaml, sys
|
||||
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)
|
||||
e.filters.update({
|
||||
"markdown":markdown,
|
||||
"any":any,
|
||||
"all":all,
|
||||
"cull_whitespace":(lambda x: " ".join(x.split())) })
|
||||
f.write(e.get_template('style.html.j2').render(card=yaml.load(data)))
|
||||
f.write(header + "\n" + e.get_template('style.html.j2').render(card=yaml.load(data)))
|
||||
endef
|
||||
export PYTHON_MAKE_RENDERED_CARD
|
||||
build/card_rendered.html: card.yaml style.html.j2
|
||||
python3 -c "$$PYTHON_MAKE_RENDERED_CARD"
|
||||
|
||||
export PYTHON_MAKE_JINJA2_RENDERED_CARD
|
||||
build/test_card_rendered.html: test_card.yaml style.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
|
||||
python3 -c "$$PYTHON_MAKE_JINJA2_RENDERED_CARD" $< $@
|
||||
|
||||
|
||||
define PYTHON_MAKE_CARD_XML
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
with open("card.yaml") as f: data = f.read()
|
||||
with open("test_card.yaml") as f: data = f.read()
|
||||
with open("build/card.xml", "w") as f:
|
||||
f.write(Environment(
|
||||
loader=FileSystemLoader('templates'))
|
||||
|
@ -45,7 +57,7 @@ with open("build/card.xml", "w") as f:
|
|||
.render(data=data))
|
||||
endef
|
||||
export PYTHON_MAKE_CARD_XML
|
||||
build/card.xml: card.yaml templates/card.xml.j2
|
||||
build/card.xml: test_card.yaml templates/card.xml.j2
|
||||
python3 -c "$$PYTHON_MAKE_CARD_XML"
|
||||
|
||||
|
||||
|
@ -54,16 +66,18 @@ 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(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))
|
||||
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 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
|
||||
python3 -c "$$PYTHON_MAKE_STYLE_XSL"
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
<!--fonts, loaded asyncronously-->
|
||||
{% macro async() -%}
|
||||
media="none" onload="if(media!='all')media='all'"
|
||||
{%- endmacro -%}
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" {{async()}}>
|
||||
<link rel="stylesheet" href="https://cdn.materialdesignicons.com/2.0.46/css/materialdesignicons.min.css" {{async()}}>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" {{async()}}>
|
||||
<link rel="stylesheet" href="https://cdn.linearicons.com/free/1.0.0/icon-font.min.css" {{async()}}>
|
||||
|
|
@ -29,14 +29,14 @@
|
|||
<span class="oi" data-glyph="{{ figure.name }}"></span>
|
||||
{% elif figure.type == "svg" %}
|
||||
{# /cards/svg #}
|
||||
{% if figure.color != false %}
|
||||
{% if figure.color %}
|
||||
<img src="https://pvv.ntnu.no/~pederbs/cards/svg/data/{{ figure.name }}" class="colored" style="--figure-color:{{ figure.color }}">
|
||||
{% if figure.color %}
|
||||
{% if figure.color == true %}
|
||||
<img src="https://pvv.ntnu.no/~pederbs/cards/svg/data/{{ figure.name }}">
|
||||
{% else %}
|
||||
<img src="https://pvv.ntnu.no/~pederbs/cards/svg/data/{{ figure.name }}" class="colored">
|
||||
<img src="https://pvv.ntnu.no/~pederbs/cards/svg/data/{{ figure.name }}" class="colored" style="--figure-color:{{ figure.color }}">
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<img src="https://pvv.ntnu.no/~pederbs/cards/svg/data/{{ figure.name }}">
|
||||
<img src="https://pvv.ntnu.no/~pederbs/cards/svg/data/{{ figure.name }}" class="colored">
|
||||
{% endif %}
|
||||
{% elif figure.type == "img" %}
|
||||
{# /cards/img #}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
{% set async = "media=\"none\" onload=\"if(media!='all')media='all'\"" -%}
|
||||
|
||||
<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>
|
||||
|
||||
<!--fonts, loaded asyncronously-->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/open-iconic/1.1.1/font/css/open-iconic.min.css" {{async}}/>
|
||||
<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}}/>
|
||||
<link rel="stylesheet" href="https://cdn.materialdesignicons.com/2.0.46/css/materialdesignicons.min.css" {{async}}/>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" {{async}}/>
|
||||
<link rel="stylesheet" href="https://cdn.linearicons.com/free/1.0.0/icon-font.min.css" {{async}}/>
|
||||
|
||||
{% if css_data %}
|
||||
<style type="text/css">
|
||||
{{ css_data.strip() }}
|
||||
</style>
|
||||
{% endif %}
|
|
@ -2,27 +2,18 @@
|
|||
<xsl:output method="xml" omit-xml-declaration="yes" />
|
||||
<xsl:template match="/*">
|
||||
{% set newline = "<xsl:text disable-output-escaping='yes'>\n</xsl:text>" %}
|
||||
{% set async = "media=\"none\" onload=\"if(media!='all')media='all'\"" %}
|
||||
|
||||
<html>
|
||||
|
||||
{% filter replace(">", ">foobarhuehuehue")
|
||||
| replace("<", "<xsl:text disable-output-escaping='yes'><</xsl:text>")
|
||||
| replace(">foobarhuehuehue", "<xsl:text disable-output-escaping='yes'>></xsl:text>")
|
||||
| replace("\n", newline) %}
|
||||
| replace("\n", newline)
|
||||
| replace("</xsl:text><xsl:text disable-output-escaping='yes'>", "") %}
|
||||
|
||||
<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://cdnjs.cloudflare.com/ajax/libs/open-iconic/1.1.1/font/css/open-iconic.min.css" {{async}}/>
|
||||
<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}}/>
|
||||
<link rel="stylesheet" href="https://cdn.materialdesignicons.com/2.0.46/css/materialdesignicons.min.css" {{async}}/>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" {{async}}/>
|
||||
<link rel="stylesheet" href="https://cdn.linearicons.com/free/1.0.0/icon-font.min.css" {{async}}/>
|
||||
{{ card_header }}
|
||||
|
||||
<title>Status Card</title>
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ notes: ''
|
|||
figures:
|
||||
- name: batman
|
||||
type: svg
|
||||
color: false
|
||||
color: true
|
||||
scale: 0.8
|
||||
flip_x: false
|
||||
flip_y: false
|
Loading…
Reference in New Issue