Skip to content

Instantly share code, notes, and snippets.

@joshbuddy
Created January 19, 2010 08:48
Show Gist options
  • Save joshbuddy/280782 to your computer and use it in GitHub Desktop.
Save joshbuddy/280782 to your computer and use it in GitHub Desktop.
crapbook-pro:emjay joshua$ node examples/nodejs/test.js
--------------------------------- RENDERED
Doing simple output
simple output
Outputting a variable passed into the template.
test title
Doing output with mixed in method, tag.
<test attr="value">
Including a partial via async inclusion.
this is from another file...:
i love the world a lot
<br>
Appending to the buffer directly.
&lt;testing&gt;
Appending to the buffer directly without escaping.
<testing>
Appending even more directly.
you are in my buffer
How many characters in the buffer?
456
Loopin'!
This is i .. 0<br>
This is i .. 1<br>
This is i .. 2<br>
This is i .. 3<br>
This is i .. 4<br>
This is i .. 5<br>
This is i .. 6<br>
This is i .. 7<br>
This is i .. 8<br>
This is i .. 9<br>
require('../../lib/emjay/node');
var sys = require('sys')
HTMLHelper = {
tag: function(name, attrs) {
var buf = "<"+name;
for(var key in attrs) {
buf += ' ' + this.htmlEscape(key) + '="'+this.htmlEscape(attrs[key]) + '"'
}
return (buf + '>').makeSafe();
}
}
new Emjay.NodeJs([HTMLHelper, Emjay.NodeJs.Helpers]).load('./examples/nodejs/test.mjs').run({title: 'test title'}, function(rendered) {
sys.puts('--------------------------------- RENDERED');
sys.puts(rendered);
});
Doing simple output
[='simple output'-]
Outputting a variable passed into the template.
[=title-]
Doing output with mixed in method, tag.
[=this.tag('test', {attr:'value'})-]
Including a partial via async inclusion.
[== this.partial('./examples/nodejs/test2.mjs', {output: 'i love the world a lot'})-]
Appending to the buffer directly.
[- this.append('<testing>') -]
Appending to the buffer directly without escaping.
[- this.append('<testing>'.makeSafe()) -]
Appending even more directly.
[- this.__buffer += 'you are in my buffer' -]
How many characters in the buffer?
[=this.__buffer.length-]
Loopin'!
[- for(var i =0; i != 10; i++) { -]
This is i .. [=i-]<br>
[- } -]
this is from another file...:
[=output-]
[=this.tag('br')-]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment