2019-09-10 00:52:30 +02:00
|
|
|
var md = window.markdownit();
|
|
|
|
var context = {
|
2019-10-06 16:03:07 +02:00
|
|
|
'xml' : {},
|
2019-09-10 00:52:30 +02:00
|
|
|
'card' : jsyaml.load(document.getElementById("yaml_data").innerHTML),
|
|
|
|
'alert' : alert,
|
|
|
|
};
|
2019-09-09 19:29:27 +02:00
|
|
|
|
2019-10-06 16:03:07 +02:00
|
|
|
// read xml data
|
|
|
|
var xml_data_items = document.getElementsByClassName("xml_data")
|
|
|
|
for (var i=0; i < xml_data_items.length; i++) {
|
|
|
|
var key = xml_data_items[i].id.substr(9);
|
|
|
|
var val = xml_data_items[i].innerHTML;
|
|
|
|
context.xml[key] = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_set(asd) {
|
|
|
|
return typeof asd === 'undefined' || asd === "XML" || asd.length === 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_set(context.card.title) && context.xml.name ) context.card.title = context.xml.name;
|
|
|
|
if (!is_set(context.card.icon) && context.xml.symbol ) context.card.icon = context.xml.symbol;
|
|
|
|
if (!is_set(context.card.description) && context.xml.description) context.card.description = context.xml.description;
|
|
|
|
if (!is_set(context.card.cp) && context.xml.cp ) context.card.cp = context.xml.cp;
|
|
|
|
if (!is_set(context.card.power) && context.xml.power ) context.card.power = context.xml.power;
|
|
|
|
if (!is_set(context.card.difficulty) && context.xml.difficulty ) context.card.difficulty = context.xml.difficulty;
|
|
|
|
if (!is_set(context.card.duration) && context.xml.duration ) context.card.duration = context.xml.duration;
|
|
|
|
if (!is_set(context.card.playcost) && context.xml.playcost ) context.card.playcost = context.xml.playcost;
|
|
|
|
if (!is_set(context.card.range) && context.xml.range ) context.card.range = context.xml.range;
|
|
|
|
if (!is_set(context.card.figures) && context.xml.image ) context.card.figures = [{
|
|
|
|
'name': context.xml.image,
|
|
|
|
'type': "url",
|
|
|
|
'scale': 1.0,
|
|
|
|
'flip_x': false,
|
|
|
|
'flip_y': false,
|
|
|
|
'offset': [0.0, 0.0],
|
|
|
|
'opacity': 1,
|
|
|
|
'rotation': 0,
|
|
|
|
}];
|
|
|
|
|
2019-09-10 00:52:30 +02:00
|
|
|
var env = new nunjucks.Environment({
|
2019-09-11 05:09:42 +02:00
|
|
|
autoescape: true,
|
|
|
|
trimBlocks: true,
|
|
|
|
lstripBlocks: true,
|
2019-09-10 00:52:30 +02:00
|
|
|
});
|
|
|
|
env.addFilter('markdown', function(str) {
|
|
|
|
return md.render(str);
|
|
|
|
});
|
|
|
|
env.addFilter('cull_whitespace', function(str) {
|
|
|
|
return str.split(/\s+/).join(' ').trim();
|
|
|
|
});
|
|
|
|
env.addFilter('any', function(iterable) {
|
|
|
|
for (var index = 0; index < iterable.length; index++) {
|
|
|
|
if (iterable[index]) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
env.addFilter('all', function(iterable) {
|
|
|
|
for (var index = 0; index < iterable.length; index++) {
|
|
|
|
if (!iterable[index]) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2019-09-09 19:29:27 +02:00
|
|
|
|
2019-09-10 00:52:30 +02:00
|
|
|
rendered = env.renderString(jinja_template, context);
|
2019-10-06 16:03:07 +02:00
|
|
|
//console.log(rendered);
|
2019-09-10 17:54:18 +02:00
|
|
|
document.write(rendered);
|