Am 25.02.2011 09:29, schrieb dennis luehring:
would be great to have this available at compiletime

better said - an at compiletime generated render-code - would be blasting fast because of just combining the template-chunks inside of an huge write - or every type of section

so something like this:

--- basic.mustache ---
Hello {{name:%s}}
You have just won ${{value:%i}}!
{{#in_ca}}
Well, ${{taxed_value:%f}}, after taxes.
{{/in_ca}}
-----------------------

would be mixined/compiled to something like:

class TemplateEngine
{
  mixin( generate template-members/sections/renderer) )
  //section:main
  struct main: section
  --> string name
  --> int value
  --> string mixined_renderer()
  {
    auto writer = appender!string();
formattedWrite(writer, "Hello %s\nYou have just won $%i!\n%s",name,value,section_in_ca.mixined_renderere());
    return writer.data;
  }

  //struct section_in_ca: sections
  --> in_ca [] blocks;
  string mixined_renderer()
  {
    string tmp;
    foreach( block blocks )
    {
       tmp ~= block.mixined_renderer();
    }
    return tmp;
  }

  //section:in_ca
  struct in_ca
  --> float taxted_value
  --> mixined_renderer
  void mixined_renderer( _writer )
  {
    auto writer = appender!string();
    formattedWrite(writer, "Well, $%f, after taxes.\n",taxed_value);
    return writer.data;
  }

  //.in_ca.create add new in_ca section to the section_in_ca.blocks

  // and section can have inner sections etc....

  string render()
  {
    return main.mixined_renderer();
  }
}

and if its runned to the end you can even check if inputs are const and remove completely the depending code... the idea is to generated to "write"-code as compact as possible

Reply via email to