function compile(id, str) { var minified = minify(str, minifyDefaults), template, tokens; id = (id+'').replace(/[^a-zA-Z]/g, ''); // check if template already exists template = twig({ ref: id }); if (!template) { template = twig({ id: id, data: minified }); } tokens = JSON.stringify(template.tokens); // the id will be the filename and path relative to the require()ing module return 'function(data) {'+ ' var template = twig({'+ ' data:' + tokens + ','+ ' precompiled: true,'+ ' allowInlineIncludes: true'+ ' });'+ ' var fragment = autoElemsFromDom(' + ' template.render(data),' + ' \'attr\',' + ' \'data-dootify\',' + ' true' + ' );'+ ' return fragment;'+ '}'; }
exports.get = function(message, data) { var fileTemplate = fs.readFileSync(path.join(__dirname, '/messages', message + '.twig'), 'utf8'); var msgTemplate = Twig.twig({ data : fileTemplate }); return msgTemplate.render(data); };
function compile(id, str) { var template = twig({ ref: id }); var minified = minifyTwig(str.toString()); if (!template) { template = twig({ id: id, data: minified }); } var tokens = JSON.stringify(template.tokens); // the id will be the filename and path relative to the require()ing module return 'twig({ id: "' + getRefName(id) + '", data:' + tokens + ', precompiled: true, allowInlineIncludes: true })'; }
it('should create twig filters from chalk styles', function() { attachFilters(Twig); var template = Twig.twig({ data: '{{ text | red | underline | bold }}' }); var output = template.render({text: 'foo'}); output.should.equal(chalk.red.underline.bold('foo')); });
it('should not error if no content is present in message', function() { attachFilters(Twig); var template = Twig.twig({ data: '{{ text | red | underline | bold }}' }); var output = template.render({text: null}); output.should.equal(chalk.red.underline.bold('')); });
/** * run * @param {String} templateFile [] * @param {Object} tVar [] * @param {Object} config [] * @return {Promise} [] */ async run(templateFile, tVar, config) { let options = this.parseConfig(config); this.prerender(options, Twig, templateFile); let content = await this.getContent(templateFile); return twig({data: content}).render(tVar); }
getTemplate() { const absolutePath = process.cwd() + this.templatePath; const templateData = fs.readFileSync(absolutePath).toString(); return twig({ data: templateData, namespaces: { bbug: 'templates/' }, }); }
function loadTwigTemplate(templateName) { if(!templateName) return null; var twigPath = path.join(config.get('template_path'), templateName); return twig({ path: twigPath, async: false }); }
function(callback){ /////////////////////////////// // Routes and templates //////////////////////////////// app.get('/connect', controllers.indexController().connectAction); highscoresTemplate = twig({ id:'highscores', path: __dirname + '/lib/server/views/highscores.html.twig' }); badgeTemplate = twig({ id:'badge', path: __dirname + '/lib/server/views/badge.html.twig' }); process.nextTick(function() {callback(null)}); }
outputBlocks: function(data, outputFile) { var template = Twig.twig({ path: this.options.templateFile || path.join(__dirname, 'styleguide.twig'), async: false }); grunt.file.write(outputFile, template.render(data)); //console.log( JSON.stringify(blocks, null, 2) ); }
it('should use template compiler', function() { var write = jasmine.createSpyObj('write', ['asModule']), template = Twig.twig({ id: 'raw_template', data: '{{ value }}' }); template.compile = function() { return 'compiled_template'; }; twigjs.write('twigjs', 'raw_template', write); expect(write.asModule).toHaveBeenCalledWith('twigjs!raw_template', 'compiled_template'); });
return new Promise((resolve) => { const handle = `@${Path.parse(tplPath).name.replace(/^_/, '').replace(/^\d\d\-/, '')}`; const template = Twig.twig({ method: this._partials[handle] ? 'fractal' : undefined, name: this._partials[handle] ? `@${Path.parse(tplPath).name.replace(/^_/, '').replace(/^\d\d\-/, '')}` : undefined, path: this._partials[handle] ? undefined : tplPath, allowInlineIncludes: true, async: false }); const html = template.render(context); resolve(html); });
GruntTwigRender.prototype.render = function(data, dataPath, template, dest, flatten) { var i, len; //loop vars var actualData = this._getData(data, dataPath); var replacer = function(match, filename, extension) { return filename+"_"+i+extension; }; if(actualData) { if(isArray(actualData.dataPath)) { var pathArray = actualData.dataPath; // flatten as needed if(flatten) { pathArray = []; for (i = 0, len = actualData.dataPath.length; i < len; i++){ var elt = actualData.dataPath[i]; if(elt[flatten]) { pathArray = pathArray.concat(elt[flatten]); } else { pathArray.push(elt); } } } for (i = 0, len = pathArray.length; i < len; i++) { var tt = Twig.twig({path: template, async: false}); // compute destination path by inserting '_n' var destPath = dest.replace(/(.*)(\.[^\.]+)$/, replacer); actualData.dataPath = pathArray[i]; grunt.file.write(destPath, tt.render(actualData)); } actualData.dataPath = pathArray; } else { var twigTemplate = Twig.twig({ path: template, async: false }); grunt.file.write(dest, twigTemplate.render(actualData)); } } };
function generate(options) { var tS = this.template || "{{institution}}:{{prefix|wide(4)}}{{controll}}{{sequence|wide(-9)}}{{sufix}}-{{GLNumber}}.{{currency|upper}}"; var tmpl = twig.twig({data: tS}); return tmpl.render({ prefix: this.prefix, sufix: this.sufix, institution: this.institutionCode, owner: options.owner && options.owner.code, GLNumber: this.GLNumber, currency: this.currency, sequence: this.sequence, controll: buildConrtoll(this.prefix, this.sequence, this.sufix) }); };
}).map(function(filepath) { // Read file source and run it through Twig's almost-compiler, which // produces an object that can be used to render the template. var source = grunt.file.read(filepath); try { return options.each_template.render({ variable: options.variable, filepath: options.template_key(filepath), compiled: JSON.stringify(Twig.twig({ data: source }).tokens), }); } catch (e) { grunt.log.warn(e); } }).join(grunt.util.normalizelf(options.separator));
module.exports.format = function stringStream(format, options) { chalkTwig(Twig, options); var template = Twig.twig({ data: format, }); var processor = function(data, enc, cb) { if (typeof data === 'object') { data = template.render(data); } cb(null, data + os.EOL); }; return through2.obj(processor); };
parse = function( name, _path, content, flags ) { var widget = false; if( isAsset( name ) || ( widget = isWidget( name ) ) ) flags = und.extend( { 'template' : widget ? template( name, _path ) : '' }, flags, packageJSON( name, _path ) ); try { content = Twig.twig({ data : content }).render( flags || {} ) } catch( ex ) { console.log( ex ); grunt.log.error( ex ); } return content; };
function twigCompile(data) { var template = Twig.twig({ data: data.text, path: data.path }); return function(locals) { var context = {}; Object.keys(locals).forEach(function(key) { var value = locals[key]; if ('function' === typeof value) { Twig.extendFunction(key, value); } else { context[key] = value; } }); return template.render(context); } }
redisClient.zrevrange('plan9_highscores','0','9', 'withscores', function(err, highscores) { logger.debug('Getting highscores by zrevrange: ' + err); logger.debug('Getting highscores by zrevrange: ' + highscores); if (!err && highscores) { logger.debug('Highscore is filled: ' + highscores); var parsedHighscores = []; for (var highscoreIndex in highscores) { if (highscores.hasOwnProperty(highscoreIndex)) { try { logger.debug('PARSED highscore: ' + JSON.parse(highscores[highscoreIndex].toString())); parsedHighscores.push(JSON.parse(highscores[highscoreIndex].toString())); } catch(e) { logger.debug('ERROR in parsing Highscore.'); } } } var highscoreMarkup = twig({ ref: 'highscores', async: false }).render({ highscores: parsedHighscores }); logger.debug('highscore markup', highscoreMarkup); socket.volatile.emit('command', { commandtype: 'updateHighScore', payload: highscoreMarkup }); } else { if (!err) { err = 'Highscores List is empty'; } process.nextTick(function() {callback(err)}); } });
/** * @param {String[]} destinations */ copyConfigs(destinations) { destinations = destinations.length ? destinations : this.generateFrontendTestsPaths(); for (let destination of destinations) { let karmaDestination = path.join(destination, FrontendUnitTest.KARMA_CONFIG); let jspmConfigDestination = path.join(destination, FrontendUnitTest.JSPM_CONFIG); let name = karmaDestination.replace(/(?:.*\/)?src\/(.*)\/tests\/.*/gi, '$1'); let healthCheckObj = this.getHealthCheckObjectByName(name); let hasStripeDependency = false; if (!FrontendUnitTest.accessSync(karmaDestination)) { fsExtra.createFileSync(karmaDestination); let templateObj = Twig.twig({ data: fs.readFileSync(FrontendUnitTest.KARMA_CONFIG_TPL_PATH, 'utf8').toString(), }); if (healthCheckObj && healthCheckObj.hasOwnProperty('dependencies') && healthCheckObj.dependencies.hasOwnProperty('angular-stripe')) { hasStripeDependency = true; } let karmaContentString = templateObj.render({ hasStripeDependency: hasStripeDependency, }); fs.writeFileSync(karmaDestination, karmaContentString); } if (!FrontendUnitTest.accessSync(jspmConfigDestination)) { fsExtra.copySync( path.join(FrontendUnitTest.CONFIGS_SOURCE, FrontendUnitTest.JSPM_CONFIG), jspmConfigDestination ); } } }
redisClient.HGET('user_' + messageObj.user.user_id , 'user_socket_id', function(err, result) { logger.debug('Fetching user_socket_id by HGET err: ', err); logger.debug('Fetching user_socket_id by HGET result: ', result); if (!err && null != result) { var socketId = result.toString(); logger.debug('User socket id: ', socketId); console.log(io.of('/playground')); io.of('/playground').connected[socketId].volatile.emit( //socket.emit( 'command', { payload: twig({ ref: 'badge', async: false }).render({ badge: messageObj.badge }), commandtype: 'showBadge' } ); } else { logger.error('Cannot send badge to user: '******', because user_id => user_socket_id cannot be found'); } });
/** * Returns String[] of generated health checks * @returns {String[]} */ generateAngularHealthChecks() { let result = []; for (let healthCheckPath of this.healthCheckPaths) { if (FrontendUnitTest.accessSync(healthCheckPath.path)) { continue; } let templateObj = Twig.twig({ data: fs.readFileSync(FrontendUnitTest.HEALTH_CHECK_TPL_PATH, 'utf8').toString(), }); let relativePath = path.relative( path.dirname(healthCheckPath.path), path.dirname(healthCheckPath.moduleNamePath) ); relativePath = path.join(relativePath, 'name'); fsExtra.createFileSync(healthCheckPath.path); fs.writeFileSync( healthCheckPath.path, templateObj.render({ angularModuleName: healthCheckPath.name, moduleNamePath: relativePath }), 'utf-8' ); console.log(`Health check tests <info>${healthCheckPath.path}</info> have been added`); result.push(healthCheckPath.path); } return result; }
/** * @param {String} name * @param {String} filePath */ updatePackageJson(name, filePath) { let packageName = FrontendUnitTest.toKebabCase(`${name}FrontendTest`); //find dependencies let healthCheckObj = this.getHealthCheckObjectByName(name); let packageContentObject = {}; // file doesn't exist - need to create if (!FrontendUnitTest.accessSync(filePath)) { fsExtra.createFileSync(filePath); let templateObj = Twig.twig({ data: fs.readFileSync(FrontendUnitTest.PACKAGE_JSON_TPL_PATH, 'utf8').toString(), }); //update name in tests/frontend package.json let packageContentString = templateObj.render({ name: packageName, }); packageContentObject = JSON.parse(packageContentString); } else { // file exists - need just to update deps packageContentObject = fsExtra.readJsonSync(filePath, {throws: true}); } FrontendUnitTest.addDependencies(packageContentObject, healthCheckObj); fsExtra.writeJsonSync( filePath, packageContentObject ); }
var stream = through.obj(function (file, encoding, cb) { if (file.isNull()) { return cb(); } if (file.isStream()) { this.emit('error', new PluginError(PLUGIN_NAME, 'Streams not supported')); return cb(); } var paths = getFilePaths(file); var pattern, meta, data, patternCatDir = '', patternDestDir, configYml = {}; console.log('path.dirname(paths.absolute)'); console.log(path.dirname(paths.absolute)); var pathElements = path.dirname(paths.absolute).replace(/\/$/, '').split('/'); var patternDirName = pathElements[pathElements.length - 1]; console.log(paths.folder); console.log(patternDirName); /* find all patterns using their pattern.yml data file */ //if (options.patternFile) if (path.basename(paths.absolute) === 'pattern.yml') { // NATH: "pattern.yml" for file name should have the option of being something else // get metadata from pattern.yml file meta = yaml.safeLoad(fs.readFileSync(paths.relative, 'utf8')); console.log(meta); // get the data variables (if there are any) data = meta.data || {}; // make the pattern folder mkdirp.sync(PATTERN_IMPORT_DEST); // start putting pattern data into configYml object configYml.name = meta.name; // if there is a description, we'll add that to the configYml object if (meta.includes) { configYml.includes = meta.includes } // source will be the location of the pattern in this project configYml.source = paths.folder; // source of the DATA used - NATH: this section will change with addition of func to add LIVE/LOCAL data configYml.data = 'source'; // if there is a description, we'll add that to the configYml object if (meta.description) { configYml.description = meta.description } // if there is a category, we'll put this pattern into that category's subfolder if (meta.category) { // add category to configYml configYml.category = meta.category patternCatDir = meta.category + '/'; // add category to list of patterns array:: NATH: this may be not needed. why do you have this object? if (patternList[meta.category] === undefined) { patternList[meta.category] = []; } patternList[meta.category].push(path.join(meta.twig)); } else { patternList['uncategorized'].push(path.join(meta.twig)); } patternDestDir = PATTERN_IMPORT_DEST + patternCatDir + patternDirName; console.log(patternDestDir); mkdirp.sync(patternDestDir); //console.log(patternDestDir.isDirectory()); if (meta.sass) { var stats = fs.statSync(path.join(paths.folder, meta.sass)); if (stats.isDirectory()) { // allow a whole directory to be dumped console.log('SASS is A DIR'); fs.copy(path.join(paths.folder, meta.sass), patternDestDir + '/sass', function(err) { if (err) return console.error(err) console.log("success! (sass dir)") }) //copies directory } else { //otherwise, finds the containing dir of the file console.log('SASS is A FILE'); var cssFileName = patternDirName + '.css'; // THIS SECTION IS TO COPY THE SASS DIRECTORY // var origSassDir = path.dirname(path.join(paths.folder, meta.sass)); // fs.copy(origSassDir, patternDestDir + '/sass', function(err) { // if (err) return console.error(err) // console.log("success! (sass file)"); // }) //copies file // console.log('ACKACK'); // console.log('./'+path.join(patternDestDir, patternDirName + '.css')); // add css to configYml configYml.css = cssFileName; var result = sass.renderSync({ file: path.join(paths.folder, meta.sass) }); fs.writeFile(path.join(patternDestDir, cssFileName), result.css.toString().trim(), function (err) { if (err) throw err; console.log('css file saved ('+path.join(patternDestDir, cssFileName)+')'); }); } } if (meta.script && fs.existsSync(path.join(paths.folder, meta.script))) { // add script to configYml configYml.script = meta.script //mkdirp.sync(PATTERN_IMPORT_DEST + patternCatDir + 'scripts/'); var script = readFile(path.join(paths.folder, meta.script)); fs.writeFile(path.join(patternDestDir, meta.script), script, function (err) { if (err) throw err; console.log('script saved!'); }); } if (meta.twig && fs.existsSync(path.join(paths.folder, meta.twig))) { // add html file to configYml configYml.html = patternDirName + '.html'; var pattern = readFile(path.join(paths.folder, meta.twig)); console.log('data'); console.log(data); var tpl = twig.twig({ path: path.join(paths.folder, meta.twig), async: false }); //read the file with Twig console.log(tpl.render(data)); fs.writeFile(path.join(patternDestDir, patternDirName + '.html'), tpl.render(data), function (err) { if (err) throw err; console.log('pattern saved!'); }); // var tpl = swig.compileFile(path.join(paths.folder, meta.html)); // fs.writeFile(path.join(patternDestDir, meta.html), tpl(data), function (err) { // if (err) throw err; // console.log('pattern saved!'); // }); } console.log('configYml'); console.log(configYml); /* source: bower_components/pattern-library/patterns/figure-image data: source, [name of data source] includes: - base/img - components/message */ // configYml.source = 'test'; // configYml.data = 'source'; fs.writeFile(path.join(patternDestDir, 'compiled.yml'), yaml.safeDump(configYml), function (err) { if (err) throw err; console.log('compiled.yml saved!'); }); // Tell the user that stuff's gone down. gutil.log('Pattern ' + gutil.colors.magenta(paths.inner) + ' compiled'); } this.push(file); cb(); });
module.declare([{ twig: "vendor/twig" }], function (require, exports, module) { var twig = require("twig").twig; exports.template = twig({id:"templates/sub/sub.twig", data:[{"type":"raw","value":"I'm a "},{"type":"output","stack":[{"type":"Twig.expression.type.variable","value":"type","match":["type"]}]},{"type":"raw","value":"\n"}], precompiled: true}); });
grunt.registerMultiTask('twig', 'Compile and concatenate Twig templates.', function() { var Twig = require('twig'); // Merge task-specific and/or target-specific options with these defaults. // We use Twig templates to define the output format of your compiled Twig // templates. (Because we heard you like Twig templates.) var options = this.options({ amd_wrapper: true, variable: 'window.JST', separator: '\n', template: '{{ variable }} = {{ variable }} || {};\n{{ templates }}\n', each_template: '{{ variable }}["{{ filepath }}"] = Twig.twig({ data: {{ compiled }} });', template_key: function(path) { return path; }, extend: function () {}, allowInlineIncludes: true }); // extend twig options.extend(Twig); // Compile *our* templates. options.template = Twig.twig({ allowInlineIncludes: options.allowInlineIncludes, data: options.template }); options.each_template = Twig.twig({ allowInlineIncludes: options.allowInlineIncludes, data: options.each_template }); // Iterate over all specified file groups. this.files.forEach(function(f) { // Concat specified files. var src = f.src.filter(function(filepath) { // Warn on and remove invalid source files. if (!grunt.file.exists(filepath)) { grunt.log.warn('Source file "' + filepath + '" not found.'); return false; } return true; }).map(function(filepath) { // Read file source and run it through Twig's almost-compiler, which // produces an object that can be used to render the template. var source = grunt.file.read(filepath); try { return options.each_template.render({ variable: options.variable, filepath: options.template_key(filepath), compiled: JSON.stringify(Twig.twig({ data: source }).tokens), }); } catch (e) { grunt.log.warn(e); } }).join(grunt.util.normalizelf(options.separator)); // Apply overall template. src = options.template.render({ variable: options.variable, templates: src }); // Provide an AMD wrapper if requested. if (options.amd_wrapper) { src = 'require(["twig"], function(Twig) {\n' + src + '});\n'; } // Write the destination file. grunt.file.write(f.dest, src); // Print a success message. grunt.log.writeln('File "' + f.dest + '" created.'); }); });
/** * @param {String} type * @param {String} absoluteClassPath * @param {String} absoluteTestPath * @returns {String} */ createTestWithRelativePath(type, absoluteClassPath = '', absoluteTestPath = '') { let templateObj, services, providers, injectedDepsArray; let name = FrontendUnitTest.getClassName(absoluteTestPath); let testPathDir = path.dirname(absoluteTestPath); let classPathDir = path.dirname(absoluteClassPath); let relativePath = path.relative(testPathDir, classPathDir); let moduleNamePath = relativePath.replace(new RegExp(`${type}.+`, 'i'), 'name'); let hasInjectedServices = FrontendUnitTest.hasInjectedServices(absoluteClassPath); let hasInjectedProviders = FrontendUnitTest.hasInjectedProviders(absoluteClassPath); let hasImports = FrontendUnitTest.hasImports(absoluteClassPath); switch (type) { case FrontendUnitTest.CONTROLLER: let controllerName = FrontendUnitTest.getControllerName(absoluteClassPath); injectedDepsArray = FrontendUnitTest.getInjectedDepsForCtrl(absoluteClassPath); services = FrontendUnitTest.fetchServices(injectedDepsArray); providers = this.fetchProviders(injectedDepsArray); let otherDeps = FrontendUnitTest.skipScopeServices( FrontendUnitTest.diffArray(injectedDepsArray, services, providers) ); //@todo - need to clarify if we want to force this validation if (controllerName.indexOf(name) === -1) { throw new Error(`Controller name doesn't match to file name: ${absoluteClassPath}. Please refactor.`); } templateObj = Twig.twig({ data: fs.readFileSync(FrontendUnitTest.CONTROLLER_TPL_PATH, 'utf8').toString(), }); return templateObj.render({ ControllerName: controllerName, ClassName: name, moduleNamePath: moduleNamePath, services: services, providers: providers, otherDeps: otherDeps, staticGetters: FrontendUnitTest.getStaticGetters(absoluteClassPath), }); case FrontendUnitTest.DIRECTIVE: let directiveName = FrontendUnitTest.getDirectiveName(absoluteClassPath); let externalTemplatePath = FrontendUnitTest.getExternalTemplatePath(absoluteClassPath); let restrictType = FrontendUnitTest.getRestrictType(absoluteClassPath); let directiveController = FrontendUnitTest.getDirectiveController(absoluteClassPath); injectedDepsArray = FrontendUnitTest.getInjectedDepsForCtrl(absoluteClassPath); services = FrontendUnitTest.fetchServices(injectedDepsArray); providers = this.fetchProviders(injectedDepsArray); if (hasImports) { throw new Error(`Directive has import to external files`); } if (hasInjectedProviders) { throw new Error(`Directive has dependencies to unmocked providers`); } if (!directiveName || directiveName.length === 0) { let importString = (FrontendUnitTest.isDefaultExport(absoluteClassPath)) ? `import ${name} from \'${relativePath}/${name}\';` : `import {${name}} from \'${relativePath}/${name}\';`; templateObj = Twig.twig({ data: fs.readFileSync(FrontendUnitTest.DIRECTIVE_AS_CLASS_TPL_PATH, 'utf8').toString(), }); return templateObj.render({ ClassName: name, import: importString, objectName: FrontendUnitTest.lowerCaseFirstChar(name), staticGetters: FrontendUnitTest.getStaticGetters(absoluteClassPath), }); } templateObj = Twig.twig({ data: fs.readFileSync(FrontendUnitTest.DIRECTIVE_TPL_PATH, 'utf8').toString(), }); return templateObj.render({ directiveName: directiveName, directive: FrontendUnitTest.toKebabCase(directiveName), moduleNamePath: moduleNamePath, services: services, providers: providers, templateUrl: externalTemplatePath, restrictType: restrictType, directiveController: directiveController, }); case FrontendUnitTest.SERVICE: let serviceName = FrontendUnitTest.getServiceName(absoluteClassPath); injectedDepsArray = FrontendUnitTest.getInjectedDepsForService(absoluteClassPath); services = FrontendUnitTest.fetchServices(injectedDepsArray); providers = this.fetchProviders(injectedDepsArray); //create service test with injected services or providers if (serviceName === 'msAuthentication' || hasImports) { throw new Error(`Service has import to external files or service name is "msAuthentication"`); } if (!serviceName || serviceName.length === 0) { let importString = (FrontendUnitTest.isDefaultExport(absoluteClassPath)) ? `import ${name} from \'${relativePath}/${name}\';` : `import {${name}} from \'${relativePath}/${name}\';`; templateObj = Twig.twig({ data: fs.readFileSync(FrontendUnitTest.SERVICE_AS_CLASS_TPL_PATH, 'utf8').toString(), }); return templateObj.render({ ClassName: name, import: importString, objectName: FrontendUnitTest.lowerCaseFirstChar(name), staticGetters: FrontendUnitTest.getStaticGetters(absoluteClassPath), }); } else { templateObj = Twig.twig({ data: fs.readFileSync(FrontendUnitTest.SERVICE_TPL_PATH, 'utf8').toString(), }); return templateObj.render({ ClassName: name, ServiceName: serviceName, serviceName: FrontendUnitTest.lowerCaseFirstChar(serviceName), moduleNamePath: moduleNamePath, services: services, providers: providers, staticGetters: FrontendUnitTest.getStaticGetters(absoluteClassPath), }); } case FrontendUnitTest.MODEL: let service = FrontendUnitTest.isService(absoluteClassPath); //create model test as for angular service if (service) { templateObj = Twig.twig({ data: fs.readFileSync(FrontendUnitTest.MODEL_WITH_SERVICE_TPL_PATH, 'utf8').toString(), }); return templateObj.render({ ClassName: name, ServiceName: service, serviceName: FrontendUnitTest.lowerCaseFirstChar(service), moduleNamePath: moduleNamePath, }); } templateObj = Twig.twig({ data: fs.readFileSync(FrontendUnitTest.MODEL_TPL_PATH, 'utf8').toString(), }); //create model test as for class return templateObj.render({ ClassName: name, import: `import {${name}} from \'${relativePath}/${name}\';`, objectName: FrontendUnitTest.lowerCaseFirstChar(name), staticGetters: FrontendUnitTest.getStaticGetters(absoluteClassPath), }); case FrontendUnitTest.FILTER: templateObj = Twig.twig({ data: fs.readFileSync(FrontendUnitTest.FILTER_TPL_PATH, 'utf8').toString(), }); let filterName = FrontendUnitTest.getFilterName(absoluteClassPath); return templateObj.render({ filterName: filterName, moduleNamePath: moduleNamePath, }); default: throw new Error(`Invalid ${type} type of test`); } }