Browse files

Add Jade support. Include runtime code into the output script.

  • Loading branch information...
1 parent 94ee528 commit 0471e5f793149ea2101d7e192ea4f3917223e2a6 @Staltec committed Nov 10, 2012
View
13 README.md
@@ -7,11 +7,13 @@ TemplateReady is multi-templating on the fly pre-compiler.
* Most common template libraries support.
* If rewrite template in another templating library - don't need to change client-side application code.
* Create common, minified and gzipped versions (useful with gzip_static Nginx module).
+* include template library runtime code (if exists) into the output script file.
## Supported template libraries
* [Underscore](http://underscorejs.org/#template) template - builds client-side independent methods. Not even need Underscore.js!
-* [Mustache](http://mustache.github.com/) - client-side [hogan.js](https://github.com/twitter/hogan.js) ([template-2.0.0.js](https://github.com/twitter/hogan.js/blob/master/web/builds/2.0.0/template-2.0.0.js)) required.
+* [Mustache](http://mustache.github.com/) - client-side [runtime](https://github.com/twitter/hogan.js/blob/master/web/builds/2.0.0/template-2.0.0.js) code required.
+* [Jade](https://github.com/visionmedia/jade) - client-side [runtime](https://github.com/visionmedia/jade/blob/master/runtime.js) code required.
## Simple Install
@@ -57,8 +59,12 @@ Get this code, install npm, and then do this:
You must ensure that the object already declared in your JS application.
Default is 'Core.Template'
+ -r| --runtime
+ Add template library runtime code (if exists) into the output script file.
+ No default
+
-w|--watch
- When a change template file occurs, rebuild output js files.
+ When a change template file occurs, rebuild output js file.
No default
-p|--poll-interval <milliseconds>
@@ -75,8 +81,9 @@ Get this code, install npm, and then do this:
Show version and exit.
Examples:
+ templateready -d ./wwwroot/app --runtime
templateready -d ./wwwroot/app -s mytemplates -w -p 1000
- templateready --source ./wwwroot/mytemplates --file ./wwwroot/app/comiled.js --target 'Application.Templates'
+ templateready --source ./wwwroot/mytemplates --file ./wwwroot/app/comiled.js --target 'MyApplicationTemplates'
## Issues
View
0 wwwroot/app/hogan/template-2.0.0.min.js → compilers/hogan.template-2.0.0.min.js
File renamed without changes.
View
45 compilers/jade.js
@@ -0,0 +1,45 @@
+/**
+ * User: Staltec
+ * Date: 10.11.12
+ * Time: 3:45
+ */
+
+var util = require("util")
+ , fs = require("fs")
+ , jade = require('jade')
+ ;
+
+
+module.exports = {};
+
+module.exports.type = 'jade';
+
+module.exports.filePattern = /^.*\.(jade)$/;
+
+module.exports.runtime = fs.readFileSync(__dirname+'/jade.runtime.min.js', 'utf8');
+
+module.exports.compiler = function(options, callback){
+
+ fs.readFile(options.file, 'utf8', function(err, fileContent){
+ var code, cErr;
+
+ if(err){
+ callback(err, '');
+ }else{
+ try{
+ code = jade.compile(fileContent, {
+ filename : options.file,
+ client : true,
+ self: true,
+ compileDebug : false
+ }).toString();
+ if(code) code = code.toString().replace('function anonymous', 'function');
+ }catch(e){
+ cErr = e;
+ }
+ callback(cErr, code);
+ }
+
+ });
+};
+
View
1 compilers/jade.runtime.min.js
@@ -0,0 +1 @@
+jade=function(exports){Array.isArray||(Array.isArray=function(arr){return"[object Array]"==Object.prototype.toString.call(arr)}),Object.keys||(Object.keys=function(obj){var arr=[];for(var key in obj)obj.hasOwnProperty(key)&&arr.push(key);return arr}),exports.merge=function merge(a,b){var ac=a["class"],bc=b["class"];if(ac||bc)ac=ac||[],bc=bc||[],Array.isArray(ac)||(ac=[ac]),Array.isArray(bc)||(bc=[bc]),ac=ac.filter(nulls),bc=bc.filter(nulls),a["class"]=ac.concat(bc).join(" ");for(var key in b)key!="class"&&(a[key]=b[key]);return a};function nulls(val){return val!=null}return exports.attrs=function attrs(obj,escaped){var buf=[],terse=obj.terse;delete obj.terse;var keys=Object.keys(obj),len=keys.length;if(len){buf.push("");for(var i=0;i<len;++i){var key=keys[i],val=obj[key];"boolean"==typeof val||null==val?val&&(terse?buf.push(key):buf.push(key+'="'+key+'"')):0==key.indexOf("data")&&"string"!=typeof val?buf.push(key+"='"+JSON.stringify(val)+"'"):"class"==key&&Array.isArray(val)?buf.push(key+'="'+exports.escape(val.join(" "))+'"'):escaped&&escaped[key]?buf.push(key+'="'+exports.escape(val)+'"'):buf.push(key+'="'+val+'"')}}return buf.join(" ")},exports.escape=function escape(html){return String(html).replace(/&(?!(\w+|\#\d+);)/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},exports.rethrow=function rethrow(err,filename,lineno){if(!filename)throw err;var context=3,str=require("fs").readFileSync(filename,"utf8"),lines=str.split("\n"),start=Math.max(lineno-context,0),end=Math.min(lines.length,lineno+context),context=lines.slice(start,end).map(function(line,i){var curr=i+start+1;return(curr==lineno?" > ":" ")+curr+"| "+line}).join("\n");throw err.path=filename,err.message=(filename||"Jade")+":"+lineno+"\n"+context+"\n\n"+err.message,err},exports}({});
View
11 compilers/mustache.js
@@ -4,16 +4,19 @@
* Time: 14:52
*/
-var util = require("util");
-var fs = require("fs");
-var hogan = require("hogan.js");
+var util = require("util")
+ , fs = require("fs")
+ , hogan = require("hogan.js")
+ ;
module.exports = {};
-module.exports.name = 'Mustache compiler';
+module.exports.type = 'mustache';
module.exports.filePattern = /^.*\.(mustache)$/;
+module.exports.runtime = fs.readFileSync(__dirname+'/hogan.template-2.0.0.min.js', 'utf8')+';';
+
module.exports.compiler = function(options, callback){
fs.readFile(options.file, 'utf8', function(err, fileContent){
View
2 compilers/underscore-template.js
@@ -10,7 +10,7 @@ var _ = require('underscore');
module.exports = {};
-module.exports.name = 'Underscore-template compiler';
+module.exports.type = 'underscore';
module.exports.filePattern = /^.*\.(html?)$/;
View
9 index.js
@@ -1,9 +1,9 @@
#!/usr/bin/env node
-var path = require("path"),
- args = process.argv.slice(1),
- templateready = require("./templateready")
- ;
+var path = require("path")
+ , args = process.argv.slice(1)
+ , templateready = require("./templateready")
+ ;
var arg, base;
do arg = args.shift();
@@ -15,4 +15,5 @@ while ( arg !== __filename
templateready
.addEngine(require('./compilers/underscore-template'))
.addEngine(require('./compilers/mustache'))
+ .addEngine(require('./compilers/jade'))
.run(args);
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "templateready",
- "version": "0.1.2",
+ "version": "0.2.0",
"description": "Template on the fly pre-compiler.",
"author": "Alexander `Staltec` Prozorov <staltec@gmail.com>",
"dependencies": {
View
62 templateready.js
@@ -4,26 +4,26 @@
* Time: 22:42
*/
-var util = require("util");
-var path = require("path");
-var fs = require("fs");
-var async = require("async");
-var jsp = require("uglify-js").parser;
-var pro = require("uglify-js").uglify;
-var zlib = require('zlib');
-var meta = require("./package.json");
-
-var cfg = {},
- sourceDirRegExp,
- templateNames,
- alreadyWatched = {},
- compilers = [];
+var util = require("util")
+ , path = require("path")
+ , fs = require("fs")
+ , async = require("async")
+ , jsp = require("uglify-js").parser
+ , pro = require("uglify-js").uglify
+ , zlib = require('zlib')
+ , meta = require("./package.json");
+
+var cfg = {}
+ , sourceDirRegExp
+ , templateNames
+ , runtimeCode
+ , alreadyWatched = {}
+ , compilers = [];
exports.addEngine = function(engine, forcePattern){
if(engine && engine.filePattern instanceof RegExp && engine.compiler instanceof Function){
if(forcePattern instanceof RegExp) engine.filePattern = forcePattern;
compilers.push(engine);
- //util.puts('Plugin template engine: "'+(engine.name?engine.name:'Unknown')+'" with pattern: '+engine.filePattern);
}
return this;
};
@@ -44,6 +44,8 @@ exports.run = function (args){
return console.log('templateready version: '+meta.version);
} else if(arg === "--watch" || arg === "-w"){
cfg.watch = true;
+ } else if(arg === "--runtime" || arg === "-r"){
+ cfg.runtime = true;
} else if(arg === "--dir" || arg === "-d"){
cfg.workDir = args.shift();
} else if(arg === "--file" || arg === "-f"){
@@ -146,6 +148,7 @@ var _requireSample = function (n){ return this[this._n[n]] };
function compileFiles (files){
var hdr, buf = '';
templateNames = {};
+ runtimeCode = {};
async.map(files,
function(f, cb){
@@ -161,6 +164,10 @@ function compileFiles (files){
buf += 'require: '+_requireSample.toString()+'\n';
buf += '}\n\n';
+ for(var key in runtimeCode) if (runtimeCode.hasOwnProperty(key)) {
+ buf += runtimeCode[key]+'\n\n';
+ }
+
// Save common JS file
saveToFile(cfg.outFile+'.js', hdr + buf);
@@ -194,20 +201,24 @@ function getFuncName(file){
function compileFile (file, callback){
- var compiler;
+ var engine;
for(var i=0, l=compilers.length; i<l; i++){
if(compilers[i].filePattern.test(file)){
- compiler = compilers[i].compiler;
+ engine = compilers[i];
break;
}
}
- if(compiler){
- compiler({file:file}, function(err, funcCode){
+ if(engine && engine.compiler){
+ engine.compiler({file:file}, function(err, funcCode){
if(err){
callback(err, '');
util.error('Trouble with template file: ' + file + ' > '+ err);
}else{
+ // get runtime code if exists
+ if(cfg.runtime && engine.type && engine.runtime) runtimeCode[engine.type] = engine.runtime;
+
+ // return template code
callback(null, funcCode ? getFuncName(file)+': ' + funcCode + ',' : '');
}
if(!cfg.isWindowsWithoutWatchFile) watchGivenFile(file);
@@ -281,14 +292,18 @@ function help (){
(" Default is 'templates.js'")
("")
- (" -t, --target <targetVariable>")
+ (" -t| --target <targetVariable>")
(" Name of the global object containing templates.")
(" Default is 'TemplateReady'")
("")
+ (" -r| --runtime")
+ (" Add template library runtime code (if exists) into the output script file.")
+ (" No default")
+ ("")
+
(" -w|--watch")
- (" Watch for changes for source directory.")
- (" When a change template file occurs, rebuild output js files")
+ (" When a change template file occurs, rebuild output js file.")
(" No default")
("")
@@ -309,8 +324,9 @@ function help (){
("")
("Examples:")
+ (" templateready -d ./wwwroot/app --runtime")
(" templateready -d ./wwwroot/app -s mytemplates -w -p 1000")
- (" templateready --source ./wwwroot/mytemplates --file ./wwwroot/app/comiled.js --target 'Application.Templates'")
+ (" templateready --source ./wwwroot/mytemplates --file ./wwwroot/app/comiled.js --target 'MyApplicationTemplates'")
("");
}
View
10 wwwroot/app/index.js
@@ -31,6 +31,10 @@
testFunc('mustacheTest_space');
testFile('mustache/test space.mustache');
+ // Jade template
+ testFunc('jadeTest');
+ testFile('jade/test.jade');
+
}
/* ----------------------------------------------- */
@@ -62,9 +66,6 @@
counter++;
if(!locals) locals = testData;
- var sb = document.getElementById('statusBar');
- sb.innerHTML += '<a href="#'+counter+'" style="text-decoration:none; background-color:'+(err ? 'red' : 'green')+'">&nbsp;&nbsp;&nbsp;&nbsp;</a>&nbsp;';
-
var html, err, f;
try{
f = Template.require(fileName);
@@ -74,6 +75,9 @@
html = e;
}
+ var sb = document.getElementById('statusBar');
+ sb.innerHTML += '<a href="#'+counter+'" style="text-decoration:none; background-color:'+(err ? 'red' : 'green')+'">&nbsp;&nbsp;&nbsp;&nbsp;</a>&nbsp;';
+
var tests = document.getElementById('tests');
tests.innerHTML += '<span id="'+counter+'" style="background-color:'+(err ? 'red' : 'green')+'">&nbsp;&nbsp;&nbsp;&nbsp;</span> <strong>File "'+fileName+'"</strong>';
tests.innerHTML += '<div style="padding:5px; margin-bottom:30px; border: 1px dashed #999999; background-color: #eeeeee">'+html+'</div>';
View
5 wwwroot/app/runtime/hogan.template-2.0.0.min.js
@@ -0,0 +1,5 @@
+/**
+* @preserve Copyright 2012 Twitter, Inc.
+* @license http://www.apache.org/licenses/LICENSE-2.0.txt
+*/
+var Hogan={};(function(a,b){function i(a){return String(a===null||a===undefined?"":a)}function j(a){return a=i(a),h.test(a)?a.replace(c,"&amp;").replace(d,"&lt;").replace(e,"&gt;").replace(f,"&#39;").replace(g,"&quot;"):a}a.Template=function(a,c,d,e){this.r=a||this.r,this.c=d,this.options=e,this.text=c||"",this.buf=b?[]:""},a.Template.prototype={r:function(a,b,c){return""},v:j,t:i,render:function(b,c,d){return this.ri([b],c||{},d)},ri:function(a,b,c){return this.r(a,b,c)},rp:function(a,b,c,d){var e=c[a];return e?(this.c&&typeof e=="string"&&(e=this.c.compile(e,this.options)),e.ri(b,c,d)):""},rs:function(a,b,c){var d=a[a.length-1];if(!k(d)){c(a,b,this);return}for(var e=0;e<d.length;e++)a.push(d[e]),c(a,b,this),a.pop()},s:function(a,b,c,d,e,f,g){var h;return k(a)&&a.length===0?!1:(typeof a=="function"&&(a=this.ls(a,b,c,d,e,f,g)),h=a===""||!!a,!d&&h&&b&&b.push(typeof a=="object"?a:b[b.length-1]),h)},d:function(a,b,c,d){var e=a.split("."),f=this.f(e[0],b,c,d),g=null;if(a==="."&&k(b[b.length-2]))return b[b.length-1];for(var h=1;h<e.length;h++)f&&typeof f=="object"&&e[h]in f?(g=f,f=f[e[h]]):f="";return d&&!f?!1:(!d&&typeof f=="function"&&(b.push(g),f=this.lv(f,b,c),b.pop()),f)},f:function(a,b,c,d){var e=!1,f=null,g=!1;for(var h=b.length-1;h>=0;h--){f=b[h];if(f&&typeof f=="object"&&a in f){e=f[a],g=!0;break}}return g?(!d&&typeof e=="function"&&(e=this.lv(e,b,c)),e):d?!1:""},ho:function(a,b,c,d,e){var f=this.c,g=this.options;g.delimiters=e;var d=a.call(b,d);return d=d==null?String(d):d.toString(),this.b(f.compile(d,g).render(b,c)),!1},b:b?function(a){this.buf.push(a)}:function(a){this.buf+=a},fl:b?function(){var a=this.buf.join("");return this.buf=[],a}:function(){var a=this.buf;return this.buf="",a},ls:function(a,b,c,d,e,f,g){var h=b[b.length-1],i=null;if(!d&&this.c&&a.length>0)return this.ho(a,h,c,this.text.substring(e,f),g);i=a.call(h);if(typeof i=="function"){if(d)return!0;if(this.c)return this.ho(i,h,c,this.text.substring(e,f),g)}return i},lv:function(a,b,c){var d=b[b.length-1],e=a.call(d);if(typeof e=="function"){e=i(e.call(d));if(this.c&&~e.indexOf("{{"))return this.c.compile(e,this.options).render(d,c)}return i(e)}};var c=/&/g,d=/</g,e=/>/g,f=/\'/g,g=/\"/g,h=/[&<>\"\']/,k=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"}})(typeof exports!="undefined"?exports:Hogan)
View
1 wwwroot/app/runtime/jade.runtime.min.js
@@ -0,0 +1 @@
+jade=function(exports){Array.isArray||(Array.isArray=function(arr){return"[object Array]"==Object.prototype.toString.call(arr)}),Object.keys||(Object.keys=function(obj){var arr=[];for(var key in obj)obj.hasOwnProperty(key)&&arr.push(key);return arr}),exports.merge=function merge(a,b){var ac=a["class"],bc=b["class"];if(ac||bc)ac=ac||[],bc=bc||[],Array.isArray(ac)||(ac=[ac]),Array.isArray(bc)||(bc=[bc]),ac=ac.filter(nulls),bc=bc.filter(nulls),a["class"]=ac.concat(bc).join(" ");for(var key in b)key!="class"&&(a[key]=b[key]);return a};function nulls(val){return val!=null}return exports.attrs=function attrs(obj,escaped){var buf=[],terse=obj.terse;delete obj.terse;var keys=Object.keys(obj),len=keys.length;if(len){buf.push("");for(var i=0;i<len;++i){var key=keys[i],val=obj[key];"boolean"==typeof val||null==val?val&&(terse?buf.push(key):buf.push(key+'="'+key+'"')):0==key.indexOf("data")&&"string"!=typeof val?buf.push(key+"='"+JSON.stringify(val)+"'"):"class"==key&&Array.isArray(val)?buf.push(key+'="'+exports.escape(val.join(" "))+'"'):escaped&&escaped[key]?buf.push(key+'="'+exports.escape(val)+'"'):buf.push(key+'="'+val+'"')}}return buf.join(" ")},exports.escape=function escape(html){return String(html).replace(/&(?!(\w+|\#\d+);)/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},exports.rethrow=function rethrow(err,filename,lineno){if(!filename)throw err;var context=3,str=require("fs").readFileSync(filename,"utf8"),lines=str.split("\n"),start=Math.max(lineno-context,0),end=Math.min(lines.length,lineno+context),context=lines.slice(start,end).map(function(line,i){var curr=i+start+1;return(curr==lineno?" > ":" ")+curr+"| "+line}).join("\n");throw err.path=filename,err.message=(filename||"Jade")+":"+lineno+"\n"+context+"\n\n"+err.message,err},exports}({});
View
22 wwwroot/app/templates.js
@@ -1,5 +1,5 @@
-// Assembled by TemplateReady 0.1.2
-// At Fri Nov 09 2012 23:57:02 GMT+0800 (KRAT)
+// Assembled by TemplateReady 0.2.0
+// At Sat Nov 10 2012 05:52:31 GMT+0800 (KRAT)
var TemplateReady = {
@@ -43,7 +43,23 @@ mustacheTest_space: function(obj){return new Hogan.Template(function(c,p,i){var
mustacheTest: function(obj){return new Hogan.Template(function(c,p,i){var _=this;_.b(i=i||"");_.b("<div>");_.b("\n" + i);_.b(" <h1>");_.b(_.v(_.f("title",c,p,0)));_.b("</h1>");_.b("\n" + i);_.b("\n" + i);_.b(" <ol>");_.b("\n" + i);if(_.s(_.f("list",c,p,1),c,p,0,52,80,"{{ }}")){_.rs(c,p,function(c,p,_){_.b(" <li>");_.b(_.v(_.d(".",c,p,0)));_.b("</li>");_.b("\n");});c.pop();}if(!_.s(_.f("list",c,p,1),c,p,1,0,0,"")){_.b(" <li>Пустой список (не будет показан).</li>");_.b("\n");};_.b(" </ol>");_.b("\n" + i);_.b("\n" + i);if(_.s(_.f("hash",c,p,1),c,p,0,193,277,"{{ }}")){_.rs(c,p,function(c,p,_){_.b(" <h2>Дискография: ");_.b(_.v(_.f("firstName",c,p,0)));_.b(" ");_.b(_.v(_.f("lastName",c,p,0)));_.b(" ");if(_.s(_.f("age",c,p,1),c,p,0,250,259,"{{ }}")){_.rs(c,p,function(c,p,_){_.b("(");_.b(_.v(_.f("age",c,p,0)));_.b(")");});c.pop();}_.b("</h2>");_.b("\n");});c.pop();}_.b("\n" + i);_.b(" <ul>");_.b("\n" + i);if(_.s(_.f("objList",c,p,1),c,p,0,313,362,"{{ }}")){_.rs(c,p,function(c,p,_){_.b(" <li>");_.b(_.v(_.f("year",c,p,0)));_.b(" &mdash; ");_.b(_.v(_.f("album",c,p,0)));_.b("</li>");_.b("\n");});c.pop();}_.b(" </ul>");_.b("\n" + i);_.b("\n" + i);_.b("\n" + i);_.b("</div>");_.b("\n" + i);_.b("\n");return _.fl();;}).render(obj)},
-_n: {"underscore/test.htm":"underscoreTest","mustache/test space.mustache":"mustacheTest_space","mustache/test.mustache":"mustacheTest"},
+jadeTest: function(locals, attrs, escape, rethrow, merge) {
+attrs = attrs || jade.attrs; escape = escape || jade.escape; rethrow = rethrow || jade.rethrow; merge = merge || jade.merge;
+var buf = [];
+var self = locals || {};
+var interp;
+buf.push('<h1>hello</h1><div id="main">Hello world</div>');return buf.join("");
+},
+
+_n: {"underscore/test.htm":"underscoreTest","mustache/test space.mustache":"mustacheTest_space","mustache/test.mustache":"mustacheTest","jade/test.jade":"jadeTest"},
require: function (n){ return this[this._n[n]] }
}
+/**
+* @preserve Copyright 2012 Twitter, Inc.
+* @license http://www.apache.org/licenses/LICENSE-2.0.txt
+*/
+var Hogan={};(function(a,b){function i(a){return String(a===null||a===undefined?"":a)}function j(a){return a=i(a),h.test(a)?a.replace(c,"&amp;").replace(d,"&lt;").replace(e,"&gt;").replace(f,"&#39;").replace(g,"&quot;"):a}a.Template=function(a,c,d,e){this.r=a||this.r,this.c=d,this.options=e,this.text=c||"",this.buf=b?[]:""},a.Template.prototype={r:function(a,b,c){return""},v:j,t:i,render:function(b,c,d){return this.ri([b],c||{},d)},ri:function(a,b,c){return this.r(a,b,c)},rp:function(a,b,c,d){var e=c[a];return e?(this.c&&typeof e=="string"&&(e=this.c.compile(e,this.options)),e.ri(b,c,d)):""},rs:function(a,b,c){var d=a[a.length-1];if(!k(d)){c(a,b,this);return}for(var e=0;e<d.length;e++)a.push(d[e]),c(a,b,this),a.pop()},s:function(a,b,c,d,e,f,g){var h;return k(a)&&a.length===0?!1:(typeof a=="function"&&(a=this.ls(a,b,c,d,e,f,g)),h=a===""||!!a,!d&&h&&b&&b.push(typeof a=="object"?a:b[b.length-1]),h)},d:function(a,b,c,d){var e=a.split("."),f=this.f(e[0],b,c,d),g=null;if(a==="."&&k(b[b.length-2]))return b[b.length-1];for(var h=1;h<e.length;h++)f&&typeof f=="object"&&e[h]in f?(g=f,f=f[e[h]]):f="";return d&&!f?!1:(!d&&typeof f=="function"&&(b.push(g),f=this.lv(f,b,c),b.pop()),f)},f:function(a,b,c,d){var e=!1,f=null,g=!1;for(var h=b.length-1;h>=0;h--){f=b[h];if(f&&typeof f=="object"&&a in f){e=f[a],g=!0;break}}return g?(!d&&typeof e=="function"&&(e=this.lv(e,b,c)),e):d?!1:""},ho:function(a,b,c,d,e){var f=this.c,g=this.options;g.delimiters=e;var d=a.call(b,d);return d=d==null?String(d):d.toString(),this.b(f.compile(d,g).render(b,c)),!1},b:b?function(a){this.buf.push(a)}:function(a){this.buf+=a},fl:b?function(){var a=this.buf.join("");return this.buf=[],a}:function(){var a=this.buf;return this.buf="",a},ls:function(a,b,c,d,e,f,g){var h=b[b.length-1],i=null;if(!d&&this.c&&a.length>0)return this.ho(a,h,c,this.text.substring(e,f),g);i=a.call(h);if(typeof i=="function"){if(d)return!0;if(this.c)return this.ho(i,h,c,this.text.substring(e,f),g)}return i},lv:function(a,b,c){var d=b[b.length-1],e=a.call(d);if(typeof e=="function"){e=i(e.call(d));if(this.c&&~e.indexOf("{{"))return this.c.compile(e,this.options).render(d,c)}return i(e)}};var c=/&/g,d=/</g,e=/>/g,f=/\'/g,g=/\"/g,h=/[&<>\"\']/,k=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"}})(typeof exports!="undefined"?exports:Hogan);
+
+jade=function(exports){Array.isArray||(Array.isArray=function(arr){return"[object Array]"==Object.prototype.toString.call(arr)}),Object.keys||(Object.keys=function(obj){var arr=[];for(var key in obj)obj.hasOwnProperty(key)&&arr.push(key);return arr}),exports.merge=function merge(a,b){var ac=a["class"],bc=b["class"];if(ac||bc)ac=ac||[],bc=bc||[],Array.isArray(ac)||(ac=[ac]),Array.isArray(bc)||(bc=[bc]),ac=ac.filter(nulls),bc=bc.filter(nulls),a["class"]=ac.concat(bc).join(" ");for(var key in b)key!="class"&&(a[key]=b[key]);return a};function nulls(val){return val!=null}return exports.attrs=function attrs(obj,escaped){var buf=[],terse=obj.terse;delete obj.terse;var keys=Object.keys(obj),len=keys.length;if(len){buf.push("");for(var i=0;i<len;++i){var key=keys[i],val=obj[key];"boolean"==typeof val||null==val?val&&(terse?buf.push(key):buf.push(key+'="'+key+'"')):0==key.indexOf("data")&&"string"!=typeof val?buf.push(key+"='"+JSON.stringify(val)+"'"):"class"==key&&Array.isArray(val)?buf.push(key+'="'+exports.escape(val.join(" "))+'"'):escaped&&escaped[key]?buf.push(key+'="'+exports.escape(val)+'"'):buf.push(key+'="'+val+'"')}}return buf.join(" ")},exports.escape=function escape(html){return String(html).replace(/&(?!(\w+|\#\d+);)/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},exports.rethrow=function rethrow(err,filename,lineno){if(!filename)throw err;var context=3,str=require("fs").readFileSync(filename,"utf8"),lines=str.split("\n"),start=Math.max(lineno-context,0),end=Math.min(lines.length,lineno+context),context=lines.slice(start,end).map(function(line,i){var curr=i+start+1;return(curr==lineno?" > ":" ")+curr+"| "+line}).join("\n");throw err.path=filename,err.message=(filename||"Jade")+":"+lineno+"\n"+context+"\n\n"+err.message,err},exports}({});
+
View
2 wwwroot/app/templates.min.js
@@ -1 +1 @@
-var TemplateReady={underscoreTest:function(obj){var __t,__p="",__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,"")};with(obj||{}){__p+="<div>\r\n <h1>"+((__t=title)==null?"":__t)+"</h1>\r\n\r\n <ol>\r\n ";if(list.length){__p+="\r\n ";for(var v,i=0,l=list.length;i<l;i++)v=list[i],__p+="\r\n <li>"+((__t=v)==null?"":__t)+"</li>\r\n ";__p+="\r\n "}else __p+="\r\n <li>Пустой список (не будет показан).</li>\r\n ";__p+="\r\n </ol>\r\n\r\n <h2>Дискография: "+((__t=hash.firstName)==null?"":__t)+" "+((__t=hash.lastName)==null?"":__t)+" "+((__t=hash.age?"("+hash.age+")":"")==null?"":__t)+"</h2>\r\n\r\n <ul>\r\n ";for(var v,i=0,l=objList.length;i<l;i++)v=objList[i],__p+="\r\n <li>"+((__t=v.year)==null?"":__t)+" &mdash; "+((__t=v.album)==null?"":__t)+"</li>\r\n ";__p+="\r\n </ul>\r\n</div>"}return __p},mustacheTest_space:function(e){return(new Hogan.Template(function(e,t,n){var r=this;return r.b(n=n||""),r.b("<div>"),r.b("\n"+n),r.b(" <h1>"),r.b(r.v(r.f("title",e,t,0))),r.b("</h1>"),r.b("\n"+n),r.b("\n"+n),r.b(" <ol>"),r.b("\n"+n),r.s(r.f("list",e,t,1),e,t,0,52,80,"{{ }}")&&(r.rs(e,t,function(e,t,n){n.b(" <li>"),n.b(n.v(n.d(".",e,t,0))),n.b("</li>"),n.b("\n")}),e.pop()),r.s(r.f("list",e,t,1),e,t,1,0,0,"")||(r.b(" <li>Пустой список (не будет показан).</li>"),r.b("\n")),r.b(" </ol>"),r.b("\n"+n),r.b("\n"+n),r.s(r.f("hash",e,t,1),e,t,0,193,277,"{{ }}")&&(r.rs(e,t,function(e,t,n){n.b(" <h2>Дискография: "),n.b(n.v(n.f("firstName",e,t,0))),n.b(" "),n.b(n.v(n.f("lastName",e,t,0))),n.b(" "),n.s(n.f("age",e,t,1),e,t,0,250,259,"{{ }}")&&(n.rs(e,t,function(e,t,n){n.b("("),n.b(n.v(n.f("age",e,t,0))),n.b(")")}),e.pop()),n.b("</h2>"),n.b("\n")}),e.pop()),r.b("\n"+n),r.b(" <ul>"),r.b("\n"+n),r.s(r.f("objList",e,t,1),e,t,0,313,362,"{{ }}")&&(r.rs(e,t,function(e,t,n){n.b(" <li>"),n.b(n.v(n.f("year",e,t,0))),n.b(" &mdash; "),n.b(n.v(n.f("album",e,t,0))),n.b("</li>"),n.b("\n")}),e.pop()),r.b(" </ul>"),r.b("\n"+n),r.b("\n"+n),r.b("\n"+n),r.b("</div>"),r.b("\n"+n),r.b("\n"),r.fl()})).render(e)},mustacheTest:function(e){return(new Hogan.Template(function(e,t,n){var r=this;return r.b(n=n||""),r.b("<div>"),r.b("\n"+n),r.b(" <h1>"),r.b(r.v(r.f("title",e,t,0))),r.b("</h1>"),r.b("\n"+n),r.b("\n"+n),r.b(" <ol>"),r.b("\n"+n),r.s(r.f("list",e,t,1),e,t,0,52,80,"{{ }}")&&(r.rs(e,t,function(e,t,n){n.b(" <li>"),n.b(n.v(n.d(".",e,t,0))),n.b("</li>"),n.b("\n")}),e.pop()),r.s(r.f("list",e,t,1),e,t,1,0,0,"")||(r.b(" <li>Пустой список (не будет показан).</li>"),r.b("\n")),r.b(" </ol>"),r.b("\n"+n),r.b("\n"+n),r.s(r.f("hash",e,t,1),e,t,0,193,277,"{{ }}")&&(r.rs(e,t,function(e,t,n){n.b(" <h2>Дискография: "),n.b(n.v(n.f("firstName",e,t,0))),n.b(" "),n.b(n.v(n.f("lastName",e,t,0))),n.b(" "),n.s(n.f("age",e,t,1),e,t,0,250,259,"{{ }}")&&(n.rs(e,t,function(e,t,n){n.b("("),n.b(n.v(n.f("age",e,t,0))),n.b(")")}),e.pop()),n.b("</h2>"),n.b("\n")}),e.pop()),r.b("\n"+n),r.b(" <ul>"),r.b("\n"+n),r.s(r.f("objList",e,t,1),e,t,0,313,362,"{{ }}")&&(r.rs(e,t,function(e,t,n){n.b(" <li>"),n.b(n.v(n.f("year",e,t,0))),n.b(" &mdash; "),n.b(n.v(n.f("album",e,t,0))),n.b("</li>"),n.b("\n")}),e.pop()),r.b(" </ul>"),r.b("\n"+n),r.b("\n"+n),r.b("\n"+n),r.b("</div>"),r.b("\n"+n),r.b("\n"),r.fl()})).render(e)},_n:{"underscore/test.htm":"underscoreTest","mustache/test space.mustache":"mustacheTest_space","mustache/test.mustache":"mustacheTest"},require:function(e){return this[this._n[e]]}}
+var TemplateReady={underscoreTest:function(obj){var __t,__p="",__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,"")};with(obj||{}){__p+="<div>\r\n <h1>"+((__t=title)==null?"":__t)+"</h1>\r\n\r\n <ol>\r\n ";if(list.length){__p+="\r\n ";for(var v,i=0,l=list.length;i<l;i++)v=list[i],__p+="\r\n <li>"+((__t=v)==null?"":__t)+"</li>\r\n ";__p+="\r\n "}else __p+="\r\n <li>Пустой список (не будет показан).</li>\r\n ";__p+="\r\n </ol>\r\n\r\n <h2>Дискография: "+((__t=hash.firstName)==null?"":__t)+" "+((__t=hash.lastName)==null?"":__t)+" "+((__t=hash.age?"("+hash.age+")":"")==null?"":__t)+"</h2>\r\n\r\n <ul>\r\n ";for(var v,i=0,l=objList.length;i<l;i++)v=objList[i],__p+="\r\n <li>"+((__t=v.year)==null?"":__t)+" &mdash; "+((__t=v.album)==null?"":__t)+"</li>\r\n ";__p+="\r\n </ul>\r\n</div>"}return __p},mustacheTest_space:function(e){return(new Hogan.Template(function(e,t,n){var r=this;return r.b(n=n||""),r.b("<div>"),r.b("\n"+n),r.b(" <h1>"),r.b(r.v(r.f("title",e,t,0))),r.b("</h1>"),r.b("\n"+n),r.b("\n"+n),r.b(" <ol>"),r.b("\n"+n),r.s(r.f("list",e,t,1),e,t,0,52,80,"{{ }}")&&(r.rs(e,t,function(e,t,n){n.b(" <li>"),n.b(n.v(n.d(".",e,t,0))),n.b("</li>"),n.b("\n")}),e.pop()),r.s(r.f("list",e,t,1),e,t,1,0,0,"")||(r.b(" <li>Пустой список (не будет показан).</li>"),r.b("\n")),r.b(" </ol>"),r.b("\n"+n),r.b("\n"+n),r.s(r.f("hash",e,t,1),e,t,0,193,277,"{{ }}")&&(r.rs(e,t,function(e,t,n){n.b(" <h2>Дискография: "),n.b(n.v(n.f("firstName",e,t,0))),n.b(" "),n.b(n.v(n.f("lastName",e,t,0))),n.b(" "),n.s(n.f("age",e,t,1),e,t,0,250,259,"{{ }}")&&(n.rs(e,t,function(e,t,n){n.b("("),n.b(n.v(n.f("age",e,t,0))),n.b(")")}),e.pop()),n.b("</h2>"),n.b("\n")}),e.pop()),r.b("\n"+n),r.b(" <ul>"),r.b("\n"+n),r.s(r.f("objList",e,t,1),e,t,0,313,362,"{{ }}")&&(r.rs(e,t,function(e,t,n){n.b(" <li>"),n.b(n.v(n.f("year",e,t,0))),n.b(" &mdash; "),n.b(n.v(n.f("album",e,t,0))),n.b("</li>"),n.b("\n")}),e.pop()),r.b(" </ul>"),r.b("\n"+n),r.b("\n"+n),r.b("\n"+n),r.b("</div>"),r.b("\n"+n),r.b("\n"),r.fl()})).render(e)},mustacheTest:function(e){return(new Hogan.Template(function(e,t,n){var r=this;return r.b(n=n||""),r.b("<div>"),r.b("\n"+n),r.b(" <h1>"),r.b(r.v(r.f("title",e,t,0))),r.b("</h1>"),r.b("\n"+n),r.b("\n"+n),r.b(" <ol>"),r.b("\n"+n),r.s(r.f("list",e,t,1),e,t,0,52,80,"{{ }}")&&(r.rs(e,t,function(e,t,n){n.b(" <li>"),n.b(n.v(n.d(".",e,t,0))),n.b("</li>"),n.b("\n")}),e.pop()),r.s(r.f("list",e,t,1),e,t,1,0,0,"")||(r.b(" <li>Пустой список (не будет показан).</li>"),r.b("\n")),r.b(" </ol>"),r.b("\n"+n),r.b("\n"+n),r.s(r.f("hash",e,t,1),e,t,0,193,277,"{{ }}")&&(r.rs(e,t,function(e,t,n){n.b(" <h2>Дискография: "),n.b(n.v(n.f("firstName",e,t,0))),n.b(" "),n.b(n.v(n.f("lastName",e,t,0))),n.b(" "),n.s(n.f("age",e,t,1),e,t,0,250,259,"{{ }}")&&(n.rs(e,t,function(e,t,n){n.b("("),n.b(n.v(n.f("age",e,t,0))),n.b(")")}),e.pop()),n.b("</h2>"),n.b("\n")}),e.pop()),r.b("\n"+n),r.b(" <ul>"),r.b("\n"+n),r.s(r.f("objList",e,t,1),e,t,0,313,362,"{{ }}")&&(r.rs(e,t,function(e,t,n){n.b(" <li>"),n.b(n.v(n.f("year",e,t,0))),n.b(" &mdash; "),n.b(n.v(n.f("album",e,t,0))),n.b("</li>"),n.b("\n")}),e.pop()),r.b(" </ul>"),r.b("\n"+n),r.b("\n"+n),r.b("\n"+n),r.b("</div>"),r.b("\n"+n),r.b("\n"),r.fl()})).render(e)},jadeTest:function(e,t,n,r,i){t=t||jade.attrs,n=n||jade.escape,r=r||jade.rethrow,i=i||jade.merge;var s=[],o=e||{},u;return s.push('<h1>hello</h1><div id="main">Hello world</div>'),s.join("")},_n:{"underscore/test.htm":"underscoreTest","mustache/test space.mustache":"mustacheTest_space","mustache/test.mustache":"mustacheTest","jade/test.jade":"jadeTest"},require:function(e){return this[this._n[e]]}},Hogan={};(function(e,t){function n(e){return String(e===null||e===undefined?"":e)}function r(e){return e=n(e),f.test(e)?e.replace(i,"&amp;").replace(s,"&lt;").replace(o,"&gt;").replace(u,"&#39;").replace(a,"&quot;"):e}e.Template=function(e,n,r,i){this.r=e||this.r,this.c=r,this.options=i,this.text=n||"",this.buf=t?[]:""},e.Template.prototype={r:function(e,t,n){return""},v:r,t:n,render:function(e,t,n){return this.ri([e],t||{},n)},ri:function(e,t,n){return this.r(e,t,n)},rp:function(e,t,n,r){var i=n[e];return i?(this.c&&typeof i=="string"&&(i=this.c.compile(i,this.options)),i.ri(t,n,r)):""},rs:function(e,t,n){var r=e[e.length-1];if(!l(r)){n(e,t,this);return}for(var i=0;i<r.length;i++)e.push(r[i]),n(e,t,this),e.pop()},s:function(e,t,n,r,i,s,o){var u;return l(e)&&e.length===0?!1:(typeof e=="function"&&(e=this.ls(e,t,n,r,i,s,o)),u=e===""||!!e,!r&&u&&t&&t.push(typeof e=="object"?e:t[t.length-1]),u)},d:function(e,t,n,r){var i=e.split("."),s=this.f(i[0],t,n,r),o=null;if(e==="."&&l(t[t.length-2]))return t[t.length-1];for(var u=1;u<i.length;u++)s&&typeof s=="object"&&i[u]in s?(o=s,s=s[i[u]]):s="";return r&&!s?!1:(!r&&typeof s=="function"&&(t.push(o),s=this.lv(s,t,n),t.pop()),s)},f:function(e,t,n,r){var i=!1,s=null,o=!1;for(var u=t.length-1;u>=0;u--){s=t[u];if(s&&typeof s=="object"&&e in s){i=s[e],o=!0;break}}return o?(!r&&typeof i=="function"&&(i=this.lv(i,t,n)),i):r?!1:""},ho:function(e,t,n,r,i){var s=this.c,o=this.options;o.delimiters=i;var r=e.call(t,r);return r=r==null?String(r):r.toString(),this.b(s.compile(r,o).render(t,n)),!1},b:t?function(e){this.buf.push(e)}:function(e){this.buf+=e},fl:t?function(){var e=this.buf.join("");return this.buf=[],e}:function(){var e=this.buf;return this.buf="",e},ls:function(e,t,n,r,i,s,o){var u=t[t.length-1],a=null;if(!r&&this.c&&e.length>0)return this.ho(e,u,n,this.text.substring(i,s),o);a=e.call(u);if(typeof a=="function"){if(r)return!0;if(this.c)return this.ho(a,u,n,this.text.substring(i,s),o)}return a},lv:function(e,t,r){var i=t[t.length-1],s=e.call(i);if(typeof s=="function"){s=n(s.call(i));if(this.c&&~s.indexOf("{{"))return this.c.compile(s,this.options).render(i,r)}return n(s)}};var i=/&/g,s=/</g,o=/>/g,u=/\'/g,a=/\"/g,f=/[&<>\"\']/,l=Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"}})(typeof exports!="undefined"?exports:Hogan),jade=function(e){function t(e){return e!=null}return Array.isArray||(Array.isArray=function(e){return"[object Array]"==Object.prototype.toString.call(e)}),Object.keys||(Object.keys=function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);return t}),e.merge=function(n,r){var i=n["class"],s=r["class"];if(i||s)i=i||[],s=s||[],Array.isArray(i)||(i=[i]),Array.isArray(s)||(s=[s]),i=i.filter(t),s=s.filter(t),n["class"]=i.concat(s).join(" ");for(var o in r)o!="class"&&(n[o]=r[o]);return n},e.attrs=function(n,r){var i=[],s=n.terse;delete n.terse;var o=Object.keys(n),u=o.length;if(u){i.push("");for(var a=0;a<u;++a){var f=o[a],l=n[f];"boolean"==typeof l||null==l?l&&(s?i.push(f):i.push(f+'="'+f+'"')):0==f.indexOf("data")&&"string"!=typeof l?i.push(f+"='"+JSON.stringify(l)+"'"):"class"==f&&Array.isArray(l)?i.push(f+'="'+e.escape(l.join(" "))+'"'):r&&r[f]?i.push(f+'="'+e.escape(l)+'"'):i.push(f+'="'+l+'"')}}return i.join(" ")},e.escape=function(t){return String(t).replace(/&(?!(\w+|\#\d+);)/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},e.rethrow=function(t,n,r){if(!n)throw t;var i=3,s=require("fs").readFileSync(n,"utf8"),o=s.split("\n"),u=Math.max(r-i,0),a=Math.min(o.length,r+i),i=o.slice(u,a).map(function(e,t){var n=t+u+1;return(n==r?" > ":" ")+n+"| "+e}).join("\n");throw t.path=n,t.message=(n||"Jade")+":"+r+"\n"+i+"\n\n"+t.message,t},e}({})
View
BIN wwwroot/app/templates.min.js.gz
Binary file not shown.
View
3 wwwroot/app/templates/jade/test.jade
@@ -0,0 +1,3 @@
+h1 hello
+
+#main Hello world
View
3 wwwroot/index.htm
@@ -7,7 +7,8 @@
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
- <script src="/app/hogan/template-2.0.0.min.js"></script> <!-- Need for mustache pre-compile templates -->
+ <!-- <script src="/app/runtime/hogan.template-2.0.0.min.js"></script> <!-- Runtime for Mustache pre-compile templates -->
+ <!-- <script src="/app/runtime/jade.runtime.min.js"></script> <!-- Runtime for Jade pre-compile templates -->
<script src="/app/index.js?"></script>
<script src="/app/templates.min.js"></script>

0 comments on commit 0471e5f

Please sign in to comment.