Updated compiled output

This commit is contained in:
Patrick Steele-Idem 2014-05-05 14:48:13 -06:00
parent 3da3d36335
commit f1ce8a4e95

View File

@ -254,8 +254,7 @@ setTimeout(function() {
}, 1000); }, 1000);
// Render the template to the existing render context: // Render the template to the existing render context:
template template.render({
.render({
name: 'World' name: 'World'
}, },
context); context);
@ -372,46 +371,46 @@ require('raptor-templates/compiler').compileFile(path, function(err, src) {
### Sample Compiled Template ### Sample Compiled Template
```javascript ```javascript
module.exports = function create(helpers) { module.exports = function create(__helpers) {
var empty = helpers.e, var empty = __helpers.e,
notEmpty = helpers.ne, notEmpty = __helpers.ne,
escapeXml = helpers.x, escapeXml = __helpers.x,
forEach = helpers.f, forEach = __helpers.f,
escapeXmlAttr = helpers.xa; escapeXmlAttr = __helpers.xa;
return function render(data, context) { return function render(data, context) {
context.w('Hello ') context.w(('Hello ') +
.w(escapeXml(data.name)) (escapeXml(data.name)) +
.w('! '); ('! '));
if (notEmpty(colors)) { if (notEmpty(data.colors)) {
context.w('<ul>'); context.w(('<ul>'));
forEach(data.colors, function(color) { forEach(data.colors, function(color) {
context.w('<li style="color: ') context.w(('<li style="color: ') +
.w(escapeXmlAttr(color)) (escapeXmlAttr(color)) +
.w('">') ('">') +
.w(escapeXml(color)) (escapeXml(color)) +
.w('</li>'); ('</li>'));
}); });
context.w('</ul>'); context.w(('</ul>'));
} }
else { else {
context.w('<div>No colors!</div>'); context.w(('<div>No colors!</div>'));
} }
}; };
} }
``` ```
The compiled output is designed to be extremely minifiable. The minified code is shown below: The compiled output is designed to be both extremely readable and minifiable. The minified code is shown below:
```javascript ```javascript
module.exports=function(a){var d=a.ne,c=a.x,e=a.f,f=a.xa;return function(a,b){b.w("Hello ").w(c(a.name)).w("! ");d(colors)?(b.w("<ul>"),e(a.colors,function(a){b.w('<li style="color: ').w(f(a)).w('">').w(c(a)).w("</li>")}),b.w("</ul>")):b.w("<div>No colors!</div>")}}; module.exports=function(a){var d=a.ne,c=a.x,e=a.f,f=a.xa;return function(a,b){b.w("Hello "+c(a.name)+"! ");d(a.colors)?(b.w("<ul>"),e(a.colors,function(a){b.w('<li style="color: '+f(a)+'">'+c(a)+"</li>")}),b.w("</ul>")):b.w("<div>No colors!</div>")}};
``` ```
_File size: 193 bytes gzipped (267 bytes uncompressed)_ _File size: 190 bytes gzipped (251 bytes uncompressed)_
# Language Guide # Language Guide