shawnbot / meta-template

:sparkles: Automagically convert Nunjucks templates into a variety of other formats!
52 stars 9 forks source link

Automate generation of a support matrix #5

Open shawnbot opened 7 years ago

shawnbot commented 7 years ago

It should be possible to generate a matrix of support for specific features from a set of Nunjucks template snippets. For instance, these roughly map to the more common AST node types:

symbol:  '{{ foo }}'
lookup:  '{{ foo.bar[1].baz[0][1] }}'
literal: '{{ true }}'
filter:  '{{ foo | bar }}'
# maybe for Mustache's {{}} vs. {{{}}}?
escape:  '{{ foo | escape }}'
if:      '{% if foo %}foo{% endif %}'
# there is no Else or ElseIf node type, but these need their own tests:
else:    '{% if foo %}foo{% else %}bar{% endif %}'
elseif:  '{% if foo %}foo{% elseif bar %}bar{% else %}baz{% endif %}'
unless:  '{% unless foo %}bar{% endunless %}'
for:     '{% for x in foo %}foo {{ x }}{% endfor %}'
include: '{% include "foo.html" %}'
block:   '{% block foo %}foo{% endblock %}'
extends: '{% extends "foo.html" %}{% block foo %}foo{% endblock %}'
shawnbot commented 7 years ago

This might actually be a better format for input to the unit tests for each format, too... something like:

# e.g. for PHP
converts:
  '{{ foo }}': '<?= $foo ?>'
  '{{ foo | escape }}': '<?= htmlspecialchars($foo) ?>'