pug
Advanced tools
Comparing version 2.0.0-alpha7 to 2.0.0-alpha8
@@ -37,2 +37,12 @@ 'use strict'; | ||
function applyPlugins(value, options, plugins, name) { | ||
return plugins.reduce(function (value, plugin) { | ||
return ( | ||
plugin[name] | ||
? plugin[name](value, options) | ||
: value | ||
); | ||
}, value); | ||
} | ||
/** | ||
@@ -51,5 +61,19 @@ * Compile the given `str` of pug and return a function body. | ||
var dependencies = []; | ||
var ast = load.string(str, options.filename, { | ||
lex: lex, | ||
parse: function (tokens, filename) { | ||
var plugins = options.plugins || []; | ||
var ast = load.string(str, { | ||
filename: options.filename, | ||
basedir: options.basedir, | ||
lex: function (str, options) { | ||
var lexOptions = {}; | ||
Object.keys(options).forEach(function (key) { | ||
lexOptions[key] = options[key]; | ||
}); | ||
lexOptions.plugins = plugins.filter(function (plugin) { | ||
return !!plugin.lex; | ||
}).map(function (plugin) { | ||
return plugin.lex; | ||
}); | ||
return applyPlugins(lex(str, lexOptions), options, plugins, 'postLex'); | ||
}, | ||
parse: function (tokens, options) { | ||
tokens = tokens.map(function (token) { | ||
@@ -66,17 +90,36 @@ if (token.type === 'path' && path.extname(token.val) === '') { | ||
}); | ||
tokens = stripComments(tokens, { filename: filename }); | ||
return parse(tokens, filename); | ||
tokens = stripComments(tokens, options); | ||
tokens = applyPlugins(tokens, options, plugins, 'preParse'); | ||
var parseOptions = {}; | ||
Object.keys(options).forEach(function (key) { | ||
parseOptions[key] = options[key]; | ||
}); | ||
parseOptions.plugins = plugins.filter(function (plugin) { | ||
return !!plugin.parse; | ||
}).map(function (plugin) { | ||
return plugin.parse; | ||
}); | ||
return applyPlugins( | ||
applyPlugins(parse(tokens, parseOptions), options, plugins, 'postParse'), | ||
options, plugins, 'preLoad' | ||
); | ||
}, | ||
read: function (filename) { | ||
dependencies.push(filename); | ||
var str = fs.readFileSync(filename, 'utf8'); | ||
var str = applyPlugins(fs.readFileSync(filename, 'utf8'), {filename: filename}, plugins, 'preLex'); | ||
debug_sources[filename] = str; | ||
return str; | ||
}, | ||
basedir: options.basedir | ||
} | ||
}); | ||
ast = applyPlugins(ast, options, plugins, 'postLoad'); | ||
ast = applyPlugins(ast, options, plugins, 'preFilters'); | ||
ast = filters.handleFilters(ast, options.filters, options.filterOptions); | ||
ast = applyPlugins(ast, options, plugins, 'postFilters'); | ||
ast = applyPlugins(ast, options, plugins, 'preLink'); | ||
ast = link(ast); | ||
ast = applyPlugins(ast, options, plugins, 'postLink'); | ||
// Compile | ||
ast = applyPlugins(ast, options, plugins, 'preCodeGen'); | ||
var js = generateCode(ast, { | ||
@@ -92,2 +135,3 @@ pretty: options.pretty, | ||
}); | ||
js = applyPlugins(js, options, plugins, 'postCodeGen'); | ||
@@ -162,3 +206,4 @@ // Debug compiler | ||
filters: options.filters, | ||
filterOptions: options.filterOptions | ||
filterOptions: options.filterOptions, | ||
plugins: options.plugins, | ||
}); | ||
@@ -208,3 +253,4 @@ | ||
filters: options.filters, | ||
filterOptions: options.filterOptions | ||
filterOptions: options.filterOptions, | ||
plugins: options.plugins, | ||
}); | ||
@@ -211,0 +257,0 @@ |
{ | ||
"name": "pug", | ||
"description": "A clean, whitespace-sensitive template language for writing HTML", | ||
"version": "2.0.0-alpha7", | ||
"version": "2.0.0-alpha8", | ||
"author": "TJ Holowaychuk <tj@vision-media.ca>", | ||
@@ -25,6 +25,6 @@ "maintainers": [ | ||
"pug-filters": "^1.2.1", | ||
"pug-lexer": "^1.0.1", | ||
"pug-lexer": "^2.0.0", | ||
"pug-linker": "0.0.4", | ||
"pug-load": "^1.0.3", | ||
"pug-parser": "^1.0.0", | ||
"pug-load": "^2.0.0", | ||
"pug-parser": "^2.0.0", | ||
"pug-runtime": "^2.0.1", | ||
@@ -31,0 +31,0 @@ "pug-strip-comments": "0.0.1" |
88175
423
+ Addedis-expression@3.0.0(transitive)
+ Addedpug-lexer@2.3.2(transitive)
+ Addedpug-load@2.0.12(transitive)
+ Addedpug-parser@2.0.2(transitive)
- Removedis-expression@2.1.0(transitive)
- Removedpug-lexer@1.2.0(transitive)
- Removedpug-load@1.0.3(transitive)
- Removedpug-parser@1.0.0(transitive)
Updatedpug-lexer@^2.0.0
Updatedpug-load@^2.0.0
Updatedpug-parser@^2.0.0