{"_id":"Templ8","_rev":"148-f0e892ea5d1f1fb7f14122af38d72559","name":"Templ8","description":"JavaScript Client/ Server Template Engine","dist-tags":{"latest":"0.10.5"},"versions":{"0.1.7":{"name":"Templ8","description":"JavaScript Client/ Server Template Engine","keywords":["template","tpl","Templ8"],"author":{"name":"constantology","email":"constantology@gmail.com","url":"http://muigui.com"},"main":"./Templ8.js","version":"0.1.7","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"_npmJsonOpts":{"file":"/Users/christosconstandinou/.npm/Templ8/0.1.7/package/package.json","wscript":false,"contributors":false,"serverjs":false},"_id":"Templ8@0.1.7","dependencies":{},"devDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.0.15","_nodeVersion":"v0.5.0-pre","_defaultsLoaded":true,"dist":{"shasum":"a0136813199f34d615ff07435a34f3e60ac91a9e","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.1.7.tgz","integrity":"sha512-9bVApJ3+rPhRsOaiNBsjRNdY1+tJv46X6lVLDp6AqxwnlO5IzDSX9WF15w00QRkzHy0ic6uNBS0QRmawmPMkqQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCjjn9Ug1TTugnFAj0r1okn2e+qonPH4LK2vCYglVovVQIgEhiTJhlWpRvY8wp5uku9HsGE9sWrMWGYqBs72XDqxxo="}]},"scripts":{},"directories":{}},"0.1.8":{"name":"Templ8","description":"JavaScript Client/ Server Template Engine","keywords":["template","tpl","Templ8"],"author":{"name":"constantology","email":"constantology@gmail.com","url":"http://muigui.com"},"main":"./Templ8.js","version":"0.1.8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"_npmJsonOpts":{"file":"/Users/christosconstandinou/.npm/Templ8/0.1.8/package/package.json","wscript":false,"contributors":false,"serverjs":false},"_id":"Templ8@0.1.8","dependencies":{},"devDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.0.22","_nodeVersion":"v0.5.0-pre","_defaultsLoaded":true,"dist":{"shasum":"aca8d677753aa971a83a045db4442cd77e6a4bad","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.1.8.tgz","integrity":"sha512-fZ+bOPLaWH0DmmWSThGgMLrjpxEbUoJ0Dprwtb2q3pRqw+XpzprWL7cgCzJjyrXzClMjMRBWx+Djyb+nO94hlA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIASqf98THJWPvacBRp/9q4WeM2wg8nGvmZqlY9RsXip+AiBDzyWoW2T8tPi+R7WYx+9uyQZD7y6u+1QMLxAU1KMwNA=="}]},"scripts":{},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.1.9":{"name":"Templ8","description":"JavaScript Client/ Server Template Engine","keywords":["template","tpl","Templ8"],"author":{"name":"constantology","email":"constantology@gmail.com","url":"http://muigui.com"},"main":"./Templ8.js","version":"0.1.9","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"dependencies":{},"devDependencies":{},"_id":"Templ8@0.1.9","engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.0.6","_nodeVersion":"v0.5.0-pre","_defaultsLoaded":true,"dist":{"shasum":"5a63381fd316f5c7fdb0f5100d585a2fe5e76be4","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.1.9.tgz","integrity":"sha512-nLSGDS178ifbMtSWlGpyP4ysz8H7ipEsCSdqLKi4sLIp5YG7rJHxOhVRfK+1RLJPuMkDcvDXcelHhvF2OwHmDw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICyo+RI55cwDJNpv5zJE70iIJnGD62LngaDG/JZyAWAyAiAx46YfPhXmRQWvZ/M+08VvPkw5K6bqr/R5fvoi93BvGg=="}]},"scripts":{},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.2.0":{"name":"Templ8","description":"JavaScript Client/ Server Template Engine","keywords":["template","tpl","Templ8"],"author":{"name":"constantology","email":"constantology@gmail.com","url":"http://muigui.com"},"main":"./Templ8.js","version":"0.2.0","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"dependencies":{},"devDependencies":{},"_id":"Templ8@0.2.0","engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.0.6","_nodeVersion":"v0.5.0-pre","_defaultsLoaded":true,"dist":{"shasum":"35ed3d1316ead806b30ebd088affc6ba72ce9f45","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.2.0.tgz","integrity":"sha512-TzoYCRlFM8aDkwDX/SBGI1zli8vI+nQ9MxY4inpu9i3T7jVgN6yVy0mN3cls/KrXma1adlw4XLVNzjkOIivTrQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCLzL6Unl+KnmFZDlL4XWXA+jqt1W63gifCDfIUiSTwAgIhAI7FdWAxoeSvo7oouaynP6AhN/OUH9sKxIzmN5ezLKlv"}]},"scripts":{},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.2.1":{"name":"Templ8","description":"JavaScript Client/ Server Template Engine","keywords":["template","tpl","Templ8"],"author":{"name":"constantology","email":"constantology@gmail.com","url":"http://muigui.com"},"main":"./Templ8.js","version":"0.2.1","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"_npmJsonOpts":{"file":"/Users/christosconstandinou/.npm/Templ8/0.2.1/package/package.json","wscript":false,"contributors":false,"serverjs":false},"_id":"Templ8@0.2.1","dependencies":{},"devDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.0.22","_nodeVersion":"v0.5.0-pre","_defaultsLoaded":true,"dist":{"shasum":"75d97971545256916e5f4cff3c8de39ee70cd45d","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.2.1.tgz","integrity":"sha512-nVN/wiG4umUpNiwlWVKZH+42GX5ToAlbwsRP11jWSEMXFWCBnC3RwApusgwdNAMHwGQOLctjjb7SIxWN4ivvJQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIATOsjl+RogyM1gQclYuUQzebc4pGVD2N2CWBIQGUwWFAiEA/uCWMmciYnMWo7j/ckf5Hg+zJNTK9gxbu/1+2iciMX4="}]},"scripts":{},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.3.0":{"name":"Templ8","description":"JavaScript Client/ Server Template Engine","keywords":["template","tpl","Templ8"],"author":{"name":"constantology","email":"constantology@gmail.com","url":"http://muigui.com"},"main":"./Templ8.js","version":"0.3.0","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"_npmJsonOpts":{"file":"/Users/constantology/.npm/Templ8/0.3.0/package/package.json","wscript":false,"contributors":false,"serverjs":false},"_id":"Templ8@0.3.0","dependencies":{},"devDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.0.30","_nodeVersion":"v0.4.12","_defaultsLoaded":true,"dist":{"shasum":"3dc8f631b0033956c2aedd6c40a2108e34dc978f","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.3.0.tgz","integrity":"sha512-E1q8I4reRDdpExJtIL8yd8ms8+/TxIJKkJcldcY8/ZMBPQmNfgaM3Q7H+cKNf4KCnGZaH+TfWHtuixNhCIn5+w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIApO4pjSElDqQ9Q+vimRihCvgDumJHQoDUHo+ohMgvkgAiEAkt17pbrmuzLHDv+W9SXwZjWn+/zmBPUQpUm1Uz41waw="}]},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.5.0":{"author":{"name":"constantology","email":"constantology@gmail.com","url":"http://muigui.com"},"description":"JavaScript Client/ Server Template Engine","keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"version":"0.5.0","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"_id":"Templ8@0.5.0","dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.1","_nodeVersion":"v0.6.11","_defaultsLoaded":true,"dist":{"shasum":"77f16db596878514b34b9a26ea5bfe11b7987a63","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.5.0.tgz","integrity":"sha512-1lUkj9QUvppjeF8Y+71GlI+5ZYGMJY9EG32mx6AYMkcCEh9clW7vdLYYH1X3FjgnPaWQ3gyDIjSOU/JdA0deAA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCGl3CvX90QvNpmJb3TYpZaA5BIIXZOUP+hK/qc/SJdvgIgSbXb37NdJG5orPM0K0zTg/Z0fJp0H3SAVYUKtcgzl+w="}]},"readme":"#TODO:\n\n- documentation is not yet complete\n- add unit tests (already have tests: just wanting to port them from my own framework to an existing one like JSTestDriver or something).\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## Usage\nTempl8 is avaiable as a Node JS module as well as a browser micro-framework.\n\n### Node\n\n#### Installation\n```\n   npm install Templ8\n```\n#### Requiring\n```javascript\n   var Templ8 = require( 'Templ8' );\n```\n\n### Browser\n\nYou have 2 options.\n\n1. `Templ8.js`/ `Templ8.min.js` are the dev/ prod versions optimised for modern browsers (i.e. browsers that have implemented all of the items in [kangax's es5 compatability table](http://kangax.github.com/es5-compat-table/)).\n2. `Templ8.shim.js`/ `Templ8.shim.min.js` are as above, except that [wedgES](https://github.com/constantology/wedgES) – only an extra 1.6kb – has been included to enable backwards compatibility with older browsers.\n\n**NOTE:** Safari <= 5.1.3 still has not implemented `Function.prototype.bind` so you will need to use `Templ8.shim.js` for Safari.\n\n**NOTE:** The shimmed methods **will not** overwrite any native implementations.\n\n## File size\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t<tbody>\n\t\t<tr><td>Templ8.js</td><td>6.7kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.min.js</td><td>5.1kb</td><td>uglified + deflate</td>\n\t\t<tr><td>Templ8.shim.js</td><td>8.5kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.shim.min.js</td><td>6.5kb</td><td>uglified + deflate</td>\n\t</tbody>\n</table>\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the curent iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of thecurrent iteration.</td>\n</tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>previous</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt has the following extra properties available for **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>firstKey</strong></td><td>The key of the first item in the Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Object.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Object.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>previousKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns true if there is a value after the current iteration to iterate over. Otherwise it will return false.</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the iterating, once it finishes it's current iteration.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C or \\_\\_CONTEXT\\_\\_\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>destroy</strong></td><td>destroys the ContextStack.</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_\n\nThis is where all parsed template output is stored. It is an instance of an internal class call **Output**.\n\nIt has two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>join</strong></td><td>returns the output of the Templ8 instance.</td>\n</tr><tr>\n\t<td><strong>push</strong></td><td>adds a String representation of the passed parameter to the Templ8 instance's output.</td>\n</tr>\n</table>\n\n##### \\_\\_ASSERT\\_\\_\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.6.0":{"author":{"name":"constantology","email":"constantology@gmail.com","url":"http://muigui.com"},"description":"JavaScript Client/ Server Template Engine","devDependencies":{"priv8i":">= 0.0.1"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"version":"0.6.0","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"_id":"Templ8@0.6.0","dependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.1","_nodeVersion":"v0.6.11","_defaultsLoaded":true,"dist":{"shasum":"95b53b36d33034b1203ddb5363df4f53a67872de","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.6.0.tgz","integrity":"sha512-j7s/HprKRancrzbfHvQIJ4UZFJOJ7jcXJikLa34czIEOK3BDsVnuYMcfjJ53zV5J8k0xwhAHYewiNy2w7KpjUA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICE2kxVhFknjXD2YP3qxBgYiy8C2cAlf7JRexNhf+9HnAiEA+BvO9W9ID27h8z3iTlSFq/k3PcIxxS1BjSH6x3N40YA="}]},"readme":"#TODO:\n\n- documentation is not yet complete\n- add unit tests (already have tests: just wanting to port them from my own framework to an existing one like JSTestDriver or something).\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## Usage\nTempl8 is avaiable as a Node JS module as well as a browser micro-framework.\n\n### Node\n\n#### Installation\n```\n   npm install Templ8\n```\n#### Requiring\n```javascript\n   var Templ8 = require( 'Templ8' );\n```\n\n### Browser\n\nYou have 2 options.\n\n1. `Templ8.js`/ `Templ8.min.js` are the dev/ prod versions optimised for modern browsers (i.e. browsers that have implemented all of the items in [kangax's es5 compatability table](http://kangax.github.com/es5-compat-table/)).\n2. `Templ8.shim.js`/ `Templ8.shim.min.js` are as above, except that [wedgES](https://github.com/constantology/wedgES) – only an extra 1.6kb – has been included to enable backwards compatibility with older browsers.\n\n**NOTE:** Safari <= 5.1.3 still has not implemented `Function.prototype.bind` so you will need to use `Templ8.shim.js` for Safari.\n\n**NOTE:** The shimmed methods **will not** overwrite any native implementations.\n\n## File size\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t<tbody>\n\t\t<tr><td>Templ8.js</td><td>6.7kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.min.js</td><td>5.1kb</td><td>uglified + deflate</td>\n\t\t<tr><td>Templ8.shim.js</td><td>8.5kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.shim.min.js</td><td>6.5kb</td><td>uglified + deflate</td>\n\t</tbody>\n</table>\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the curent iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of thecurrent iteration.</td>\n</tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>previous</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt has the following extra properties available for **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>firstKey</strong></td><td>The key of the first item in the Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Object.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Object.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>previousKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns true if there is a value after the current iteration to iterate over. Otherwise it will return false.</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the iterating, once it finishes it's current iteration.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C or \\_\\_CONTEXT\\_\\_\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>destroy</strong></td><td>destroys the ContextStack.</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_\n\nThis is where all parsed template output is stored. It is an instance of an internal class call **Output**.\n\nIt has two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>join</strong></td><td>returns the output of the Templ8 instance.</td>\n</tr><tr>\n\t<td><strong>push</strong></td><td>adds a String representation of the passed parameter to the Templ8 instance's output.</td>\n</tr>\n</table>\n\n##### \\_\\_ASSERT\\_\\_\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.7.0":{"author":{"name":"constantology","email":"constantology@gmail.com","url":"http://muigui.com"},"description":"JavaScript Client/ Server Template Engine","devDependencies":{"priv8i":">= 0.0.1"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"version":"0.7.0","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"_id":"Templ8@0.7.0","dependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.1","_nodeVersion":"v0.6.11","_defaultsLoaded":true,"dist":{"shasum":"d0203db2493db8a150b2c340810b6c1ccefd85c1","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.7.0.tgz","integrity":"sha512-dT4Vs6leMi/bGAX6eNZH3hGePi+xeLCxSRXKY3CzgO+CozDQjITA+Q/bwMy2OvSeHlI2/cXqoTQhSULBoXTd9g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICrrehBUTwBaRZrBBjhAfR4vHeO24EFeiT9o3uMAS5QQAiEA0/vCrRHc3czpISvFQF14OPbcb+x3AnSk58jQsjjF/jY="}]},"readme":"#TODO:\n\n- documentation is not yet complete\n- add unit tests (already have tests: just wanting to port them from my own framework to an existing one like JSTestDriver or something).\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## Usage\nTempl8 is avaiable as a Node JS module as well as a browser micro-framework.\n\n### Node\n\n#### Installation\n```\n   npm install Templ8\n```\n#### Requiring\n```javascript\n   var Templ8 = require( 'Templ8' );\n```\n\n### Browser\n\nYou have 2 options.\n\n1. `Templ8.js`/ `Templ8.min.js` are the dev/ prod versions optimised for modern browsers (i.e. browsers that have implemented all of the items in [kangax's es5 compatability table](http://kangax.github.com/es5-compat-table/)).\n2. `Templ8.shim.js`/ `Templ8.shim.min.js` are as above, except that [wedgES](https://github.com/constantology/wedgES) – only an extra 1.6kb – has been included to enable backwards compatibility with older browsers.\n\n**NOTE:** Safari <= 5.1.3 still has not implemented `Function.prototype.bind` so you will need to use `Templ8.shim.js` for Safari.\n\n**NOTE:** The shimmed methods **will not** overwrite any native implementations.\n\n## File size\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t<tbody>\n\t\t<tr><td>Templ8.js</td><td>6.7kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.min.js</td><td>5.1kb</td><td>uglified + deflate</td>\n\t\t<tr><td>Templ8.shim.js</td><td>8.5kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.shim.min.js</td><td>6.5kb</td><td>uglified + deflate</td>\n\t</tbody>\n</table>\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the curent iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of thecurrent iteration.</td>\n</tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>previous</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt has the following extra properties available for **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>firstKey</strong></td><td>The key of the first item in the Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Object.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Object.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>previousKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns true if there is a value after the current iteration to iterate over. Otherwise it will return false.</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the iterating, once it finishes it's current iteration.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C or \\_\\_CONTEXT\\_\\_\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>destroy</strong></td><td>destroys the ContextStack.</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_\n\nThis is where all parsed template output is stored. It is an instance of an internal class call **Output**.\n\nIt has two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>join</strong></td><td>returns the output of the Templ8 instance.</td>\n</tr><tr>\n\t<td><strong>push</strong></td><td>adds a String representation of the passed parameter to the Templ8 instance's output.</td>\n</tr>\n</table>\n\n##### \\_\\_ASSERT\\_\\_\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.7.1":{"author":{"name":"constantology","email":"constantology@gmail.com","url":"http://muigui.com"},"description":"JavaScript Client/ Server Template Engine","devDependencies":{"priv8i":">= 0.0.1"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"version":"0.7.1","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"_id":"Templ8@0.7.1","dependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.1","_nodeVersion":"v0.6.11","_defaultsLoaded":true,"dist":{"shasum":"ad6f5c8b64a1f729bbe3545208a31f641365c42c","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.7.1.tgz","integrity":"sha512-q9q86UtFetoSX5sfkIgw5jCeyCqHfz3jVDHBVLbWMJlBhJoGBKcXYR7ZbXim0UA50JSOsRGsxGTrcUzQqdESCw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD2XrB3HzcLNnFinD3TIOzr6CmWYAmXl0ATmzoqi2SCWQIgOwU4GjllWKXUStXttvnsc72O8D+Mlot5i4e/a756Bu0="}]},"readme":"#TODO:\n\n- documentation is not yet complete\n- add unit tests (already have tests: just wanting to port them from my own framework to an existing one like JSTestDriver or something).\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## Usage\nTempl8 is avaiable as a Node JS module as well as a browser micro-framework.\n\n### Node\n\n#### Installation\n```\n   npm install Templ8\n```\n#### Requiring\n```javascript\n   var Templ8 = require( 'Templ8' );\n```\n\n### Browser\n\nYou have 2 options.\n\n1. `Templ8.js`/ `Templ8.min.js` are the dev/ prod versions optimised for modern browsers (i.e. browsers that have implemented all of the items in [kangax's es5 compatability table](http://kangax.github.com/es5-compat-table/)).\n2. `Templ8.shim.js`/ `Templ8.shim.min.js` are as above, except that [wedgES](https://github.com/constantology/wedgES) – only an extra 1.6kb – has been included to enable backwards compatibility with older browsers.\n\n**NOTE:** Safari <= 5.1.3 still has not implemented `Function.prototype.bind` so you will need to use `Templ8.shim.js` for Safari.\n\n**NOTE:** The shimmed methods **will not** overwrite any native implementations.\n\n## File size\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t<tbody>\n\t\t<tr><td>Templ8.js</td><td>6.7kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.min.js</td><td>5.1kb</td><td>uglified + deflate</td>\n\t\t<tr><td>Templ8.shim.js</td><td>8.5kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.shim.min.js</td><td>6.5kb</td><td>uglified + deflate</td>\n\t</tbody>\n</table>\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the curent iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of thecurrent iteration.</td>\n</tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>previous</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt has the following extra properties available for **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>firstKey</strong></td><td>The key of the first item in the Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Object.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Object.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>previousKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns true if there is a value after the current iteration to iterate over. Otherwise it will return false.</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the iterating, once it finishes it's current iteration.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C or \\_\\_CONTEXT\\_\\_\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>destroy</strong></td><td>destroys the ContextStack.</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_\n\nThis is where all parsed template output is stored. It is an instance of an internal class call **Output**.\n\nIt has two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>join</strong></td><td>returns the output of the Templ8 instance.</td>\n</tr><tr>\n\t<td><strong>push</strong></td><td>adds a String representation of the passed parameter to the Templ8 instance's output.</td>\n</tr>\n</table>\n\n##### \\_\\_ASSERT\\_\\_\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.7.2":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"description":"JavaScript Client/ Server Template Engine","devDependencies":{"priv8i":">= 0.0.1"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"version":"0.7.2","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"_id":"Templ8@0.7.2","dependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.4","_nodeVersion":"v0.6.12","_defaultsLoaded":true,"dist":{"shasum":"e8062ccf89043e901362fda454ee349a37a6d0c5","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.7.2.tgz","integrity":"sha512-qHQz4gOwKhLvF9mX//w7Guqd2oXPjnpFRU360X1bnMcjTBEDDYP5Gy1Lzx5c53nph1XxfdPmUdO1gWe19T5vUw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCqP1OiOOVEkASxerUXTtxs/CsxPxHlJI4w/Q+1jFmKSQIhALGFuhGD4J4NGuel7EvgCa8WVbSFojOUKfmStVQm6p16"}]},"readme":"#TODO:\n\n- documentation is not yet complete\n- add unit tests (already have tests: just wanting to port them from my own framework to an existing one like JSTestDriver or something).\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## Usage\nTempl8 is avaiable as a Node JS module as well as a browser micro-framework.\n\n### Node\n\n#### Installation\n```\n   npm install Templ8\n```\n#### Requiring\n```javascript\n   var Templ8 = require( 'Templ8' );\n```\n\n### Browser\n\nYou have 2 options.\n\n1. `Templ8.js`/ `Templ8.min.js` are the dev/ prod versions optimised for modern browsers (i.e. browsers that have implemented all of the items in [kangax's es5 compatability table](http://kangax.github.com/es5-compat-table/)).\n2. `Templ8.shim.js`/ `Templ8.shim.min.js` are as above, except that [wedgES](https://github.com/constantology/wedgES) – only an extra 1.6kb – has been included to enable backwards compatibility with older browsers.\n\n**NOTE:** Safari <= 5.1.3 still has not implemented `Function.prototype.bind` so you will need to use `Templ8.shim.js` for Safari.\n\n**NOTE:** The shimmed methods **will not** overwrite any native implementations.\n\n## File size\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t<tbody>\n\t\t<tr><td>Templ8.js</td><td>6.7kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.min.js</td><td>5.1kb</td><td>uglified + deflate</td>\n\t\t<tr><td>Templ8.shim.js</td><td>8.5kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.shim.min.js</td><td>6.5kb</td><td>uglified + deflate</td>\n\t</tbody>\n</table>\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the curent iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of thecurrent iteration.</td>\n</tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>previous</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt has the following extra properties available for **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>firstKey</strong></td><td>The key of the first item in the Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Object.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Object.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>previousKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns true if there is a value after the current iteration to iterate over. Otherwise it will return false.</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the iterating, once it finishes it's current iteration.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C or \\_\\_CONTEXT\\_\\_\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>destroy</strong></td><td>destroys the ContextStack.</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_\n\nThis is where all parsed template output is stored. It is an instance of an internal class call **Output**.\n\nIt has two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>join</strong></td><td>returns the output of the Templ8 instance.</td>\n</tr><tr>\n\t<td><strong>push</strong></td><td>adds a String representation of the passed parameter to the Templ8 instance's output.</td>\n</tr>\n</table>\n\n##### \\_\\_ASSERT\\_\\_\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.8.0":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"description":"JavaScript Client/ Server Template Engine","devDependencies":{"priv8i":">= 0.0.1"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"version":"0.8.0","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"_id":"Templ8@0.8.0","dependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.4","_nodeVersion":"v0.6.12","_defaultsLoaded":true,"dist":{"shasum":"1751663029579040f4851d18e3c56339bb96d372","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.8.0.tgz","integrity":"sha512-2MlW1M8GlHJlmRnz++/5SRC5tt+RqZXap1rF2E0ji4t2wAIqhx48Hu/yYr17uLhUAgZWGCtLNsvSyPY1fj8aOA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCObp2jnNjJC99KttYfS5WRZgWsVUdPX/K8nbfqAqPWsgIgbqzll+q3YoPL1fiJro+0x7pY5TTGs6reS++BL4IYYtM="}]},"readme":"#TODO:\n\n- documentation is not yet complete\n- add unit tests (already have tests: just wanting to port them from my own framework to an existing one like JSTestDriver or something).\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## Usage\nTempl8 is avaiable as a Node JS module as well as a browser micro-framework.\n\n### Node\n\n#### Installation\n```\n   npm install Templ8\n```\n#### Requiring\n```javascript\n   var Templ8 = require( 'Templ8' );\n```\n\n### Browser\n\nYou have 2 options.\n\n1. `Templ8.js`/ `Templ8.min.js` are the dev/ prod versions optimised for modern browsers (i.e. browsers that have implemented all of the items in [kangax's es5 compatability table](http://kangax.github.com/es5-compat-table/)).\n2. `Templ8.shim.js`/ `Templ8.shim.min.js` are as above, except that [wedgES](https://github.com/constantology/wedgES) – only an extra 1.6kb – has been included to enable backwards compatibility with older browsers.\n\n**NOTE:** Safari <= 5.1.3 still has not implemented `Function.prototype.bind` so you will need to use `Templ8.shim.js` for Safari.\n\n**NOTE:** The shimmed methods **will not** overwrite any native implementations.\n\n## File size\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t<tbody>\n\t\t<tr><td>Templ8.js</td><td>6.7kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.min.js</td><td>5.1kb</td><td>uglified + deflate</td>\n\t\t<tr><td>Templ8.shim.js</td><td>8.5kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.shim.min.js</td><td>6.5kb</td><td>uglified + deflate</td>\n\t</tbody>\n</table>\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the curent iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of thecurrent iteration.</td>\n</tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>previous</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt has the following extra properties available for **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>firstKey</strong></td><td>The key of the first item in the Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Object.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Object.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>previousKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns true if there is a value after the current iteration to iterate over. Otherwise it will return false.</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the iterating, once it finishes it's current iteration.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C or \\_\\_CONTEXT\\_\\_\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>destroy</strong></td><td>destroys the ContextStack.</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_\n\nThis is where all parsed template output is stored. It is an instance of an internal class call **Output**.\n\nIt has two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>join</strong></td><td>returns the output of the Templ8 instance.</td>\n</tr><tr>\n\t<td><strong>push</strong></td><td>adds a String representation of the passed parameter to the Templ8 instance's output.</td>\n</tr>\n</table>\n\n##### \\_\\_ASSERT\\_\\_\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.0":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 0.5.0","mkdirp":">= 0.3.0","n8iv":">= 0.1.0","uglify-js":">= 1.2.5"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"version":"0.9.0","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"_id":"Templ8@0.9.0","devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.4","_nodeVersion":"v0.6.12","_defaultsLoaded":true,"dist":{"shasum":"f7eb21bead586b49086531dc425325c5c53eedca","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.0.tgz","integrity":"sha512-wN3yAE9lb9xN63t9gHDBsjnaomQ/lz4nDUZAfjCwHrPZzFONljGIAV/SnrCOy4VoowoZOEVZAPKONVKBs040qQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHY60r5QUrEPWHPiNZtrtr0mtFOi9DZ0ajaGlJXh9p9XAiEAhE9KwUYXlDAd6NGlxK8FSP9OUVkA49fVPuFp5WsCePk="}]},"readme":"#TODO:\n\n- documentation is not yet complete\n- add unit tests (already have tests: just wanting to port them from my own framework to an existing one like JSTestDriver or something).\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## Usage\nTempl8 is avaiable as a Node JS module as well as a browser micro-framework.\n\n### Node\n\n#### Installation\n```\n   npm install Templ8\n```\n#### Requiring\n```javascript\n   var Templ8 = require( 'Templ8' );\n```\n\n### Browser\n\nYou have 2 options.\n\n1. `Templ8.js`/ `Templ8.min.js` are the dev/ prod versions optimised for modern browsers (i.e. browsers that have implemented all of the items in [kangax's es5 compatability table](http://kangax.github.com/es5-compat-table/)).\n2. `Templ8.shim.js`/ `Templ8.shim.min.js` are as above, except that [wedgES](https://github.com/constantology/wedgES) – only an extra 1.6kb – has been included to enable backwards compatibility with older browsers.\n\n**NOTE:** Safari <= 5.1.3 still has not implemented `Function.prototype.bind` so you will need to use `Templ8.shim.js` for Safari.\n\n**NOTE:** The shimmed methods **will not** overwrite any native implementations.\n\n## File size\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t<tbody>\n\t\t<tr><td>Templ8.js</td><td>7kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.min.js</td><td>5.2kb</td><td>uglified + deflate</td>\n\t\t<tr><td>Templ8.shim.js</td><td>8.8kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.shim.min.js</td><td>6.6kb</td><td>uglified + deflate</td>\n\t</tbody>\n</table>\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the curent iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of thecurrent iteration.</td>\n</tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>previous</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt has the following extra properties available for **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>firstKey</strong></td><td>The key of the first item in the Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Object.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Object.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>previousKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns true if there is a value after the current iteration to iterate over. Otherwise it will return false.</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the iterating, once it finishes it's current iteration.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C or \\_\\_CONTEXT\\_\\_\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>destroy</strong></td><td>destroys the ContextStack.</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_\n\nThis is where all parsed template output is stored. It is an instance of an internal class call **Output**.\n\nIt has two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>join</strong></td><td>returns the output of the Templ8 instance.</td>\n</tr><tr>\n\t<td><strong>push</strong></td><td>adds a String representation of the passed parameter to the Templ8 instance's output.</td>\n</tr>\n</table>\n\n##### \\_\\_ASSERT\\_\\_\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.1":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 0.5.0","mkdirp":">= 0.3.0","n8iv":">= 0.1.0","uglify-js":">= 1.2.5"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"version":"0.9.1","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"_id":"Templ8@0.9.1","devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.4","_nodeVersion":"v0.6.12","_defaultsLoaded":true,"dist":{"shasum":"10b6c2b3e02ccf8cabd29be42d3eb0f776d1441c","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.1.tgz","integrity":"sha512-ixD3+GISu5gY90tpk+YIeZWbR1HTCY7cv81vHo8VIvXXbO01JvAOI1zyHxFyu16B330Ce786qOhFs5HCJYqUVw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIB3mFwakjmzcUAZxG8+fwvDNYIN7vPwPscExccpC/AusAiB5S/ctWuKab9+Pm9i3xPrcoPmz/S5tOSYc6vr+3hAWGQ=="}]},"readme":"#TODO:\n\n- documentation is not yet complete\n- add unit tests (already have tests: just wanting to port them from my own framework to an existing one like JSTestDriver or something).\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## Usage\nTempl8 is avaiable as a Node JS module as well as a browser micro-framework.\n\n### Node\n\n#### Installation\n```\n   npm install Templ8\n```\n#### Requiring\n```javascript\n   var Templ8 = require( 'Templ8' );\n```\n\n### Browser\n\nYou have 2 options.\n\n1. `Templ8.js`/ `Templ8.min.js` are the dev/ prod versions optimised for modern browsers (i.e. browsers that have implemented all of the items in [kangax's es5 compatability table](http://kangax.github.com/es5-compat-table/)).\n2. `Templ8.shim.js`/ `Templ8.shim.min.js` are as above, except that [wedgES](https://github.com/constantology/wedgES) – only an extra 1.6kb – has been included to enable backwards compatibility with older browsers.\n\n**NOTE:** Safari <= 5.1.3 still has not implemented `Function.prototype.bind` so you will need to use `Templ8.shim.js` for Safari.\n\n**NOTE:** The shimmed methods **will not** overwrite any native implementations.\n\n## File size\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t<tbody>\n\t\t<tr><td>Templ8.js</td><td>6.9kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.min.js</td><td>5.2kb</td><td>uglified + deflate</td>\n\t\t<tr><td>Templ8.shim.js</td><td>8.9kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.shim.min.js</td><td>6.8kb</td><td>uglified + deflate</td>\n\t\t<tr><td>Templ8.Filter.html.js</td><td>0.59kb</td><td>deflate</td>\n\t</tbody>\n</table>\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the curent iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of thecurrent iteration.</td>\n</tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>previous</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt has the following extra properties available for **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>firstKey</strong></td><td>The key of the first item in the Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Object.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Object.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>previousKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns true if there is a value after the current iteration to iterate over. Otherwise it will return false.</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the iterating, once it finishes it's current iteration.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C or \\_\\_CONTEXT\\_\\_\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>destroy</strong></td><td>destroys the ContextStack.</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_\n\nThis is where all parsed template output is stored. It is an instance of an internal class call **Output**.\n\nIt has two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>join</strong></td><td>returns the output of the Templ8 instance.</td>\n</tr><tr>\n\t<td><strong>push</strong></td><td>adds a String representation of the passed parameter to the Templ8 instance's output.</td>\n</tr>\n</table>\n\n##### \\_\\_ASSERT\\_\\_\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.2":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 0.5.0","mkdirp":">= 0.3.0","n8iv":">= 0.1.0","uglify-js":">= 1.2.5"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"version":"0.9.2","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"_id":"Templ8@0.9.2","devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.12","_nodeVersion":"v0.6.14","_defaultsLoaded":true,"dist":{"shasum":"56bbfc2fd42e682f8fab284283a8f7c1210f0641","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.2.tgz","integrity":"sha512-97gI47nqWBs1FmN0EuXvZA2xR3fOZ3jwTC5bk4gXtbD1qGKwxKh4sZFAN7od6tWFarqSIEFX0M/8kvnGChN/oQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDLnoD2BgLHsLpe0NySn0S+DRqsCnBBh+7vzMnaf3avigIgUfnkS0Ai9WF0lf1DienXbpcDrkvr2XfbiNoiLBw7Bd0="}]},"readme":"#TODO:\n\n- documentation is not yet complete\n- add unit tests (already have tests: just wanting to port them from my own framework to an existing one like JSTestDriver or something).\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## Usage\nTempl8 is avaiable as a Node JS module as well as a browser micro-framework.\n\n### Node\n\n#### Installation\n```\n   npm install Templ8\n```\n#### Requiring\n```javascript\n   var Templ8 = require( 'Templ8' );\n```\n\n### Browser\n\nYou have 2 options.\n\n1. `Templ8.js`/ `Templ8.min.js` are the dev/ prod versions optimised for modern browsers (i.e. browsers that have implemented all of the items in [kangax's es5 compatability table](http://kangax.github.com/es5-compat-table/)).\n2. `Templ8.shim.js`/ `Templ8.shim.min.js` are as above, except that [wedgES](https://github.com/constantology/wedgES) – only an extra 1.6kb – has been included to enable backwards compatibility with older browsers.\n\n**NOTE:** Safari <= 5.1.3 still has not implemented `Function.prototype.bind` so you will need to use `Templ8.shim.js` for Safari.\n\n**NOTE:** The shimmed methods **will not** overwrite any native implementations.\n\n## File size\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t<tbody>\n\t\t<tr><td>Templ8.js</td><td>6.9kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.min.js</td><td>5.2kb</td><td>uglified + deflate</td>\n\t\t<tr><td>Templ8.shim.js</td><td>8.9kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.shim.min.js</td><td>6.8kb</td><td>uglified + deflate</td>\n\t\t<tr><td>Templ8.Filter.html.js</td><td>0.59kb</td><td>deflate</td>\n\t</tbody>\n</table>\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the curent iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of thecurrent iteration.</td>\n</tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>previous</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt has the following extra properties available for **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>firstKey</strong></td><td>The key of the first item in the Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Object.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Object.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>previousKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns true if there is a value after the current iteration to iterate over. Otherwise it will return false.</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the iterating, once it finishes it's current iteration.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C or \\_\\_CONTEXT\\_\\_\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>destroy</strong></td><td>destroys the ContextStack.</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_\n\nThis is where all parsed template output is stored. It is an instance of an internal class call **Output**.\n\nIt has two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>join</strong></td><td>returns the output of the Templ8 instance.</td>\n</tr><tr>\n\t<td><strong>push</strong></td><td>adds a String representation of the passed parameter to the Templ8 instance's output.</td>\n</tr>\n</table>\n\n##### \\_\\_ASSERT\\_\\_\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.3":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"m8":">= 0.1.0","commander":">= 0.5.0","mkdirp":">= 0.3.0","n8iv":">= 0.1.0","uglify-js":">= 1.2.5"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"version":"0.9.3","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"_id":"Templ8@0.9.3","devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.16","_nodeVersion":"v0.6.15","_defaultsLoaded":true,"dist":{"shasum":"c9cd5282e85e5ca3f132144ef30eef171bcfc960","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.3.tgz","integrity":"sha512-M2EMpY9om9GIzqQ5/pXFKjQu31FtrmVxyDbActg/0ax1Di4ZlPT9lvMjptBVGxh599ejfeslgIbr+/aPXw8NpA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCP2j0g8GBwSDbWeSTLTydt82H6geQdwWbVDISqy9d0bQIhALMMzVNBF0uB3IiSqAs903KrFS9k1mQjVgi+J5tcC1VZ"}]},"readme":"#TODO:\n\n- documentation is not yet complete\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## WARNING!!!\nWhile **Templ8** has been tested, the testing framework I've written and used is very much a work in progress.\n\nAlso I'm currently between virtual machine software and operating system licenses, so I have only tested on mac osx lion and snow leopard: nodejs – >= v0.613 – as well as current – and beta/ nightly – versions of Chrome, Safari/ Webkit and FireFox.\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## File size\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t<tbody>\n\t\t<tr><td>Templ8.js</td><td>6.6kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.min.js</td><td>5.0kb</td><td>uglified + deflate</td>\n\t\t<tr><td>Templ8.Filter.html.js</td><td>0.59kb</td><td>deflate</td>\n\t</tbody>\n</table>\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the curent iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of thecurrent iteration.</td>\n</tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>previous</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt has the following extra properties available for **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>firstKey</strong></td><td>The key of the first item in the Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Object.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Object.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>previousKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns true if there is a value after the current iteration to iterate over. Otherwise it will return false.</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the iterating, once it finishes it's current iteration.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C or \\_\\_CONTEXT\\_\\_\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>destroy</strong></td><td>destroys the ContextStack.</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_\n\nThis is where all parsed template output is stored. It is an instance of an internal class call **Output**.\n\nIt has two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>join</strong></td><td>returns the output of the Templ8 instance.</td>\n</tr><tr>\n\t<td><strong>push</strong></td><td>adds a String representation of the passed parameter to the Templ8 instance's output.</td>\n</tr>\n</table>\n\n##### \\_\\_ASSERT\\_\\_\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.4":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"m8":">= 0.1.0","commander":">= 0.5.0","mkdirp":">= 0.3.0","n8iv":">= 0.1.0","uglify-js":">= 1.2.5"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"version":"0.9.4","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"_id":"Templ8@0.9.4","devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.16","_nodeVersion":"v0.6.15","_defaultsLoaded":true,"dist":{"shasum":"470c81cbc7e921d0e9bb37d2ad3a5923124326e3","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.4.tgz","integrity":"sha512-M4uO3GB+cBNAePOpwMhoG6fgwFPLIxtLqwUfMlBFoN29I5uZaCkbJuwguyZod6Acsxpw33KNonpIO2zUIC7Wjg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCqjjdwR2f60msS7i7ZCm920IkPOtUsdGTmOT/btsNppAIhALRxJtd5/Uqj8s55WEudNMbWzq2cfFORq5wJh2dp0yc+"}]},"readme":"#TODO:\n\n- documentation is not yet complete\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## WARNING!!!\nWhile **Templ8** has been tested, the testing framework I've written and used is very much a work in progress.\n\nAlso I'm currently between virtual machine software and operating system licenses, so I have only tested on mac osx lion and snow leopard: nodejs – >= v0.6.13 – as well as current – and beta/ nightly – versions of Chrome, Safari/ Webkit and FireFox.\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## File size\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t<tbody>\n\t\t<tr><td>Templ8.js</td><td>6.6kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.min.js</td><td>5.0kb</td><td>uglified + deflate</td>\n\t\t<tr><td>Templ8.Filter.html.js</td><td>0.59kb</td><td>deflate</td>\n\t</tbody>\n</table>\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the curent iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of thecurrent iteration.</td>\n</tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>previous</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt has the following extra properties available for **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>firstKey</strong></td><td>The key of the first item in the Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Object.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Object.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>previousKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns true if there is a value after the current iteration to iterate over. Otherwise it will return false.</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the iterating, once it finishes it's current iteration.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>destroy</strong></td><td>destroys the ContextStack.</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.5":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"m8":">= 0.1.0","commander":">= 0.5.0","mkdirp":">= 0.3.0","n8iv":">= 0.1.0","uglify-js":">= 1.2.5"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"version":"0.9.5","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"_id":"Templ8@0.9.5","devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.16","_nodeVersion":"v0.6.15","_defaultsLoaded":true,"dist":{"shasum":"3bebf949dc4f29e23434818fb6adc02a5f3be328","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.5.tgz","integrity":"sha512-bJhA8T4aha11K5Xut+BoPpRJrOv9/X6QcmXYTt7VliLpPLipAadgZjNv7amGIo2WT0k6L3074G8Q6+KFGDoWyg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC3gDTffHzmwhqjPHrFFxJH8oQxrkemiG2nmehyFHKlZAIhAMLlbagkTc33bZNnO5WylwT9VjiHogqjfRrV9nqgAAGH"}]},"readme":"#TODO:\n\n- documentation is not yet complete\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## WARNING!!!\nWhile **Templ8** has been tested, the testing framework I've written and used is very much a work in progress.\n\nAlso I'm currently between virtual machine software and operating system licenses, so I have only tested on mac osx lion and snow leopard: nodejs – >= v0.6.13 – as well as current – and beta/ nightly – versions of Chrome, Safari/ Webkit and FireFox.\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## File size\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t<tbody>\n\t\t<tr><td>Templ8.js</td><td>6.6kb</td><td>deflate</td>\n\t\t<tr><td>Templ8.min.js</td><td>5.0kb</td><td>uglified + deflate</td>\n\t\t<tr><td>Templ8.Filter.html.js</td><td>0.59kb</td><td>deflate</td>\n\t</tbody>\n</table>\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the curent iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of thecurrent iteration.</td>\n</tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>previous</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt has the following extra properties available for **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>firstKey</strong></td><td>The key of the first item in the Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Object.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Object.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>previousKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns true if there is a value after the current iteration to iterate over. Otherwise it will return false.</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the iterating, once it finishes it's current iteration.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>destroy</strong></td><td>destroys the ContextStack.</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.6":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"m8":">= 0.1.0","commander":">= 0.5.0","mkdirp":">= 0.3.0","n8iv":">= 0.1.0","uglify-js":">= 1.2.5"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"version":"0.9.6","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"_id":"Templ8@0.9.6","devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.21","_nodeVersion":"v0.6.18","_defaultsLoaded":true,"dist":{"shasum":"95ff0c19f7e374b1f4744cd84ea373a08aeeb68e","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.6.tgz","integrity":"sha512-u0VlKyuQBDTyDdtFmzDCOX/meOiUfPoANMu4Ly3gclcQQuc7byQWrgAcRJl8rCM7XK9uqxM3nfywfutYwenpKg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFLfvx+lK0nFGbiy84Lc9OR4+M3kVDyR3ckfDhY2X+O6AiEAuS4891SWSgxD4GTcIngiuh+WQtjV3H+hfhDIqZyMY+I="}]},"readme":"#TODO:\n\n- documentation is not yet complete\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## WARNING!!!\nWhile **Templ8** has been tested, the testing framework I've written and used is very much a work in progress.\n\nAlso I'm currently between virtual machine software and operating system licenses, so I have only tested on mac osx lion and snow leopard: nodejs – >= v0.6.13 – as well as current – and beta/ nightly – versions of Chrome, Safari/ Webkit and FireFox.\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.7":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"m8":">= 0.1.0","commander":">= 0.5.0","mkdirp":">= 0.3.0","n8iv":">= 0.1.0"},"devDependencies":{"mocha":">= 1.3.0","uglify-js":">= 1.2.5"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --globals mocha,expect,m8,Templ8,tpl_test_value -R spec -u tdd ./test"},"version":"0.9.7","readme":"#TODO:\n\n- documentation is not yet complete\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"Templ8@0.9.7","dist":{"shasum":"62abfb8df14130ce4185f8a443b677d6c225946c","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.7.tgz","integrity":"sha512-8C+FTmHWUyBIddEUdaz4jsOjPLRWy9ZMfkqNKPswu4Fs4sGAQdq8rsV8fATn7l4x/tkQVDLw9oNLVs3cyaTcSg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCIP1S7eNHTCmF5PfZYtHqsUIrK1RPA5/sgxrZHNdiubgIhAPdH98HzoPZGHaewotE1RUHHlQSJADBA4b1hJB13FANR"}]},"_npmVersion":"1.1.49","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.8":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"m8":">= 0.1.0","commander":">= 0.5.0","mkdirp":">= 0.3.0","n8iv":">= 0.1.0"},"devDependencies":{"mocha":">= 1.3.0","uglify-js":">= 1.2.5"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --globals mocha,expect,m8,Templ8,tpl_test_value -R spec -u tdd ./test"},"version":"0.9.8","readme":"#TODO:\n\n- documentation is not yet complete\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"Templ8@0.9.8","dist":{"shasum":"4939b3b9c956d4b2045c98f76a7dd3c7ca4a9f24","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.8.tgz","integrity":"sha512-J2rgIDcagdDCVkdUjv5roKXUh2zoxoLTk3pPdzCkdm4ECY35bXY5qHo0/1P48v6tL6C0Bqe6NOML9azGPqzjAw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCCcjBRLB+1FCGz/hVXonwyYvgdXOhDQKWBFXz4xfrEWQIgVN39GeqcFtL/0ZHn1IH9wmXMRo4Efjtjk2L+q3b/IFI="}]},"_npmVersion":"1.1.49","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.9":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"m8":">= 0.1.0","commander":">= 0.5.0","mkdirp":">= 0.3.0","n8iv":">= 0.1.0"},"devDependencies":{"mocha":">= 1.3.0","uglify-js":">= 1.2.5"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8.js","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --globals mocha,expect,m8,Templ8,tpl_test_value -R spec -u tdd ./test"},"version":"0.9.9","readme":"#TODO:\n\n- documentation is not yet complete\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"Templ8@0.9.9","dist":{"shasum":"03e8feb95e7d4ea6f67b54c344e39d7093a1116b","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.9.tgz","integrity":"sha512-kVU4GL+kkaSJHVu0hSecRiywB5ma3eBKI5iqXMRvfJ+vp5JroQRYNWLhgufQJYNSl3Pme1hzf2AgvFgDLQeFSQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIC4ddOaUYndeUg+4dsxLb0QDobp6BYJoD8NI68fQWmMLAiAteIykr1/g65Qbu/G+lTDwaGg4e3oA1fK8llkA5J/leQ=="}]},"_npmVersion":"1.1.49","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.11":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"m8":">= 0.1.0","commander":">= 0.5.0","mkdirp":">= 0.3.0","n8iv":">= 0.1.0"},"devDependencies":{"mocha":">= 1.3.0","uglify-js":">= 1.2.5"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.11","readme":"<!-- [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8) -->\n\n#TODO:\n\n- documentation is not yet complete\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"Templ8@0.9.11","dist":{"shasum":"bf9eb78c2b943ea2d9b2eb852924d1d31815a460","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.11.tgz","integrity":"sha512-2JNyzC14LUblVWY/PZFSabIK6nccFNrb5LP+mgMOCBMjLbKvHhPMoE44dhugvFlH+pEYEDyMAjn83dRTV8nZKQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG65RWr/o+WzSwJ37hYXvugQwVouMZXqcS7hyV31jSErAiEAzl4m1qqc7fJUm7b761T/BtT2TvD+UxXY/x0RI0Ub8tU="}]},"_npmVersion":"1.1.59","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.12":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.2.7","mkdirp":">= 0.3.4","n8iv":">= 0.2.6"},"devDependencies":{"catn8":">= 0.0.2","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.12","readme":"<!-- [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8) -->\n\n#TODO:\n\n- documentation is not yet complete\n\n# Templ8\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"Templ8@0.9.12","dist":{"shasum":"0f9f05ec12ffe77bdc39dc233dca069562e5238c","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.12.tgz","integrity":"sha512-gAnFQLDkHYI81gb/vHntJA5+BV6d0KVaSGEAU7K8MgT8F6y9YA13jTBKCkLLt+M8+chhFDT7EzXFpc8lAIKPWg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDbyANhrJZwc6dDdslw/RqrhFX2nKskODJMCETQQRfWwAiB0XJiyYD8MFvCzGUhTMuI11g5pHMgan/RaGnVgkMMq7Q=="}]},"_npmVersion":"1.1.61","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.13":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.2.7","mkdirp":">= 0.3.4","n8iv":">= 0.2.6"},"devDependencies":{"catn8":">= 0.0.2","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.13","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"Templ8@0.9.13","dist":{"shasum":"ac81c33467bcb4f87a51f740fa49f6a0e70c59fa","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.13.tgz","integrity":"sha512-C56vXktLJjmABiej7LcJCO3B16TVVtiVaPgVIJzyHqRlM3U4AB4z8kvsJ2Owatmhavdg9FxHFUuGWsEjWSsq2A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIASPEbwWgb43uPOIeEkO7DNjaYVxqdhsgk5dV1IECinmAiANSP8yLnGmZzbdmtpWwPkVb/x6Y5ywBti7vLdn/x/7RQ=="}]},"_npmVersion":"1.1.61","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.14":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.2.7","mkdirp":">= 0.3.4","n8iv":">= 0.2.6"},"devDependencies":{"catn8":">= 0.0.2","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.14","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.9.14","dist":{"shasum":"ef1d47fac2f71b0bc1e8b4a00a0f0c243c6f1925","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.14.tgz","integrity":"sha512-jPaz5qcLdPofwmbV0QttjbczLTmVL5aLRyTYG90QOuv+wW5ju/QkpFePM0c4N1oSZcR1MZ11iRA4Zf4XHWT8RQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDE5LHxhCO+/wea8QkZVp5gX2TsCKwVlQ9qk3pjHHvbQQIhAORDe2vuE70T6QZjDXHGjNqoXTqjc4aO3MCbyULsEuey"}]},"_npmVersion":"1.1.63","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.15":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.2.7","mkdirp":">= 0.3.4","n8iv":">= 0.2.6"},"devDependencies":{"catn8":">= 0.0.2","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.15","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.9.15","dist":{"shasum":"698fa78c76686a127effa9436c274505046a43d7","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.15.tgz","integrity":"sha512-LKBq+qruMIrzG0htI0tpkbc4EY0l/AcGaH7YIha9xsFmxeN/dUZsuTdMnQYkWTh3XvCm7HwR970kGJu5AvDBiQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD5uTztlLY6faEYd+Y8hqKDPHJqGRMubTg/TmkfeKbdqwIgMuRqzs8d7X11nvjHymXh9+9zPR+d4no+rGUD9hxVaYE="}]},"_npmVersion":"1.1.65","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.16":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.1","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.2","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.16","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.7kb (gzipped)\n- Templ8.min.js ≅ 5.1kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.9.16","dist":{"shasum":"276b7752fcd5a76dc5222360c05db428730c2c3e","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.16.tgz","integrity":"sha512-NtXmr4nhrCIwadHl/VJbpFeQabz44axDVfaMfsTiST/O3XtJ/Y5Nq/t1YBUQo85/QeU+NhKfrwRA0i2NdD4Huw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCEV4Z70kQmmf4eOgCjF1tgaVf6g0yld/tuUZJEfEb4YAIhALQtgDPmr5fIrb7rnzgts/cCeiSd7xFn+KohvgOMts5Q"}]},"_npmVersion":"1.1.65","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.17":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.1","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.2","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.17","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.7kb (gzipped)\n- Templ8.min.js ≅ 5.1kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.9.17","dist":{"shasum":"e06b8e6fd70c2e852bd55b0dd6c7587fb4d7b4c4","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.17.tgz","integrity":"sha512-wbvYN2RUrJDs/Ni1DiB1u4SY6inYhbdjB1MG1OQM7Wk2s6/CvVAKFxuKsBGd0HJdSzN7YS37NpgBiRdPatrjnQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCh/OU/QggDtrr0DryF3egSZ44BumzPERPWCq69SAyzYAIhAOjKMS5Y+lj63jEQgllppdLQSdTkTGqG2UPb6bnpbr7E"}]},"_npmVersion":"1.1.65","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.18":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.1","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.2","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.18","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.7kb (gzipped)\n- Templ8.min.js ≅ 5.1kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.9.18","dist":{"shasum":"3f63d22c621aed2e70f7e1cda7de59bd06cc1923","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.18.tgz","integrity":"sha512-B3fBR4WNxpQqM+F1HaeAJSWHNK9MBT7xC40x/5UrCGAPkVS0CHxyGMJVpuRPdfWU8hoA5Fs4nPDXDMCc0DoN/Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDx3X63UObSo/kC6mqTU9EYAO5OoD0qggsSfbEnUPcUZAiEAmDcUqKtAjog3Ci3ljDJNC6uxNVmIxCNgz4mLRZ3dYC0="}]},"_npmVersion":"1.1.65","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.19":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.1","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.2","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.19","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.7kb (gzipped)\n- Templ8.min.js ≅ 5.1kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.9.19","dist":{"shasum":"a59331b99ab6d31f80bf810f95aa196a4d29e4aa","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.19.tgz","integrity":"sha512-OArrfNmLReq7tHm6mTa9dGN1YCPu6eiWVDFoy+pgxUm89wujXiFFS+lVsMNUgwXzaDSAa3/7DWFZJwfwuzjMAA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBWFDARmulmrkgrj8qfWNt3kUbuGoN+6sIQcCDkuVOBqAiEA/3tDbYobXYHJBRkrl5eMt3qJCFMa0GTr0uVr50iNKcE="}]},"_npmVersion":"1.1.65","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.20":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.4","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.4","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.20","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.7kb (gzipped)\n- Templ8.min.js ≅ 5.2kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.9.20","dist":{"shasum":"f3a8b17923b69e87e22c7dff845cab3310f7e456","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.20.tgz","integrity":"sha512-M8tB2DGkbIhyjFTndeubCzgWh1F5xblzP44pMYQ9YItWIXqz8Kg+h1CZssX+PPjpdmSV8D2DC2PVfeqCCmo7NQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGykwIVldTxlTyOdGqUtX2FL6V5iPaOLZD7eGEoLjL0EAiAnyGNgNnDyvTSCc7aqad7tAIHXngc2XSaxp/9QpHuaLQ=="}]},"_npmVersion":"1.1.66","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.21":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.4","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.4","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.21","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.8kb (gzipped)\n- Templ8.min.js ≅ 5.2kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.9.21","dist":{"shasum":"1f10b7510316f24a525f17788fa0de7ed59cba07","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.21.tgz","integrity":"sha512-124RLLs51zPu3OWu9ZguoL5XakEzQ2aKixkf0k6oM/P3OAuzO1r4V9ZE/1mz6AduO6AcP2lJQ+0LajB+d1AQRw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEa8MSEdJTXs7nEtQYMNUW5pxqKFKLVM5MlfxG4Isw+2AiA7PoyZbm//qv8Ua8wPjj8Ye8wy3DW7L4SaUduEvk2u+w=="}]},"_npmVersion":"1.1.69","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.22":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.8","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.4","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.22","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.8kb (gzipped)\n- Templ8.min.js ≅ 5.2kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.9.22","dist":{"shasum":"18a4aab2e4005e776e99d971dbd88e8259ead988","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.22.tgz","integrity":"sha512-zegaYSFSa+TKYhpHUF+R8aIJd2gdBjERLEMxFTPqRBb1yI/dnooqOdrpeUjLkxhzslv4htga7Ho9QT4wcKmldw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDCF1EeyqsfGqIGQbHG+vAJKfloUVBAdR1zERlHjzjA+QIhAOtQOLNjHcjMG9/QqtPa9H4hS9PoyLbiO4b+7gKu6Fiv"}]},"_npmVersion":"1.1.70","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.23":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.8","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.4","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.23","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}'\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}' \n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}', '<li>{{$_}}</li>', '{% endsub %}', \n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.8kb (gzipped)\n- Templ8.min.js ≅ 5.2kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.9.23","dist":{"shasum":"de758afd17c053ae6f835af09f1a5de8b3450181","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.23.tgz","integrity":"sha512-bBpXSz3T37zxhVYnfvhvfLiY1Y+WRTsmbrOa1QyMd9YwXUUTsOzCdNA+Qaudolte7OVyxcmNSIQJnStP1d9w6Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCID+Lkh/TRg+J1JFiHP1WPfWHcz5ELAkhJWiEBTTVW0L6AiEAhxs0rieSBLfRH3B0lEgXMe0Gb0VnfnDX3rPq+8qf56I="}]},"_npmVersion":"1.2.0","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.24":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.8","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.4","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.24","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif/ endunless Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %} // note: this tag can also be written as: {% /if %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %} // note: this tag can also be written as: {% /for %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}' // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}'  // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}',\n        \t'<li>{{$_}}</li>',\n        '{% endsub %}',  // note: this tag can also be written as: {% /sub %}\n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.8kb (gzipped)\n- Templ8.min.js ≅ 5.2kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.9.24","dist":{"shasum":"7f181e1149d2a8e87741fad4bc83aab85e37e8a9","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.24.tgz","integrity":"sha512-8W5JjZ6O8wU1yBfuEVePQKsFNIHkG5ZgvqqQ9E2frRjDf3J71pHUs+EVS0N3qWDbGP9clKjeeY4k+MNVrAA1ww==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDjabAgrGeFI0wqFJIWBQvn/6/FXrkJP+xkPvyvnUsgiwIhAK/x5NB2B6QwTv2qjxQg7i1M5/Hcz2a9uef+XrEFKWml"}]},"_from":".","_npmVersion":"1.2.12","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.25":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.8","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.4","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.25","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif/ endunless Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %} // note: this tag can also be written as: {% /if %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %} // note: this tag can also be written as: {% /for %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}' // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}'  // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}',\n        \t'<li>{{$_}}</li>',\n        '{% endsub %}',  // note: this tag can also be written as: {% /sub %}\n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.8kb (gzipped)\n- Templ8.min.js ≅ 5.2kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.9.25","dist":{"shasum":"2f2d7e08da3a4bee9be18cbd1d7e3b7398258f96","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.25.tgz","integrity":"sha512-JjltcfPs1ICqEHly3WCilVxIUP2noQvEZPajpy+XGR93jaWrRSVbYzvKx3vJR+E89gX1BwGgfEeD+GBcCLyarA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDqqQ6V/i9/XJSHug6pnqW5QckuaBBF/I1DXQav0niWAAiAm/yoxpX8oLB3SWsf3Tjg8qbqa8r3DybXLo9vJBYdrvQ=="}]},"_from":".","_npmVersion":"1.2.13","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.9.26":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.8","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.4","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.9.26","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif/ endunless Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %} // note: this tag can also be written as: {% /if %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %} // note: this tag can also be written as: {% /for %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}' // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}'  // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}',\n        \t'<li>{{$_}}</li>',\n        '{% endsub %}',  // note: this tag can also be written as: {% /sub %}\n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.8kb (gzipped)\n- Templ8.min.js ≅ 5.2kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.9.26","dist":{"shasum":"167f0b7034211dc8ca94b00270eab146a69d79d4","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.9.26.tgz","integrity":"sha512-WIBUKbgw2lLZTRQ6fRE/wggWshOqUytuHDOOdK0hAOYBjYqW38Akhfn9Ra3YFaBQtt5kw9EydHK/qBop8XC6rg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBumTtr23c1odOuPoz5YSnxdObAtIBzYjJ4bimoiHaVZAiEAn3GeO/e7S4uEtBFelQNiFZkAAx3RtrhlNESS3iLvXrU="}]},"_from":".","_npmVersion":"1.2.14","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.10.0":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.8","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.4","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.10.0","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif/ endunless Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %} // note: this tag can also be written as: {% /if %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %} // note: this tag can also be written as: {% /for %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}' // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}'  // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}',\n        \t'<li>{{$_}}</li>',\n        '{% endsub %}',  // note: this tag can also be written as: {% /sub %}\n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.8kb (gzipped)\n- Templ8.min.js ≅ 5.2kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.10.0","dist":{"shasum":"3c1a43193360550238d4ce87555dd4697369bf14","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.10.0.tgz","integrity":"sha512-J/NcKaCltB2vPKGcll7gTHg1oDnd7yPYuxbbeH164Gla/pvJ+XBEliOUN9T2TWoh0l2h8isIHxtAogjdjqssJw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAcIUg8B1d+DqvsnQAQSZrveP2821TLx4h5PCiqv9JLhAiEAqQzGs2GpHq6wIqdtFbEvaAurczs/7w+RUSt1xkYhAd4="}]},"_from":".","_npmVersion":"1.2.14","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"directories":{}},"0.10.1":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.8","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.4","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.10.1","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif/ endunless Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %} // note: this tag can also be written as: {% /if %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %} // note: this tag can also be written as: {% /for %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}' // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}'  // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}',\n        \t'<li>{{$_}}</li>',\n        '{% endsub %}',  // note: this tag can also be written as: {% /sub %}\n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.8kb (gzipped)\n- Templ8.min.js ≅ 5.2kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.10.1","dist":{"shasum":"50863265b40ad7c1121d2ce0edcd650a74b2268a","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.10.1.tgz","integrity":"sha512-LlJZXpse2NAwDhsAg/VZGPXhgJs8su3BYSwRZoAYWYD2tplS8iDVQbpByYX4g365CqZZo9V+De8VSAZ6ZUWawg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC20rcTgSe7YdPxl/9x9yYOWNfNapc6Qc7d7KZpNYL73AIgWXaGKj7iFrt7tbwRek8KDOxIMbm9f5++PQpVm+V1/fs="}]},"_from":"./","_npmVersion":"1.2.18","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}]},"0.10.2":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.8","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.4","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.10.2","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif/ endunless Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %} // note: this tag can also be written as: {% /if %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %} // note: this tag can also be written as: {% /for %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}' // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}'  // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}',\n        \t'<li>{{$_}}</li>',\n        '{% endsub %}',  // note: this tag can also be written as: {% /sub %}\n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.8kb (gzipped)\n- Templ8.min.js ≅ 5.2kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.10.2","dist":{"shasum":"12083c22cf0d09074ffc06b7d745145ca9a43ae6","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.10.2.tgz","integrity":"sha512-aQ6G4Nt4wkUkqQ6nO6jQ6HrEesOeMq9Loda4CUsW/yHoFE3Phyac+ZUgyKDH0N9AUkeZsoNo6gCsNq9CXBJSMg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC5nwt2UPpeHO9NLYP26elvZKbGa1gKkrXFMINRww5DaAIhALIDbhm6SmYlyM/WQ8gqFV0/gW8a+QVYIz1BRKZwKeH3"}]},"_from":"./","_npmVersion":"1.2.18","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}]},"0.10.3":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.8","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.4","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.10.3","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif/ endunless Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %} // note: this tag can also be written as: {% /if %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %} // note: this tag can also be written as: {% /for %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}' // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}'  // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}',\n        \t'<li>{{$_}}</li>',\n        '{% endsub %}',  // note: this tag can also be written as: {% /sub %}\n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.8kb (gzipped)\n- Templ8.min.js ≅ 5.2kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.10.3","dist":{"shasum":"0217bb1a4f4be1bcfd8c5e9bce056e5702c66107","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.10.3.tgz","integrity":"sha512-hiz8J0gO31iH0Jfv8+we821mY6lPAqBBrT4V0rxa8ASnsGmc0NxaiA73Gx9hxyjkcPb7hhOr3E7AOCTb7H/XDQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDfy20DfLjowdAaRW7ZPQTfoRyFC7hBovL53xg8OOBEpgIhANq2qkCEUcO2oftIxGiCurWxsWohiUdg9fyieO7SUKhO"}]},"_from":"./","_npmVersion":"1.2.18","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}]},"0.10.4":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.8","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.4","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.10.4","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif/ endunless Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %} // note: this tag can also be written as: {% /if %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %} // note: this tag can also be written as: {% /for %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}' // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}'  // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}',\n        \t'<li>{{$_}}</li>',\n        '{% endsub %}',  // note: this tag can also be written as: {% /sub %}\n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.8kb (gzipped)\n- Templ8.min.js ≅ 5.2kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.10.4","dist":{"shasum":"c104a6e1498a0f403a99ea7bb01b1e56673c70e4","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.10.4.tgz","integrity":"sha512-v8efOehtHsPOLz3YDZvLIw1VON0HCi5q5Q9gSd/TN1BBU4PHgAtmM1gMfu+7bqElalO6IzTEultsgPj+/Uoaww==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEucRNXrBGbMdBFNU7RWf9rPwJwo8BUwhwi+Ix1eVLW6AiAS4Jb8bF9A7wna6u7g0+O9H2VwnYXpP1F4uM/M3Bcb1g=="}]},"_from":"./","_npmVersion":"1.2.18","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}]},"0.10.5":{"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"bin":{"Templ8":"./bin/Templ8"},"description":"JavaScript Client/ Server Template Engine","dependencies":{"commander":">= 1.0.4","m8":">= 0.3.8","mkdirp":">= 0.3.4","n8iv":">= 0.2.8"},"devDependencies":{"catn8":">= 0.0.4","chai":">= 1.2.0","mocha":">= 1.4.2"},"keywords":["template","tpl","Templ8"],"licenses":[{"type":"MIT","url":"https://raw.github.com/constantology/Templ8/master/LICENSE"}],"main":"./Templ8","name":"Templ8","repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"scripts":{"test":"mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"},"version":"0.10.5","readme":"# Templ8.js [![build status](https://secure.travis-ci.org/constantology/Templ8.png)](http://travis-ci.org/constantology/Templ8)\n\nTempl8 as you can probably guess is a JavaScript template engine, with a Django'ish style of syntax.\n\nIt's fast, light weight and unlike a lot of other JavaScript template engines: **Templ8 does not use the JavaScript `with` statement**. This actually makes Templ8 parse templates faster than it would if it did use the `with` statement!\n\nTempl8 does not restrict you to generating HTML. All outputs are strings so if you want to generate HTML, CSS, JavaScript or whatever, the choice is yours...\n\n#TODO:\n\n- documentation is not yet complete\n\n## Dependencies\n\nTempl8.js only has one dependency [m8.js](/constantology/m8).\n\n**NOTE:**\nIf you are using Templ8 within a commonjs module, you don't need to require m8 before requiring Templ8 as this is done internally and a reference to **m8** is available as: `Templ8.m8`.\n\n```javascript\n\n   var Templ8 = require( 'Templ8' ),\n       m8     = Templ8.m8; // <= reference to m8\n\n// if running in a sandboxed environment remember to:\n   m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.\n\n```\n\nSee [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.\n\n## Support\n\nTested to work with nodejs, FF4+, Safari 5+, Chrome 7+, IE9+. Should technically work in any browser that supports [ecma 5]( http://kangax.github.com/es5-compat-table/) without throwing any JavaScript errors.\n\n## API\n\nIf all you want to do is swap out values you can use one of the following two smaller template functions.\n\n#### &lt;static&gt; Templ8.format( template`:String`, param1`:String`[, param2`:String`, ..., paramN`:String`] )`:String`\n\nThis function takes a minimum of two parameters. The first is the template you want perform substitutions over.\n\nThe template should use zero based tokens, e.g. `{0}`, `{1}` ... `{N}` that increment for each argument passed to the function.\n\ne.g.\n\n```javascript\n    Templ8.format( 'Hello {0}! Nice {1} we\\'re having.', 'world', 'day' );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\n---\n&nbsp;\n#### &lt;static&gt; Templ8.gsub( template`:String`, dict`:Object`[, pattern`:RegExp`] )`:String`\n\ngsub works similarly to format only it takes an Object with the values you want to substitute, instead of a sequence of parameters. Actually format calls gsub internally.\n\ne.g.\n\n```javascript\n    Templ8.gsub( 'Hello {name}! Nice {time} we\\'re having.', { name : 'world', time : 'day' } );\n```\n\nreturns: *Hello world! Nice day we're having.*\n\nThe default pattern for substitutions is `/\\{([^\\}]+)\\}/g`. However, you can supply a third argument to *gsub* which is your own custom pattern to use instead of the default.\n\nIf you want to do fancy stuff, you'll want to use the Templ8 constructor.\n\n---\n&nbsp;\n#### new Templ8( template`:String`, options`:Object` )\n\nThe Templ8 constructor actually takes an arbitrary number of String arguments which form the template body.\n\nThe last argument to the Templ8 can -- optionally -- be a configuration Object which defines any custom Filters you want to use for this Templ8 and any sub Templates it contains.\n\nIt also accepts the following four parameters (needless to say that these cannot be used as Filter names):\n\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>compiled</strong></td><td>If this is set to <code>true</code> then the Templ8 will be compiled straight away, otherwise it will wait until the first time you call it's <code>parse()</code> method to compile. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>debug</strong></td><td>Useful for debugging. Set this to <code>true</code> to have the Templ8 method body logged to the console. <strong>Default</strong> is <code>false</code>.</td>\n</tr><tr>\n\t<td><strong>fallback</strong></td><td>This is the String to use as a fallback value in case any values are not present when parsing a Templ8 instance. <strong>Default</strong> is <code>\"\"</code>, Empty String.</td>\n</tr><tr>\n\t<td><strong>id</strong></td><td>The ID of your Templ8. This is handy (and mandatory) if you want to use a Templ8 from within another Templ8. Otherwise an anonymous ID will be generated for your Templ8.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n### Templ8 instance methods\n\nTo keep it simple, a Templ8 instance only contains one method.\n\n#### parse( dictionary`:Object` )`:String`\n\nThis method accepts one parameter: an Object of values you want to substitute and returns a String of the parsed Templ8.\n\nAny tokens in the Templ8 that do not have a dictionary value will use the `fallback` value described above,\n\n---\n&nbsp;\n\n### Templ8 variables\n\n#### basic global variables\n\n##### $_\n\nThis is based on perl's `$_` and is a reference to the the current dictionary value being parsed.\n\nFor instance if you are in a loop, rather than access the value using `iter.current` you could also access it via `$_`.\n\ne.g. instead of this:\n\n```javascript\n    {[ iter.current|parse:'sub_template' for each ( items ) ]}\n```\n\nor this:\n\n```javascript\n    {[ item|parse:'sub_template' for each ( item in items ) ]}\n```\n\nyou could do this:\n\n```javascript\n    {[ $_|parse:'sub_template' for each ( items ) ]}\n```\n\n##### iter\n\nThis is the current iterator being parsed. It is an instance of an internal class called **Iter**. Iter instances are created internally, when you use a `{% for %}` loop or an Array Comprehension `{[ for each ]}` tag you should not need to create one yourself.\n\nIt has the following properties available for both **Arrays** and **Objects**:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>count</strong></td><td>the total number of all items in the Array or Object</td>\n</tr><tr>\n\t<td><strong>current</strong></td><td>The current item being iterated over.</td>\n</tr><tr>\n\t<td><strong>empty</strong></td><td>Whether or not the item to iterate over is empty – has no items. Note: if the item is not iterable, this will never be true.</td>\n</tr><tr>\n\t<td><strong>first</strong></td><td>The first item in the Array/ Object. Note: you cannot guarantee iteration order in an Object.</td>\n</tr><tr>\n\t<td><strong>firstKey</strong></td><td>The first key in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>index</strong></td><td>The zero based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>index1</strong></td><td>The one based index of the current iteration.</td>\n</tr><tr>\n\t<td><strong>key</strong></td><td>The key of the current item being iterated over in the Array/ Object. For Arrays this will be the same as <code>index</code>.</td>\n  </tr><tr>\n\t<td><strong>last</strong></td><td>The last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastIndex</strong></td><td>The zero based index of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>lastKey</strong></td><td>The key of the last item in the Array/ Object.</td>\n</tr><tr>\n\t<td><strong>next</strong></td><td>The next item in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>nextKey</strong></td><td>The next key in the iteration, or undefined if we're at the last item.</td>\n</tr><tr>\n\t<td><strong>parent</strong></td><td>If you are in a nested loop and want to call the parent iter, you can access it via this property.</td>\n</tr><tr>\n\t<td><strong>prev</strong></td><td>The previous item in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>prevKey</strong></td><td>The previous key in the iteration, or undefined if we're at the first item.</td>\n</tr><tr>\n\t<td><strong>stopped</strong></td><td>Whether or not the iteration has been stopped..</td>\n</tr><tr>\n\t<td><strong>val</strong></td><td>The same as <code>current</code>.</td>\n</tr>\n</table>\n\nIt also has the following two methods:\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>hasNext</strong></td><td>returns <code>false</code> if there is no value after the current iteration to iterate over. Otherwise it will return the <code>Iter</code> instance (this).</td>\n</tr><tr>\n\t<td><strong>stop</strong></td><td>will stop the <code>Iter</code> instance from iterating after the current iteration has completed.</td>\n</tr>\n</table>\n\n---\n&nbsp;\n\n#### Templ8 internal variables\n\nAlong with the above Templ8 has some internal variables accessible for the more advanced user, should they require access to them.\n\n##### $C:ContextStack\n\nTempl8 **does not use the JavaScript `with` statement**. It implements its own version of a `with` statement using an internal class called **ContextStack**.\n\nIt has five methods (**you should NOT** call these if you DO NOT know what you're doing):\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n\t<td><strong>current</strong></td><td>returns the current context Object</td>\n</tr><tr>\n\t<td><strong>get</strong></td><td>attempts to return the value of a dictionary Object, if it is in the ContextStack, otherwise it will return the fallback value or undefined.</td>\n</tr><tr>\n\t<td><strong>pop</strong></td><td>removes the most recently added dictionary Object from the ContextStack.</td>\n</tr><tr>\n \t<td><strong>push</strong></td><td>adds a dictionary Object to the ContextStack.</td>\n</tr>\n</table>\n\n##### \\_\\_OUTPUT\\_\\_:String\n\nThis is where all parsed template output is stored.\n\n##### \\_\\_ASSERT\\_\\_:Function{}\n\nThis is a reference to Templ8.Assertions.\n\n##### \\_\\_FILTER\\_\\_:Function{}\n\nThis is a reference to Templ8.Filters.\n\n##### \\_\\_UTIL\\_\\_:Function{}\n\nThis is a reference to the internal utility functions used by Templ8.\n\n---\n&nbsp;\n\n### Tags & Statements\n\n#### **Tag: {{}}** - Interpolation\n\nThis tag is used for interpolating dictionary values with their respective template tokens. At it simplest a tag which will be replaced by a dictionary value `foo` would look something like this:\n\n```javascript\n    var tpl = new Templ8( '{{foo}}' );\n    tpl.parse( { foo : 'bar' } ); // returns: bar\n```\n\n##### Accessing nested values\n\nIf your dictionary contains nested objects you can easily access nested values like you would in regular JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.value}}' );\n    tpl.parse( { some : { nested : { value : 'foo' } } } ); // returns: foo\n```\n\nYou can also similarly access values from Array's in the same way:\n\n```javascript\n    var tpl = new Templ8( '{{some.nested.1.value}}' );\n    tpl.parse( { some : { nested : [{ value : 'lorem' },{ value : 'ipsum' },{ value : 'dolor' }] } } ); // returns: ispum\n```\n\n##### Filtering\n\nThis is all well and good, but at some point we will want to manipulate the values in our dictionary Objects in some way or another.\n\nTempl8 provides a very simple and powerful method for doing so based on Django's pipe syntax for filtering values.\n\nIt is probably most easily illustrated with an example showing the pipe syntax converted to JavaScript. So:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph}}\n```\n\nWould translate to something like this:\n\n```javascript\n\tvalue = truncate( value, 30 );\n\tvalue = bold( value );\n\tvalue = wrap( value, '(', ')' );\n\tvalue = paragraph( value );\n\t\n\t// or \n\t\n\tparagraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) );\n```\n\nThe most important thing to note is that the first value passed to the filter is always the value being parsed by the template, the arguments passed to each filter will always come after the value being parsed.\n\n##### One line statements\n\nAs well as standard template conditionals, Templ8 introduces one line statements, because, hey it's JavaScript and we like to keep things concise. \n\nIf you only want to parse a value if a certain condition is met, rather than writing block if tags around it, you can include it in your interpolation tag like so:\n\n```javascript\n    {{value if value|exists}}\n```\n\nWhich translates to something like this:\n\n```javascript\n    if ( exists( value ) ) { __OUTPUT__ += value; }\n```\n\nNotice how you can use the same pipe syntax for conditionals. Templ8's internals work out whether your method is an assertion or a filter and reference the appropriate method.\n\nYou can also use ordinary JavaScript conditions if you want to, as well as an **unless** statement; and filtering is still ok too. \n\nA more complex example would be:\n\n```javascript\n    {{value|truncate:30|bold|wrap:\"(\", \")\"|paragraph unless value == null}}\n```\n\nTranslating to something like:\n\n```javascript\n    if ( !( value == null ) ) { \n       paragraph( wrap( bold( truncate( value, 30 ) ), '(', ')' ) ); \n    }\n```\n\n#### **Tag: {%%}** - Evaluation\n\nThis tag is used in conjunction with the above tag to give you access to more powerful conditional statements, iteration and sub templates.\n\n##### if/ unless/ elseif/ else/ endif/ endunless Statements\n\nJust like regular JavaScript Templ8 features conditional statements. It also introduces the `unless` statement based off Perl.\n\nEvery open `if`/ `unless` statement must end with an `endif` statement -- with any number of`elseif`s in between; an optional `else` is also allowed just before `endif`.\n\nThe reason for the `endif` statement is that Templ8 does not use braces to encapsulate block statements, so it requires a flag to let the parser know when to close a block.\n\n**Note: `elseif` should be written as one word, no spaces. It can also be written as `elsif`, again, based off Perl.**\n\nAn example would be:\n\n```javascript\n    {% if value == 'foo' %}\n        <h1>{{value|bold}}</h1>\n    {% elseif value == 'bar' %}\n        <h2>{{value|italics}}</h2>\n    {% else %}\n        {{value}}\n    {% endif %} // note: this tag can also be written as: {% /if %}\n```\n\nTranslating to:\n\n```javascript\n    if ( value == 'foo' ) { \n        '<h1>' + bold( value ) + '</h1>';\n    }\n    else if ( value == 'bar' ) {\n        '<h2>' + italics( value ) + '</h2>';\n    }\n    else { value; }\n````\n\n##### for/ forempty/ endfor Statements\nThe `for` statement allows you to iterate over Arrays as well as Objects. There are a number of options available with the `for` statement.\n\nJust like the `if` statement the `for` statement must end with an `endfor` statement to tell the parser that the statement block is ending.\n\nYou can also include a `forempty` statement which will be used in the case where an Array/ Object is either empty or the item you are trying to iterate over is not iterable, e.g. a Number or Date. `forempty` is not mandatory.\n\nThe `iter` variable mentioned above is the standard way to access any and all properties you require while iterating over an Array/ Object.\n\nYou can also use `$_` to access the current value being iterated over.\n\nHowever you can also assign your own variable names to the `for`. e.g.\n\n```javascript\n    {% for item in items %}\n        {{item}}\n    {% forempty %}\n        No items\n    {% endfor %} // note: this tag can also be written as: {% /for %}\n```\n\nWill assign the current value being iterated over to the variable `item`, which is accessible as demonstrated.\n\n```javascript\n    {% for [key, value] in items %}\n        {{key}}. {{value}}\n    {% endfor %}\n```\n\nWill assign the current value being iterated over to the variable `value`. If you are iterating over an Array then the variable `key` will be the zero based index of the the current item being iterated over. If you are iterating over an Object then the variable `key` will be the the key name of the current item being iterted over.\n\nIf you want to limit the number of items you are iterating over you can do so by using brackets to specify the range of items to iterate over.\n\n```javascript\n    {% for item in items [..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 0 to 10, so the first 11 items in the Array/ Object.\n\n```javascript\n    {% for item in items [5..10] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over items 5 to 10.\n\n```javascript\n    {% for item in items [5..] %}\n        {{item}}\n    {% endfor %}\n```\n\nWill iterate over all items starting from the 6th item in the Array/ Object.\n\nIf you are nesting `for` statements you can access the parent `iter` Object by using the syntax `iter.parent` this will maintain state no matter how deep you nest.\n\n##### sub/ endsub templates\nTODO\n\n#### **Tag: {[]}** - Array Comprehensions\nTODO\n\n#### **Tag: {::}** - Executing Arbitrary JavaScript\nTODO\n\n#### **Tag: {##}** - Comments\nTODO\n\n#### Adding your own Tags and/ or Statements\nTODO\n\n---\n&nbsp;\n## Examples (by tag)\n\n### **Tag: {{}}**\n\n#### Replacing values\n\n```javascript\n    var tpl = new Templ8( '{{value}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n```\n\n##### Filtering values\n\n```javascript\n    var tpl = new Templ8( '{{value|truncate:30|bold|link:\"http://github.com\"}}' );\n\n    tpl.parse( { value : 'github.com is great for sharing your code with other people.' } ); \n```\n\nreturns the String:\n\n```html\n\t<a href=\"http://github.com\"><strong>github.com is great for sharin...</strong></a>\n```\n\n##### One line *if* statement\n\n```javascript\n    var tpl = new Templ8( '{{value if value|notEmpty}}' );\n    \n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( {} );                       // returns: empty String ( \"\" )\n```\n\n##### One line *unless* statement\n\n```javascript\n   var tpl = new Templ8( '{{value unless value|equals:\"foo\"}}' );\n\n    tpl.parse( { value : 'github.com' } ); // returns: *github.com*\n\n    tpl.parse( { value : 'foo' } );        // returns: empty String ( \"\" )\n```\n\n---\n&nbsp;\n\n### Tag **{%%}**\n\n#### conditions: *if|unless/ elseif/ else/ endif*\n\n```javascript\n    var tpl = new Templ8(\n        '{% if value == \"foo\" || value == \"bar\" %}',\n            '{{value}}',\n        '{% elseif value != \"lorem ipsum\" %}',\n            '{{value|bold}}',\n        '{% elseif value|notEmpty %}',\n            '{{value|italics}}',\n        '{% else %}',\n            'No value',\n        '{% endif %}' // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { value : 'foo' } );            // returns: foo\n\n    tpl.parse( { value : 'lorem ipsum' } );    // returns: <strong>lorem ipsum</strong>\n\n    tpl.parse( { value : 'dolor sit amet' } ); // returns: <em>dolor sit amet</em>\n\n    tpl.parse( {} );                           // returns: No Value\n```\n\n#### iterating: *for/ forempty/ endfor*\n\n```javascript\n    var tpl = new Templ8(\n\t    '{% for item in items %}',\n            '<p>{{item}}</p>',\n        '{% forempty %}',\n            '<p><strong>No items</strong></p>',\n        '{% endfor %}'  // note: this tag can also be written as: {% /if %}\n    );\n\n    tpl.parse( { items : ['one', 'two', 'three'] } );               // returns: <p>one</p><p>two</p><p>three</p>\n\n    tpl.parse( { items : { \"one\" : 1, \"two\" : 2, \"three\" : 3 } } ); // returns: <p>1</p><p>2</p><p>3</p>\n\n    tpl.parse( {} );                                                // returns: <p><strong>No items</strong></p>\n    \n    tpl.parse( { items : foo } );                                   // returns: <p><strong>No items</strong></p>\n```\n\n#### *sub/ endsub* templates\n\n```javascript\n    var tpl = new Templ8(\n        '{% sub list_item %}',\n        \t'<li>{{$_}}</li>',\n        '{% endsub %}',  // note: this tag can also be written as: {% /sub %}\n        '<ul>{[ item|parse:\"list_item\" for each ( item in items ) ]}</ul>'\n    );\n\n\ttpl.parse( { items : ['one', 'two', 'three'] } );\n```\n\nreturns the String:\n\n```html\n\t<ul><li>one</li><li>two</li><li>three</li></ul>\n```\n\n---\n&nbsp;\n\n### Tag **{[]}** (Array comprehensions or one line for loops)\n\n```javascript\n    var tpl_foo = new Templ8( { id : 'foo' }, '<em>{{val}}</em>' ), \n        tpl_bar = new Templ8( { id : 'bar' }, '<strong>{{val}}</strong>' ), \n        tpl     = new Templ8( '{[ v|parse:k|paragraph for each ( [k,v] in items ) if ( k|isTPL ) ]}' );\n\n    tpl.parse( {\n        foo  : { val : 'foo' }, \t\n        bar  : { val : 'bar' }, \n        greg : { val : 'not gonna happen' }\n    } );\n```\n\nreturns the String:\n\n```html\n\t<p><em>foo</em></p><p><strong>bar</strong></p>\n```\n\nas **greg** does not exist as a template (poor greg), the value is not rendered...\n\n---\n&nbsp;\n\n### Tag **{::}**\nAllows you to execute arbitrary JavaScript.\n\n```javascript\n    var tpl = new Templ8( '{: aribtrarily.executing.nasty.code.isFun(); :}' );\n```\n\n---\n&nbsp;\n\n### Tag **{##}**\nAllows you to add comments in your template.\n\n```javascript\n    var tpl = new Templ8( '{# doing something complex and describing it is sensible, but not probable #}' );\n```\n\n## File size\n\n- Templ8.js ≅ 7.8kb (gzipped)\n- Templ8.min.js ≅ 5.2kb (minzipped)\n\n## License\n\n(The MIT License)\n\nCopyright &copy; 2011 christos \"constantology\" constandinou http://muigui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","_id":"Templ8@0.10.5","dist":{"shasum":"e5875878ab44900e3099080156098d03f0e54013","tarball":"https://registry.npmjs.org/Templ8/-/Templ8-0.10.5.tgz","integrity":"sha512-YyI/B4M1ytJ8CKaS85hLgOF2ijUyhePycdR7iZypra9lxnRMcvlGhzomlscd268uc44uOKRmFV7uy29CzlmHdQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAdPTYESqq/YEpKsmTYqE6RZibg63MUdIG6k+1R/kOfkAiA+lJPE6aIBSSswHDRVXm2+0K1aaUL/WIuqm0qtVIw6Kg=="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"constantology","email":"constantology@gmail.com"},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}]}},"maintainers":[{"name":"constantology","email":"constantology@gmail.com"}],"time":{"modified":"2022-06-13T02:16:19.526Z","created":"2011-07-14T09:52:30.396Z","0.1.7":"2011-07-14T09:52:30.957Z","0.1.8":"2011-08-01T08:13:07.116Z","0.1.9":"2011-08-28T12:36:03.137Z","0.2.0":"2011-08-29T11:01:39.969Z","0.2.1":"2011-09-04T07:44:28.406Z","0.3.0":"2011-10-25T12:04:43.386Z","0.5.0":"2012-02-25T01:07:04.777Z","0.6.0":"2012-02-25T23:25:13.246Z","0.7.0":"2012-02-27T16:54:17.267Z","0.7.1":"2012-02-27T16:55:58.768Z","0.7.2":"2012-03-21T17:03:33.289Z","0.8.0":"2012-03-23T19:22:44.494Z","0.9.0":"2012-03-30T22:18:38.125Z","0.9.1":"2012-04-01T00:00:54.355Z","0.9.2":"2012-04-05T20:49:37.323Z","0.9.3":"2012-04-24T19:21:47.754Z","0.9.4":"2012-05-06T22:09:19.095Z","0.9.5":"2012-05-07T15:59:47.554Z","0.9.6":"2012-06-30T18:12:27.454Z","0.9.7":"2012-08-19T11:29:06.467Z","0.9.8":"2012-08-19T21:26:22.283Z","0.9.9":"2012-08-21T08:34:59.019Z","0.9.11":"2012-09-08T16:56:11.891Z","0.9.12":"2012-09-14T12:40:37.527Z","0.9.13":"2012-09-25T09:33:47.540Z","0.9.14":"2012-10-23T10:54:52.943Z","0.9.15":"2012-10-31T16:00:06.717Z","0.9.16":"2012-11-01T15:29:06.240Z","0.9.17":"2012-11-06T11:44:35.786Z","0.9.18":"2012-11-10T13:36:24.927Z","0.9.19":"2012-11-14T08:57:01.487Z","0.9.20":"2012-11-23T22:55:11.281Z","0.9.21":"2012-12-13T16:13:57.116Z","0.9.22":"2013-01-09T14:44:37.515Z","0.9.23":"2013-01-10T10:34:53.079Z","0.9.24":"2013-02-21T09:59:24.897Z","0.9.25":"2013-03-07T12:00:23.363Z","0.9.26":"2013-03-13T16:40:48.325Z","0.10.0":"2013-03-25T14:31:27.232Z","0.10.1":"2013-04-16T10:10:07.229Z","0.10.2":"2013-04-16T10:13:22.638Z","0.10.3":"2013-04-16T10:32:24.331Z","0.10.4":"2013-04-16T12:48:39.740Z","0.10.5":"2013-05-09T08:05:05.018Z"},"author":{"name":"constantology","email":"christos@muigui.com","url":"http://muigui.com"},"repository":{"type":"git","url":"git@github.com:constantology/Templ8.git"},"users":{"mrstlee":true}}