Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (query.extend) {
Twig.extend(query.extend);
}
if (typeof data === 'function') {
data = data(this);
if (typeof data !== 'object') {
this.emitError('data parameter should return an object');
}
}
const registry = [];
Twig.extend((Twig) => {
const defaultSave = Object.assign(Twig.Templates.save);
// eslint-disable-next-line no-param-reassign
Twig.Templates.save = function customSave(template) {
if (template.path) {
registry.push(path.normalize(template.path));
}
return defaultSave.call(this, template);
};
});
const template = Twig.twig(options);
const output = template.render(data);
registry.forEach(this.addDependency);
Twig.extend((Twig) => {
}
if (query.functions) {
Object.entries(query.functions).forEach(([name, fn]) => Twig.extendFunction(name, fn));
}
if (query.filters) {
Object.entries(query.filters).forEach(([name, fn]) => Twig.extendFilter(name, fn));
}
if (query.tests) {
Object.entries(query.tests).forEach(([name, fn]) => Twig.extendTest(name, fn));
}
if (query.extend) {
Twig.extend(query.extend);
}
if (typeof data === 'function') {
data = data(this);
if (typeof data !== 'object') {
this.emitError('data parameter should return an object');
}
}
const registry = [];
Twig.extend((Twig) => {
const defaultSave = Object.assign(Twig.Templates.save);
// eslint-disable-next-line no-param-reassign
Twig.Templates.save = function customSave(template) {
if (template.path) {
* not use source, but use path. so as to support base dir.
* 为了与后端保持一致,开启 base,开启绝对路径的使用
*/
const template = Twig.twig({
id: currentFilePath, // id is optional, but useful for referencing the template later
base: join(process.cwd(), 'src', 'views'),
// data: source,
// allowInlineIncludes: true,
async: false,
path: currentFilePath,
...others,
});
// 使用data参数时,base会被过滤掉
// template.base = join(process.cwd(), 'src', 'views');
// 去掉缓存
Twig.extend((T) => {
if (T.Templates && T.Templates.registry) {
T.Templates.registry = {}; // eslint-disable-line
}
});
// 异步调用
// 由于使用异步调用所有不能使用相对路径,需要使用绝对路径。
getMockData(currentFilePath, (mockData) => {
const output = template.render(mockData);
callback(null, output);
});
}
const defaultSave = Object.assign(Twig.Templates.save);
// eslint-disable-next-line no-param-reassign
Twig.Templates.save = function customSave(template) {
if (template.path) {
registry.push(path.normalize(template.path));
}
return defaultSave.call(this, template);
};
});
const template = Twig.twig(options);
const output = template.render(data);
registry.forEach(this.addDependency);
Twig.extend((Twig) => {
// eslint-disable-next-line no-param-reassign
Twig.Templates.registry = {};
});
return output;
} catch (e) {
this.callback(e);
return '';
}
};
(function compile(templateData) {
// store all the paths that need to be resolved
var resolveQueue = [];
var resolve = function (value) {
if (resolveQueue.indexOf(value) === -1 && !resolveMap[value]) {
resolveQueue.push(value);
}
};
Twig.extend(function (Twig) {
var compiler = Twig.compiler;
// pass values to the compiler, and return the compiler function
compiler.module['webpack'] = compilerFactory({
loaderApi: loaderApi,
resolve: resolve,
resolveMap: resolveMap,
path: path
});
});
tpl = Twig.twig({
id: id,
path: path,
data: templateData,
allowInlineIncludes: true
});
this.options.extensions.forEach(function(fn) {
Twig.extend(fn);
});
getTwigCache,
disableTwigCache
};
/**
* Holds a list with all registered component templates.
* Including registered overrides.
*
* @type {Map}
*/
const templateRegistry = new Map();
/**
* Extends the Twig core for compatibility.
*/
Twig.extend((TwigCore) => {
/**
* Remove tokens 2, 3, 4 and 8.
* This tokens are used for functions and data output.
* Since the data binding is done in Vue this could lead to syntax issues.
* We are only using the block system for template inheritance.
*
* @type {Array}
*/
TwigCore.token.definitions = [
TwigCore.token.definitions[0],
TwigCore.token.definitions[1],
TwigCore.token.definitions[5],
TwigCore.token.definitions[6],
TwigCore.token.definitions[7],
TwigCore.token.definitions[9],
TwigCore.token.definitions[10]
const fs = require('fs');
const Twig = require('twig');
const pretty = require('pretty');
Twig.extend((TwigCore) => {
/**
* Remove tokens 2, 3, 4 and 8.
* This tokens are used for functions and data output.
* Since the data binding is done in Vue this could lead to syntax issues.
* We are only using the block system for template inheritance.
*
* @type {Array}
*/
TwigCore.token.definitions = [
TwigCore.token.definitions[0],
TwigCore.token.definitions[1],
TwigCore.token.definitions[5],
TwigCore.token.definitions[6],
TwigCore.token.definitions[7],
TwigCore.token.definitions[9],
TwigCore.token.definitions[10]
}
if (options.functions) {
options.functions.forEach(function (func) {
Twig.extendFunction(func.name, func.func);
});
}
if (options.filters) {
options.filters.forEach(function (filter) {
Twig.extendFilter(filter.name, filter.func);
});
}
if(options.extend) {
Twig.extend(options.extend);
delete options.extend;
}
if (options.useFileContents) {
var fileContents = file.contents.toString();
twigOpts.data = fileContents
}
template = twig(twigOpts);
try {
file.contents = new Buffer(template.render(data));
}catch(e){
if (options.errorLogToConsole) {
gutil.log(PLUGIN_NAME + ' ' + e);
return cb();