Ghini / ghini.desktop

plant collections manager (desktop version)
http://ghini.github.io/
GNU General Public License v2.0
24 stars 14 forks source link

please consider Jinja2 templating language #434

Closed mfrasca closed 6 years ago

mfrasca commented 6 years ago

todo

original report

I'm getting a bit fed up with Mako complications regarding inheritance and namespaces and lookups, so much that I would spend a couple of days experimenting with the Jinja2 templating language, which I know a bit better than Mako, and where I never met such difficulties.

mfrasca commented 6 years ago

oh, well, a couple of days were compressed in 20 minutes …

>>> from jinja2 import Environment, PackageLoader
>>> env = Environment(
    loader=PackageLoader('bauble.plugins.report.mako', 'templates')
)
>>> template = env.get_template('label.ps.jj2') 
>>> template.render()

where label.ps.jj2 is this file:

{% extends "base.ps.jj2" %}
{% block body %}
Index
{% endblock %}

and the base.ps.jj2 template holds the whole postscript common boilerplate, something like this:

{# copyright statement
#}
%!PS-Adobe-3.0
%%BoundingBox: (atend)
%%Creator: (Ghini)
%%For: (ghini)
%%CreationDate: (2016-01-15 21:34:45 )
%%Title: (Untitled1)
%%LanguageLevel: 2
%%DocumentData: Clean7Bit
%%Pages: (atend)
%%Orientation: (atend)
%%PageOrder: Ascend
%%EndComments
%%BeginProlog
%%BeginResource: procset PSPrint-Prolog 1.0 0
{% block body %}{% endblock %}

I'm convinced it's just as easy with Mako, too. but the quality of documentation is enervating, and the syntax in jinja2 looks neater.

mfrasca commented 6 years ago

I'm adding this to the current milestone, because this issue is a reincarnation of #431.

mfrasca commented 6 years ago

I have added jinja2 support, but while reading the docs for jinja2, i realized that most of it also applied to mako, and it helped understand bauble/ghini's mistake in using mako, namely going straight into the Template constructor instead of using Lookup (Jinja2's Environment). and really in Mako it's less complex than in Jinja2, it's just the documentation which is totally worthless for a lazy reader like me.

mfrasca commented 6 years ago

in the end, I decided that Jinja2 is far too limited, compared to Mako. while in Mako you import and execute whatever python code, in Jinja2 you are limited to filters.