pug
Advanced tools
Comparing version 2.0.0-beta2 to 2.0.0-beta3
@@ -37,3 +37,2 @@ 'use strict'; | ||
function applyPlugins(value, options, plugins, name) { | ||
@@ -48,2 +47,17 @@ return plugins.reduce(function (value, plugin) { | ||
} | ||
function findReplacementFunc(plugins, name) { | ||
var eligiblePlugins = plugins.filter(function (plugin) { | ||
return plugin[name]; | ||
}); | ||
if (eligiblePlugins.length > 1) { | ||
throw new Error('Two or more plugins all implement ' + name + ' method.'); | ||
} else if (eligiblePlugins.length) { | ||
return eligiblePlugins[0][name]; | ||
} else { | ||
return null; | ||
} | ||
} | ||
/** | ||
@@ -113,5 +127,23 @@ * Object for global custom filters. Note that you can also just pass a `filters` | ||
}, | ||
read: function (filename) { | ||
resolve: function (filename, source, loadOptions) { | ||
var replacementFunc = findReplacementFunc(plugins, 'resolve'); | ||
if (replacementFunc) { | ||
return replacementFunc(filename, source, options); | ||
} | ||
return load.resolve(filename, source, loadOptions); | ||
}, | ||
read: function (filename, loadOptions) { | ||
dependencies.push(filename); | ||
var str = applyPlugins(fs.readFileSync(filename, 'utf8'), {filename: filename}, plugins, 'preLex'); | ||
var contents; | ||
var replacementFunc = findReplacementFunc(plugins, 'read'); | ||
if (replacementFunc) { | ||
contents = replacementFunc(filename, options); | ||
} else { | ||
contents = load.read(filename, loadOptions); | ||
} | ||
var str = applyPlugins(contents, {filename: filename}, plugins, 'preLex'); | ||
debug_sources[filename] = str; | ||
@@ -118,0 +150,0 @@ return str; |
{ | ||
"name": "pug", | ||
"description": "A clean, whitespace-sensitive template language for writing HTML", | ||
"version": "2.0.0-beta2", | ||
"version": "2.0.0-beta3", | ||
"author": "TJ Holowaychuk <tj@vision-media.ca>", | ||
@@ -6,0 +6,0 @@ "maintainers": [ |
90269
463