mint icon indicating copy to clipboard operation
mint copied to clipboard

Preprocessing and postprocessing

Open riffm opened this issue 14 years ago • 2 comments

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 }}

riffm avatar Oct 30 '11 15:10 riffm

The idea is interesting, but API is too complex to understand for average user.

ods avatar Oct 31 '11 13:10 ods

Ok, lets improve this API.

riffm avatar Oct 31 '11 20:10 riffm