Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(function () {
hbs = handlebars.create();
handlebarsLayouts.register(hbs);
// Register partials
hbs.registerPartial({
'deep-a': read(config.partials, 'deep-a.hbs'),
'deep-b': read(config.partials, 'deep-b.hbs'),
'deep-c': read(config.partials, 'deep-c.hbs'),
'parent-context': read(config.partials, 'parent-context.hbs'),
context: read(config.partials, 'context.hbs'),
layout2col: read(config.partials, 'layout2col.hbs'),
layout: read(config.partials, 'layout.hbs'),
media: read(config.partials, 'media.hbs'),
user: read(config.partials, 'user.hbs')
});
});
(async function() {
const Templates = require('templates');
const app = new Templates();
const pages = app.create('pages', { type: 'renderable' });
const partials = app.create('partials', { type: 'partial' });
const layouts = app.create('layouts', { type: 'layout' });
app.data({ site: { title: 'Blog' }});
app.engine('hbs', engine(handlebars.create()));
app.option('engine', 'hbs');
const view = await pages.set('templates/foo.hbs', {
contents: Buffer.from('Name: {{name}}, {{description}}'),
data: { name: 'Brian' },
layout: 'inner'
});
// layouts
await layouts.set({
path: 'default',
data: { title: 'Blog', description: 'Awesome blog' },
contents: Buffer.from(`
'use strict';
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('..');
describe('misc', function() {
beforeEach(function() {
helpers.misc({handlebars: hbs});
});
describe('noop', function() {
it('should be a noop', function() {
var fn = hbs.compile('{{#noop}}{{message}}{{/noop}}');
assert.equal(fn({message: 'This is a test'}), 'This is a test');
});
});
describe('option', function() {
it('should get an option', function() {
it('adds partials to a Handlebars instance', () => {
const handlebars = create();
return loadPartials('test/fixtures/partials/partials', handlebars).then(() => {
expect(handlebars.partials).to.have.property('partial').that.is.a('string');
});
});
});
'use strict';
require('mocha');
var fs = require('fs');
var path = require('path');
var assert = require('assert');
var hbs = require('handlebars').create();
require('..')({handlebars: hbs});
var libFiles = fs.readdirSync(path.join(__dirname, '../lib'))
.map(function(fp) {
return path.join('lib', fp);
});
describe('fs', function() {
describe('read', function() {
it('should read a file from the file system', function() {
var fn = hbs.compile('{{read filepath}}');
assert.equal(fn({filepath: 'test/fixtures/read/a.txt'}), 'abc');
});
});
describe('readdir', function() {
it('manager gives engine via "getEngine"', async () => {
const rootServer = Hapi.server();
const relativeToPath = 'test/templates';
await rootServer.register({
plugin: Vision,
options: {
engines: { html: Handlebars.create() },
relativeTo: relativeToPath,
path: 'valid'
}
});
const one = {
name: 'one',
register: async function (server, options) {
await server.register({
plugin: Vision,
options: {
engines: {
html: Handlebars,
pug: Pug
},
'use strict';
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('..');
helpers.array({handlebars: hbs});
helpers.string({handlebars: hbs});
var context = {array: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']};
describe('array', function() {
describe('after', function() {
it('should return an empty string when undefined', function() {
assert.equal(hbs.compile('{{after}}')(), '');
});
it('should return all of the items in an array after the given index', function() {
var fn = hbs.compile('{{after array 5}}');
assert.equal(fn(context), 'f,g,h');
});
it('should defer registration of partials', function () {
var hb = handlebars.create();
handlebarsRegistrar(hb, {
partials: __dirname + '/fixtures/partials/deferred/*.js'
});
expect(hb.partials.layout).to.be.a('string');
expect(hb.partials['layout-2col']).to.be.a('string');
expect(hb.partials.item).to.be.a('string');
expect(hb.partials.link).to.be.a('string');
});
const fs = require('fs'),
handlebars = require('handlebars').create()
require.extensions['.tmpl'] = function(module, filename) {
module.exports = fs.readFileSync(filename, 'utf8')
}
const modulesTemplate = handlebars.compile(require('../files/modules.xml.tmpl'))
const moduleImlTemplate = handlebars.compile(require('../files/module.iml.tmpl'))
const workspaceXmlTemplate = handlebars.compile(require('../files/workspace.xml.tmpl'))
module.exports.ideaModulesFile = function(targetFile, modules) {
const content = modulesTemplate({modules: modules})
fs.writeFileSync(targetFile, content)
}
module.exports.ideaModuleImlFile = function(targetFile, config) {
const content = moduleImlTemplate({config})