mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Use a state object for buildTemplate like buildModule.
Former-commit-id: 850fe162a0a80b5547622f6cc267e66cad3ae4ce
This commit is contained in:
24
build.js
24
build.js
@@ -1020,16 +1020,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles template files matched by the given file path `pattern` into a
|
* Compiles template files based on the provided build state using the single
|
||||||
* single source, extending `_.templates` with precompiled templates named after
|
* source, extending `_.templates` with precompiled templates named after
|
||||||
* each template file's basename.
|
* each template file's basename.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {String} [pattern='<cwd>/*.jst'] The file path pattern.
|
* @param {Object} state The build state object.
|
||||||
* @param {Object} options The template options object.
|
|
||||||
* @returns {String} Returns the compiled source.
|
* @returns {String} Returns the compiled source.
|
||||||
*/
|
*/
|
||||||
function buildTemplate(pattern, options) {
|
function buildTemplate(state) {
|
||||||
|
var pattern = state.templatePattern,
|
||||||
|
settings = state.templateSettings,
|
||||||
|
moduleId = settings.moduleId;
|
||||||
|
|
||||||
pattern || (pattern = path.join(cwd, '*.jst'));
|
pattern || (pattern = path.join(cwd, '*.jst'));
|
||||||
|
|
||||||
var directory = fs.realpathSync(path.dirname(pattern));
|
var directory = fs.realpathSync(path.dirname(pattern));
|
||||||
@@ -1070,7 +1073,7 @@
|
|||||||
}
|
}
|
||||||
var filePath = path.join(directory, filename),
|
var filePath = path.join(directory, filename),
|
||||||
text = fs.readFileSync(filePath, 'utf8'),
|
text = fs.readFileSync(filePath, 'utf8'),
|
||||||
precompiled = cleanupCompiled(getFunctionSource(_.template(text, null, options), 2)),
|
precompiled = cleanupCompiled(getFunctionSource(_.template(text, null, settings), 2)),
|
||||||
prop = filename.replace(/\..*$/, '');
|
prop = filename.replace(/\..*$/, '');
|
||||||
|
|
||||||
source.push(" templates['" + prop.replace(/['\n\r\t]/g, '\\$&') + "'] = " + precompiled + ';', '');
|
source.push(" templates['" + prop.replace(/['\n\r\t]/g, '\\$&') + "'] = " + precompiled + ';', '');
|
||||||
@@ -1078,12 +1081,12 @@
|
|||||||
|
|
||||||
source.push(
|
source.push(
|
||||||
" if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {",
|
" if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {",
|
||||||
" define(['" + options.moduleId + "'], function(lodash) {",
|
" define(['" + moduleId + "'], function(lodash) {",
|
||||||
' _ = lodash;',
|
' _ = lodash;',
|
||||||
' lodash.templates = lodash.extend(lodash.templates || {}, templates);',
|
' lodash.templates = lodash.extend(lodash.templates || {}, templates);',
|
||||||
' });',
|
' });',
|
||||||
" } else if (freeExports && !freeExports.nodeType) {",
|
" } else if (freeExports && !freeExports.nodeType) {",
|
||||||
" _ = require('" + options.moduleId + "');",
|
" _ = require('" + moduleId + "');",
|
||||||
" if (freeModule) {",
|
" if (freeModule) {",
|
||||||
' (freeModule.exports = templates).templates = templates;',
|
' (freeModule.exports = templates).templates = templates;',
|
||||||
' } else {',
|
' } else {',
|
||||||
@@ -3941,7 +3944,10 @@
|
|||||||
/*----------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------*/
|
||||||
|
|
||||||
if (isTemplate) {
|
if (isTemplate) {
|
||||||
source = buildTemplate(templatePattern, templateSettings);
|
source = buildTemplate({
|
||||||
|
'templatePattern': templatePattern,
|
||||||
|
'templateSettings': templateSettings
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
source = removeFromCreateIterator(source, 'support');
|
source = removeFromCreateIterator(source, 'support');
|
||||||
|
|||||||
Reference in New Issue
Block a user