Created
December 8, 2011 09:21
-
-
Save oblique63/1446542 to your computer and use it in GitHub Desktop.
Template language idea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 'Zenplate': a language/template-engine agnostic markup DSL | |
| */ | |
| // extending a zenplate | |
| extend -> 'base.zen' | |
| // support for extending templates from other template engines | |
| extend -> jinja 'base.j2' | |
| // support for extending any of your existing templates; | |
| // the template that will actually be extended will depend | |
| // on the output format you choose. | |
| extend -> | |
| jinja 'base.j2' | |
| mako 'base.mako | |
| php 'base.php' | |
| // the '->' operator signifies a zenplate directive (in this case, 'extend') | |
| // and the arguments that are to be passed to the directive, are to the right of it. | |
| doctype 5 | |
| html lang="en" | |
| head | |
| // variables start with a '@' | |
| title @my_title_var | |
| meta charset="utf-8" | |
| body | |
| div #id .(class1 class2) | |
| some simple text here | |
| // keywords ending in ':' are filters. | |
| markdown: | |
| simple _markdown_ filter | |
| // '::' is the include operator. Used for including content from external files, | |
| // and passing them to a filter | |
| markdown:: 'file.md' | |
| with -> extension1, extension2 | |
| // the 'with' keyword signifies a list of parameters/extensions that are | |
| // to be passed to the filter. May be placed in the same line as the filter directive, | |
| // or indented, one line below it. | |
| // alternatively, arguments may be passed this way as well | |
| markdown(extension1, extension2):: 'file.md' | |
| // include a jinja template | |
| jinja:: 'template.j2' | |
| // indented text below an include directive (aside from special kewords/arguments) | |
| // will produce an error. | |
| // here's another way to include a jinja template | |
| include -> jinja 'template.zen' | |
| // 'include' works on zenplates by default | |
| include -> 'template2.zen' | |
| // designate a zen block | |
| block -> content | |
| text text text... | |
| // designate a template-specific block | |
| block -> jinja content | |
| you could even use {{ template_specific_syntax }} in these blocks | |
| this is an span[inline] element. | |
| this is an span(id="span")[inline] element with attributes. | |
| span this whole line is in an inline element | |
| and these are self-closing elements: img(res="image.jpg") br | |
| this is an upper:[inline] filter. | |
| and this is an inline filter with substring(0,3):[without] arguments | |
| // element attributes may be surrounded by'( )', but this is optional, | |
| // unless they are inline elements. | |
| div(id="content" class="text") | |
| text text text | |
| // is the same as: | |
| div id="content" class="text" | |
| text text text | |
| // and using shorthand: | |
| div #content .(text) | |
| text text text | |
| // class shorthand uses '.( )' to make it easier to denote a list of classes | |
| // and id uses the traditional '#' shorthand. Shorthands must all have a space in between them; | |
| // they may not be chained together like in haml. | |
| // div's must be explicitly stated by default. | |
| this text will not be contained in a div | |
| div | |
| but this text will | |
| // content for block-elements must always start in a new line, and be indented | |
| p | |
| all this text will go | |
| under the <p> element | |
| // variable declarations | |
| @some_var = "some value" | |
| // if you want that literal text in your html, just escape it: | |
| \@some_var = "some value" | |
| // call the variable's methods | |
| - if @some_link.startswith("http://") | |
| a(href="@some_link")[ go here ] | |
| // call a function | |
| - if not isempty(@some_list) | |
| ul | |
| - for @item in @some_list | |
| li @item | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment