templates
Advanced tools
Comparing version 0.9.6 to 0.10.0
@@ -49,3 +49,3 @@ 'use strict'; | ||
utils.isBuffer = function (val) { | ||
utils.isBuffer = function(val) { | ||
if (val && val.constructor && typeof val.constructor.isBuffer === 'function') { | ||
@@ -52,0 +52,0 @@ return val.constructor.isBuffer(val); |
'use strict'; | ||
var path = require('path'); | ||
var common = require('./common'); | ||
@@ -5,0 +4,0 @@ var lazy = require('./lazy'); |
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var plugin = require('./plugins'); | ||
@@ -227,3 +225,7 @@ var utils = require('./utils'); | ||
Views.prototype.getView = function(key, options, fn) { | ||
Views.prototype.getView = function(name, options, fn) { | ||
if (typeof name !== 'string') { | ||
throw new TypeError('expected a string'); | ||
} | ||
if (typeof options === 'function') { | ||
@@ -234,44 +236,39 @@ fn = options; | ||
var opts = utils.extend({}, this.options, options); | ||
var cwd = opts.cwd || process.cwd(); | ||
if (typeof fn === 'function') { | ||
key = fn(key); | ||
name = fn.call(this, name, {}); | ||
} | ||
var view = this.views[key] | ||
|| this.views[this.renameKey(key)] | ||
|| this.views[path.resolve(cwd, key)] | ||
|| this.views[path.relative(cwd, key)]; | ||
var view = this.views[name] || this.views[this.renameKey(name)]; | ||
if (view) return view; | ||
// TODO: move this code into plugin for matching or lookups | ||
var fp = path.join(cwd, key); | ||
if (fs.existsSync(fp)) { | ||
var str = fs.readFileSync(fp); | ||
view = this.setView(key, { | ||
options: utils.extend({}, opts, {renameKey: false}), | ||
key: key, | ||
contents: str | ||
}); | ||
if (view) return view; | ||
for (var key in this.views) { | ||
if (isMatch(name, this.views[key])) { | ||
return this.views[key]; | ||
} | ||
} | ||
this.__exts__ = this.__exts__ || {}; | ||
var ext = path.extname(fp); | ||
if (!ext) ext = opts.engine; | ||
if (!ext) return null; | ||
if (ext.charAt(0) !== '.') { | ||
ext = '.' + ext; | ||
function isMatch(key, view) { | ||
if (key === view.path) return true; | ||
if (key === view.stem) return true; | ||
if (key === view.basename) return true; | ||
if (key === view.relative) return true; | ||
if (key === view.key) return true; | ||
return false; | ||
} | ||
return ''; | ||
}; | ||
if (this.__exts__[ext]) { | ||
return null; | ||
} | ||
/** | ||
* Load a view from the file system. | ||
* | ||
* ```js | ||
* collection.loadView(view); | ||
* ``` | ||
* @param {Object} `view` | ||
* @return {Object} | ||
* @api public | ||
*/ | ||
this.__exts__[ext] = true; | ||
return this.getView(key + ext); | ||
Views.prototype.extendView = function(view) { | ||
return plugin.view.all(this, view); | ||
}; | ||
@@ -278,0 +275,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.9.6", | ||
"version": "0.10.0", | ||
"homepage": "https://github.com/jonschlinkert/templates", | ||
@@ -6,0 +6,0 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
118087
1249
2
3130