Hi,
I've been working over the past couple days to port my Google App
Engine website from using the built-in django template system to
using pyTenjin. The porting has been difficult primarily because my
django based templates use extensively inline conditionals, like:
<div id="chart">{% if not use_swf %}<img src="{{ img_src }}"
alt="chart">{% endif %}</div>
I think getting inline conditionals in Tenjin is too much to hope
for. My first feature request though is to allow Tenjin <?py
statement ?> tags to ignore initial indentation as long as they are
consistently indented. For example, now in my html template I must do
this:
<body>
<div>
<p>
<?py if boolean: ?>
some conditional text
<?py #endif ?>
</p>
</div>
</body>
The indentation levels of the <?py ?> statements are mandatory to be
separate from my indentation of the html content. Instead, I would
like to be able to use whatever indentation is appropriate for the
html as long as it is constant between <?py ?> statements. For
example:
<body>
<div>
<p>
<?py if boolean: ?>
some conditional text
<?py #endif ?>
</p>
</div>
</body>
This would make pyTenjin statements similar to Mako's control
structures ( http://www.makotemplates.org/docs/syntax.html#syntax_control
) and python blocks ( http://www.makotemplates.org/docs/syntax.html#syntax_python
).
Another problem I have is that my django templates get pre-processed
with an html compressor which strips out redundant whitespace. Since
I indent my html liberally and use 4 spaces per indentation, there is
a 30% reduction with this processing. Yes I do know this is minimized
with html gzip transfer encoding. Howerver some browsers ( *cough* IE
*cough* ) have caching and etag bugs with respect to gzip'd content.
Anyway, since I lose the ability to easily strip whitespace with
Tenjin (because <?py ?> statement indentation is significant) I am
trying to reduce some of my whitespace. I would like to be able to do
the following:
<?py if boolean: ?>one set of <strong>important</strong> text
<?py else: ?>one set of <em>other</em> text
<? #endif ?>final unconditional text
Right now (pyTenjin 0.7) the first two lines work as expected.
However the text after the <? #endif ?> does not get output to the
html stream. I think making it work after any <?py ?> tag would be
nice for consistency. And I think it would be as easy as automatically
adding a \n newline to the stream after parsing any ?> closing mark.
The only place that might be too simplistic would be inside <pre>
blocks.
Preliminary benchmarks show pyTenjin to compare extremely favorably to
the GAE built-in django templates. I have several inline conditionals
to try to translate to Tenjin helper functions. After that I will be
sure to post some concrete performance numbers.
Thank you for your work on this viable templating system.
Regards,
Steve