Permalink
Browse files

Added examples with custom delimiters

  • Loading branch information...
1 parent e7dd0fa commit 19c2a0bac563db05169e84deb9a13722d9ffce5a @olado committed Feb 8, 2011
Showing with 35 additions and 0 deletions.
  1. +17 −0 examples/customdoT.js
  2. +18 −0 examples/customdoU.js
View
@@ -0,0 +1,17 @@
+(function() {
+ var doT = require('../doT.js'),
+ data = { f1: 1, f2: 2, f3: 3},
+ snippet = '<h1>Just static text</h1> <p>Here is a simple case <?=it.f1+it.f3?> </p> <div class="<?=it.f1?>"> Next we will use a JavaScript block: </div> <? for(var i=0; i < it.f2; i++) { ?> <div><?=it.f3?></div> <? }; ?>';
+
+ doT.templateSettings = {
+ begin : '<?',
+ end : '?>',
+ varname : 'it'
+ };
+
+
+ var doTCompiled = doT.template(snippet);
+
+ console.log("Generated function: \n" + doTCompiled.toString());
+ console.log("Result of calling with " + JSON.stringify(data) + " :\n" + doTCompiled(data));
+}());
View
@@ -0,0 +1,18 @@
+(function() {
+ var doU = require('../doU.js'),
+ data = { f1: 1, f2: 2, f3: 3},
+ snippet = '<h1>Just static text</h1> <p>Here is a simple case <?=it.f1+it.f3?> </p> <div class="<?=it.f1?>"> Next we will use a JavaScript block: </div> <? for(var i=0; i < it.f2; i++) { ?> <div><?=it.f3?></div> <? }; ?>';
+
+ doU.templateSettings = {
+ evaluate : /\<\?([\s\S]+?)\?\>/g,
+ interpolate : /\<\?=([\s\S]+?)\?\>/g,
+ varname : 'it'
+ };
+
+
+
+ var doUCompiled = doU.template(snippet);
+
+ console.log("Generated function: \n" + doUCompiled.toString());
+ console.log("Result of calling with " + JSON.stringify(data) + " :\n" + doUCompiled(data));
+}());

0 comments on commit 19c2a0b

Please sign in to comment.