-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Labels
Description
I propose preprocessing and postprocessing during template parsing.
Preprocessing syntax:
@tag:pre
@tag:pre,pre1
Postprocessing syntax:
@tag::post
@tag::post,post1
Mixed:
@tag:pre:post
Note: I'm not sure about multiple processors syntax.
Preprocessor pre gets the whole block contents. Result of processing is inserted in abstract mint tree.
@tag:pre
Text with
indention.
pre gets:
Text with
indention
Postprocessor post gets block as abstract mint tree. Result of processing is inserted in abstract mint tree.
When we have a block to pre/post process and do not need tag there may be such syntax:
@:pre:post
Lets call it pre/post processed block
This API allows to implement:
- caching of tags and blocks
- using other tools like clever css or coffeescript inside mint templates
- transparent translations
and more
Example
// tidy post processor, will validate template structure on parsing stage
@html::tidy
@head
// coffee script
@script:coffee
one = 1
numbers = [1...3]
// clever css
@link:ccss
div#title:
margin: 0
padding: 0
// text
@script.type(text/javascript):text
for (var i=0; i<10; i++) {
concole.log(i);
}
@body
// block with jinja template
@:jinja
{% for item in items %}
<div class="item">{{ item }}</div>
{% endfor %}
@div:rst
Title
=====
Paragraph
@div::markup
Some text with <b>markup</b>
@p but mint is working here
@div:markup
Some text with <b>markup</b>
@p this is just a text
@pre
@code.class(python):text
class OldStyle:
pass
// view logic
@p.class(title)
@:python
title = doc.title
if len(title) > 100:
title = title[:100] + '...'
// `title` is visible only inside this tag
{{ title }}