templates
Advanced tools
Comparing version 0.4.4 to 0.4.5
18
index.js
@@ -75,3 +75,3 @@ /*! | ||
Templates.prototype.defaultConfig = function () { | ||
Templates.prototype.defaultConfig = function() { | ||
this.is('App'); | ||
@@ -112,3 +112,3 @@ this.plugins = []; | ||
Templates.prototype.expose = function (name) { | ||
Templates.prototype.expose = function(name) { | ||
this.define(name, this.options[name] || lib[name.toLowerCase()]); | ||
@@ -121,4 +121,4 @@ }; | ||
Templates.prototype.listen = function (app) { | ||
this.on('option', function (key, value) { | ||
Templates.prototype.listen = function(app) { | ||
this.on('option', function(key, value) { | ||
if (key === 'mixins') { | ||
@@ -130,3 +130,3 @@ app.visit('mixin', value); | ||
this.on('error', function (err) { | ||
this.on('error', function(err) { | ||
if (!err || err.id !== 'rethrow') return; | ||
@@ -156,3 +156,3 @@ if (app.options.silent !== true) { | ||
Templates.prototype.list = function (opts) { | ||
Templates.prototype.list = function(opts) { | ||
opts = opts || {}; | ||
@@ -169,3 +169,2 @@ | ||
list = opts; | ||
} else { | ||
@@ -198,3 +197,3 @@ opts.Item = opts.Item || opts.View || this.get('Item'); | ||
Templates.prototype.collection = function (opts, created) { | ||
Templates.prototype.collection = function(opts, created) { | ||
opts = opts || {}; | ||
@@ -211,3 +210,2 @@ | ||
collection = opts; | ||
} else { | ||
@@ -298,3 +296,3 @@ opts.Item = opts.Item || opts.View || this.get('View'); | ||
Templates.prototype.extendView = function (view, options) { | ||
Templates.prototype.extendView = function(view, options) { | ||
proto.view.all(this, view, options); | ||
@@ -301,0 +299,0 @@ return this; |
@@ -30,3 +30,3 @@ 'use strict'; | ||
Cache.prototype.file = function (filepath) { | ||
Cache.prototype.file = function(filepath) { | ||
return new File(filepath); | ||
@@ -42,3 +42,3 @@ }; | ||
Cache.prototype.set = function (filepath) { | ||
Cache.prototype.set = function(filepath) { | ||
this.files[filepath] = (this.files[filepath] || this.file(filepath)); | ||
@@ -55,3 +55,3 @@ return this; | ||
Cache.prototype.get = function (filepath) { | ||
Cache.prototype.get = function(filepath) { | ||
return this.files[filepath]; | ||
@@ -62,3 +62,3 @@ }; | ||
this.path = filepath; | ||
this.read = function (force) { | ||
this.read = function(force) { | ||
if (!this.contents || force) { | ||
@@ -70,3 +70,3 @@ console.log('reading contents'); | ||
define(this, 'stat', { | ||
get: function () { | ||
get: function() { | ||
if (!this._stat) { | ||
@@ -73,0 +73,0 @@ console.log('getting stats'); |
@@ -5,3 +5,3 @@ 'use strict'; | ||
module.exports = function (app, collection, options) { | ||
module.exports = function(app, collection, options) { | ||
@@ -8,0 +8,0 @@ /** |
@@ -5,3 +5,3 @@ 'use strict'; | ||
module.exports = function (app, collection, options) { | ||
module.exports = function(app, collection, options) { | ||
// if `options` is an instance of `view`, get `view.options` | ||
@@ -26,3 +26,3 @@ if (options.hasOwnProperty('options')) { | ||
app.helper('view', function (name, type) { | ||
app.helper('view', function(name, type) { | ||
var last = utils.last(arguments); | ||
@@ -76,3 +76,3 @@ if (utils.isOptions(last)) { | ||
return this.app.render(view, ctx, function (err, res) { | ||
return this.app.render(view, ctx, function(err, res) { | ||
if (err) return cb(err); | ||
@@ -79,0 +79,0 @@ |
@@ -45,6 +45,6 @@ 'use strict'; | ||
enumerable: false, | ||
get: function () { | ||
get: function() { | ||
return this._contents; | ||
}, | ||
set: function (val) { | ||
set: function(val) { | ||
utils.syncContents(this, val); | ||
@@ -86,3 +86,3 @@ } | ||
Item.prototype.clone = function (opts) { | ||
Item.prototype.clone = function(opts) { | ||
opts = opts || {}; | ||
@@ -127,3 +127,3 @@ | ||
Item.prototype.inspect = function () { | ||
Item.prototype.inspect = function() { | ||
var name = this._name || 'Item'; | ||
@@ -130,0 +130,0 @@ var inspect = []; |
@@ -10,3 +10,3 @@ 'use strict'; | ||
module.exports = function (app) { | ||
module.exports = function(app) { | ||
@@ -41,3 +41,3 @@ /** | ||
app.dataLoader('json', function (str) { | ||
app.dataLoader('json', function(str) { | ||
return JSON.parse(str); | ||
@@ -55,3 +55,3 @@ }); | ||
app.mixin('context', function (view, ctx, locals) { | ||
app.mixin('context', function(view, ctx, locals) { | ||
var obj = {}; | ||
@@ -70,3 +70,3 @@ utils.extend(obj, ctx); | ||
app.mixin('bindHelpers', function (view, locals, context, isAsync) { | ||
app.mixin('bindHelpers', function(view, locals, context, isAsync) { | ||
if (context.isBound) return; | ||
@@ -116,3 +116,3 @@ | ||
app.mixin('mergePartials', function (options) { | ||
app.mixin('mergePartials', function(options) { | ||
var opts = utils.extend({}, this.options, options); | ||
@@ -123,3 +123,3 @@ var names = opts.mergeTypes || this.viewTypes.partial; | ||
names.forEach(function (name) { | ||
names.forEach(function(name) { | ||
var collection = self.views[name]; | ||
@@ -126,0 +126,0 @@ for (var key in collection) { |
@@ -9,3 +9,3 @@ 'use strict'; | ||
module.exports = function (proto) { | ||
module.exports = function(proto) { | ||
@@ -40,3 +40,3 @@ /** | ||
} | ||
utils.arrayify(exts).forEach(function (ext) { | ||
utils.arrayify(exts).forEach(function(ext) { | ||
this.setEngine(ext, fn, settings); | ||
@@ -43,0 +43,0 @@ }.bind(this)); |
@@ -5,3 +5,3 @@ 'use strict'; | ||
module.exports = function (proto, name) { | ||
module.exports = function(proto, name) { | ||
@@ -8,0 +8,0 @@ /** |
@@ -5,3 +5,3 @@ 'use strict'; | ||
module.exports = function (app) { | ||
module.exports = function(app) { | ||
app.cache = {}; | ||
@@ -8,0 +8,0 @@ app.cache.data = {}; |
@@ -5,3 +5,3 @@ 'use strict'; | ||
module.exports = function (proto) { | ||
module.exports = function(proto) { | ||
@@ -26,3 +26,3 @@ /** | ||
proto.find = function (name, collection) { | ||
proto.find = function(name, collection) { | ||
if (typeof name !== 'string') { | ||
@@ -29,0 +29,0 @@ throw new TypeError('expected name to be a string.'); |
@@ -9,3 +9,3 @@ 'use strict'; | ||
module.exports = function () { | ||
module.exports = function() { | ||
return function(app) { | ||
@@ -12,0 +12,0 @@ app.define('renameKey', function renameKey(key, fn) { |
@@ -5,3 +5,3 @@ 'use strict'; | ||
module.exports = function (proto) { | ||
module.exports = function(proto) { | ||
@@ -123,3 +123,3 @@ /** | ||
proto.render = function (view, locals, cb) { | ||
proto.render = function(view, locals, cb) { | ||
if (typeof locals === 'function') { | ||
@@ -179,3 +179,3 @@ cb = locals; | ||
// render the view | ||
return engine.render(view.fn, context, function (err, res) { | ||
return engine.render(view.fn, context, function(err, res) { | ||
if (err) { | ||
@@ -182,0 +182,0 @@ // rethrow is a noop if `options.rethrow` is not true |
@@ -5,3 +5,3 @@ 'use strict'; | ||
module.exports = function (proto) { | ||
module.exports = function(proto) { | ||
@@ -45,3 +45,3 @@ /** | ||
proto.handle = function (method, view, locals, cb) { | ||
proto.handle = function(method, view, locals, cb) { | ||
if (typeof locals === 'function') { | ||
@@ -77,3 +77,3 @@ cb = locals; | ||
proto.handleView = function (method, view, locals/*, cb*/) { | ||
proto.handleView = function(method, view, locals/*, cb*/) { | ||
if (!view.options.handled) { | ||
@@ -96,3 +96,3 @@ view.options.handled = []; | ||
var app = this; | ||
return function (err) { | ||
return function(err) { | ||
if (err) { | ||
@@ -166,3 +166,3 @@ if (err._handled) return cb(); | ||
* ```js | ||
* app.param('title', function (view, next, title) { | ||
* app.param('title', function(view, next, title) { | ||
* //=> title === 'foo.js' | ||
@@ -172,3 +172,3 @@ * next(); | ||
* | ||
* app.onLoad('/blog/:title', function (view, next) { | ||
* app.onLoad('/blog/:title', function(view, next) { | ||
* //=> view.path === '/blog/foo.js' | ||
@@ -197,3 +197,3 @@ * next(); | ||
proto.handler = function (methods) { | ||
proto.handler = function(methods) { | ||
this.handlers(methods); | ||
@@ -206,6 +206,6 @@ }; | ||
proto.handlers = function (methods) { | ||
proto.handlers = function(methods) { | ||
this.lazyRouter(methods); | ||
utils.arrayify(methods).forEach(function (method) { | ||
utils.arrayify(methods).forEach(function(method) { | ||
this.define(method, function(path) { | ||
@@ -221,3 +221,3 @@ var route = this.route(path); | ||
// Add router methods to Templates | ||
utils.methods.forEach(function (method) { | ||
utils.methods.forEach(function(method) { | ||
proto[method] = function(path) { | ||
@@ -224,0 +224,0 @@ var route = this.route(path); |
@@ -12,3 +12,3 @@ 'use strict'; | ||
// decorate `option` method onto `view` | ||
exports.option = function (app, view, options) { | ||
exports.option = function(app, view, options) { | ||
if (typeof view.option !== 'function') { | ||
@@ -21,4 +21,4 @@ utils.option.call(view, view); | ||
// decorate `compile` method onto `view` | ||
exports.compile = function (app, view) { | ||
view.compile = function () { | ||
exports.compile = function(app, view) { | ||
view.compile = function() { | ||
var args = [this].concat([].slice.call(arguments)); | ||
@@ -31,4 +31,4 @@ app.compile.apply(app, args); | ||
// decorate `render` method onto `view` | ||
exports.render = function (app, view) { | ||
view.render = function () { | ||
exports.render = function(app, view) { | ||
view.render = function() { | ||
var args = [this].concat([].slice.call(arguments)); | ||
@@ -41,4 +41,4 @@ app.render.apply(app, args); | ||
// decorate `context` method onto `view` | ||
exports.context = function (app, view) { | ||
view.context = function (locals) { | ||
exports.context = function(app, view) { | ||
view.context = function(locals) { | ||
return utils.extend({}, this.locals, this.data, locals); | ||
@@ -49,3 +49,3 @@ }; | ||
exports.all = function (app, view, options) { | ||
exports.all = function(app, view, options) { | ||
if (!view.isItem && !view.isView) { | ||
@@ -52,0 +52,0 @@ for (var key in Base.prototype) { |
@@ -17,3 +17,3 @@ 'use strict'; | ||
views.on('view', function (view) { | ||
views.on('view', function(view) { | ||
utils.define(view, 'addView', views.addView.bind(views)); | ||
@@ -20,0 +20,0 @@ if (!view.options.hasOwnProperty('engine')) { |
@@ -54,3 +54,3 @@ 'use strict'; | ||
View.prototype.compile = function (settings) { | ||
View.prototype.compile = function(settings) { | ||
this.fn = utils.engine.compile(this.content, settings); | ||
@@ -73,3 +73,3 @@ return this; | ||
View.prototype.render = function (locals, cb) { | ||
View.prototype.render = function(locals, cb) { | ||
if (typeof locals === 'function') return this.render({}, locals); | ||
@@ -88,3 +88,3 @@ if (typeof this.fn !== 'function') this.compile(locals); | ||
utils.engine.render(this.fn, context, function (err, res) { | ||
utils.engine.render(this.fn, context, function(err, res) { | ||
if (err) return cb(err); | ||
@@ -102,8 +102,8 @@ this.contents = new Buffer(res); | ||
utils.define(View.prototype, 'layout', { | ||
set: function (val) { | ||
set: function(val) { | ||
this.define('_layout', val); | ||
}, | ||
get: function () { | ||
get: function() { | ||
return this._layout || utils.resolveLayout(this); | ||
} | ||
}); |
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
@@ -220,6 +221,17 @@ var plugin = require('./plugins'); | ||
var cwd = this.options.cwd || process.cwd(); | ||
return this.views[key] | ||
var view = this.views[key] | ||
|| this.views[this.renameKey(key)] | ||
|| this.views[path.resolve(cwd, key)] | ||
|| this.views[path.relative(cwd, key)]; | ||
if (!view) { | ||
var fp = path.join(cwd, key); | ||
if (fs.existsSync(fp)) { | ||
var str = fs.readFileSync(fp); | ||
this.addView(key, { contents: str }); | ||
return this.getView(key); | ||
} | ||
return null; | ||
} | ||
return view; | ||
}; | ||
@@ -226,0 +238,0 @@ |
{ | ||
"name": "templates", | ||
"description": "System for creating and managing template collections, and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator or blog framework.", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"homepage": "https://github.com/jonschlinkert/templates", | ||
@@ -16,3 +16,2 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
], | ||
"main": "index.js", | ||
"engines": { | ||
@@ -61,7 +60,6 @@ "node": ">=0.10.0" | ||
"gulp": "^3.9.0", | ||
"gulp-eslint": "^1.0.0", | ||
"gulp-istanbul": "^0.10.0", | ||
"gulp-jshint": "^1.11.2", | ||
"gulp-mocha": "^2.1.3", | ||
"istanbul": "^0.3.22", | ||
"jshint-stylish": "^2.0.1", | ||
"kind-of": "^2.0.1", | ||
@@ -68,0 +66,0 @@ "load-pkg": "^1.3.0", |
108201
22
2911
4