templatizer
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -7,3 +7,9 @@ (function () { | ||
// users.jade compiled: | ||
// create our folder objects | ||
exports.nested = {}; | ||
exports.otherfolder = {}; | ||
exports.otherfolder.deep2 = {}; | ||
exports.otherfolder.deepnested = {}; | ||
// users.jade compiled template | ||
exports.users = function anonymous(locals, attrs, escape, rethrow, merge) { | ||
@@ -43,4 +49,76 @@ attrs = attrs || jade.attrs; | ||
// tweet.jade compiled template | ||
exports.nested.tweet = function anonymous(locals, attrs, escape, rethrow, merge) { | ||
attrs = attrs || jade.attrs; | ||
escape = escape || jade.escape; | ||
rethrow = rethrow || jade.rethrow; | ||
merge = merge || jade.merge; | ||
var buf = []; | ||
with (locals || {}) { | ||
var interp; | ||
var __indent = []; | ||
buf.push('\n<li class="tweet">'); | ||
var __val__ = user; | ||
buf.push(escape(null == __val__ ? "" : __val__)); | ||
buf.push("</li>"); | ||
} | ||
return buf.join(""); | ||
}; | ||
// attach to windor or export with commonJS | ||
// othertweet.jade compiled template | ||
exports.otherfolder.othertweet = function anonymous(locals, attrs, escape, rethrow, merge) { | ||
attrs = attrs || jade.attrs; | ||
escape = escape || jade.escape; | ||
rethrow = rethrow || jade.rethrow; | ||
merge = merge || jade.merge; | ||
var buf = []; | ||
with (locals || {}) { | ||
var interp; | ||
var __indent = []; | ||
buf.push('\n<li class="tweet">'); | ||
var __val__ = user; | ||
buf.push(escape(null == __val__ ? "" : __val__)); | ||
buf.push("</li>"); | ||
} | ||
return buf.join(""); | ||
}; | ||
// deeptweet.jade compiled template | ||
exports.otherfolder.deep2.deeptweet = function anonymous(locals, attrs, escape, rethrow, merge) { | ||
attrs = attrs || jade.attrs; | ||
escape = escape || jade.escape; | ||
rethrow = rethrow || jade.rethrow; | ||
merge = merge || jade.merge; | ||
var buf = []; | ||
with (locals || {}) { | ||
var interp; | ||
var __indent = []; | ||
buf.push('\n<li class="tweet">'); | ||
var __val__ = tweet; | ||
buf.push(escape(null == __val__ ? "" : __val__)); | ||
buf.push("</li>"); | ||
} | ||
return buf.join(""); | ||
}; | ||
// deeptweet.jade compiled template | ||
exports.otherfolder.deepnested.deeptweet = function anonymous(locals, attrs, escape, rethrow, merge) { | ||
attrs = attrs || jade.attrs; | ||
escape = escape || jade.escape; | ||
rethrow = rethrow || jade.rethrow; | ||
merge = merge || jade.merge; | ||
var buf = []; | ||
with (locals || {}) { | ||
var interp; | ||
var __indent = []; | ||
buf.push('\n<li class="tweet">'); | ||
var __val__ = tweet; | ||
buf.push(escape(null == __val__ ? "" : __val__)); | ||
buf.push("</li>"); | ||
} | ||
return buf.join(""); | ||
}; | ||
// attach to window or export with commonJS | ||
if (typeof exports !== "undefined") { | ||
@@ -47,0 +125,0 @@ module.exports = exports; |
{ | ||
"name": "templatizer", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -8,3 +8,7 @@ "description": "Simple solution for compiling jade templates into vanilla JS functions for blazin' fast client-side use.", | ||
"jade": "", | ||
"uglify-js": "" | ||
"uglify-js": "", | ||
"findit": "", | ||
"underscore": "", | ||
"colors": "", | ||
"yetify": "" | ||
}, | ||
@@ -11,0 +15,0 @@ "repository": { |
@@ -34,3 +34,4 @@ # templatizer.js | ||
app.jade | ||
otherTemplate.jade | ||
/myfolder | ||
nestedTemplate.jade | ||
``` | ||
@@ -52,2 +53,6 @@ | ||
// folders become nested objects so | ||
// myfolder/nestedTemplate.jade becomes | ||
exports.myfolder.nestedTemplate = function () {} // the template function | ||
// etc. etc | ||
@@ -58,2 +63,6 @@ ``` | ||
## Sample? | ||
Check out the `demo_output.js` file for... err... demo output built from the `templates` directory in this project. | ||
## License | ||
@@ -60,0 +69,0 @@ |
var jade = require('jade'), | ||
uglifyjs = require('uglify-js'), | ||
findit = require('findit'), | ||
path = require('path'), | ||
_ = require('underscore'), | ||
fs = require('fs'); | ||
@@ -13,3 +16,3 @@ | ||
// we var scope it so it doesn't create a global | ||
var jadeRuntime, output; | ||
var jadeRuntime, output, item, i, l, contents, folders = [], templates = []; | ||
@@ -22,2 +25,5 @@ try { | ||
contents = findit.sync(templateDirectory); | ||
output = [ | ||
@@ -32,23 +38,46 @@ '(function () {', | ||
// loop through all our templates | ||
fs.readdirSync(templateDirectory).forEach(function (file) { | ||
var split = file.split('.'), | ||
name = split[0], | ||
ext = split[1], | ||
template, | ||
filename = templateDirectory + '/' + file; | ||
if (ext === 'jade') { | ||
template = beautify(jade.compile(fs.readFileSync(filename), {client: true, compileDebug: false, pretty: true, filename: filename}).toString()); | ||
output += [ | ||
'', | ||
'// ' + file + ' compiled:', | ||
'exports.' + name + ' = ' + template + ';', | ||
'' | ||
].join('\n'); | ||
for (i = 0, l = contents.length; i < l; i++) { | ||
item = contents[i].replace(templateDirectory, '').slice(1); | ||
if (path.extname(item) === '') { | ||
folders.push(item); | ||
} else if (path.extname(item) === '.jade') { | ||
templates.push(item); | ||
} | ||
} | ||
folders = _.sortBy(folders, function (folder) { | ||
var arr = folder.split(path.sep); | ||
return arr.length; | ||
}); | ||
output += '\n// create our folder objects'; | ||
folders.forEach(function (folder) { | ||
var arr = folder.split(path.sep); | ||
output += '\nexports.' + arr.join('.') + ' = {};'; | ||
}); | ||
output += '\n'; | ||
templates.forEach(function (file) { | ||
var name = path.basename(file, '.jade'), | ||
dirString = function () { | ||
var dirname = path.dirname(file), | ||
arr = dirname.split(path.sep); | ||
if (dirname === '.') return name; | ||
arr.push(name); | ||
return arr.join('.'); | ||
}(), | ||
fullPath = templateDirectory + '/' + file, | ||
template = beautify(jade.compile(fs.readFileSync(fullPath), {client: true, compileDebug: false, pretty: true, filename: fullPath}).toString()); | ||
output += [ | ||
'', | ||
'// ' + name + '.jade compiled template', | ||
'exports.' + dirString + ' = ' + template + ';', | ||
'' | ||
].join('\n'); | ||
}); | ||
output += [ | ||
'\n', | ||
'// attach to windor or export with commonJS', | ||
'// attach to window or export with commonJS', | ||
'if (typeof exports !== "undefined") {', | ||
@@ -55,0 +84,0 @@ ' module.exports = exports;', |
@@ -13,3 +13,6 @@ var templatizer = require('./templatizer'), | ||
console.log(templates.users({users: ['larry', 'curly', 'moe']}).green + '\n'); | ||
console.log('4.'.grey + ' rendering a deeply nested template: otherfolder.deep2.deeptweet'); | ||
console.log(templates.otherfolder.deep2.deeptweet({tweet: 'hello, templatizer!'}).green + '\n'); | ||
console.log('templatizer.js'.bold + ' was with love by ' + yetify.logo() + ' for you!' + ' <3'.red + '\n'); |
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 4 instances in 1 package
30459
16
717
69
6
7
+ Addedcolors@
+ Addedfindit@
+ Addedunderscore@
+ Addedyetify@
+ Addedcolors@1.4.0(transitive)
+ Addedfindit@2.0.0(transitive)
+ Addedunderscore@1.13.7(transitive)
+ Addedyetify@0.1.0(transitive)