Quantcast
Channel: Mako: Ticket Query
Viewing all articles
Browse latest Browse all 38

#218: Allow control statements (if, else, endif, etc.) to be closed so they can be inlined

$
0
0

In line with the discussion here:

http://groups.google.com/group/mako-discuss/browse_thread/thread/835ab6db0bb0cdb4

The pertinent parts quoted:

However, if the case is that Jinja2's (% if <expr> %}, because it has a
closing %} allows it to be inlined like {% if <expr> %} <html> {% else %}
<html> {% endif %}, then I'd want to think a bit bigger here.   I'd want to
go into match_control_line() as we did and just find some way to make the
newline optional:
% if <expr>:\n
    <html>\n
% else:\n
   <html>\n
% endif\n
we could perhaps just co-opt the { } verbosity:
{% if <expr>:}  <html> {% else:} <html> {% endif}
or just rip them off totally:
{% if <expr> %}  <html> {% else %} <html> {% endif %}
either of the above would require a rewritten (either in-place or additional
version of) match_control_line(), as we'd be doing the same kind of matching
which we do in match_expression(), which is that we need to make use of
parse_until_text() so that we properly skip over anything that might be
Python code.     I'd want the two formats to be completely interchangeable:
% if expr:
<html> {% else %} <html>
% endif
{% if <expr> %} <html>
% elif <expr>:
<html>
% else:
<html> {% endif %}
just some ideas but I'd need someone to be motivated to help patch out
lexer.py and add new tests as well.

I've frequently used Python's native 1 if 1 else 0 syntax, but it doesn't always seem ideal.

This is the only thing I can think of that other template languages can do that I wish Mako had.

Thank you for making Mako.


Viewing all articles
Browse latest Browse all 38

Trending Articles