Socket
Socket
Sign inDemoInstall

handlebars-layouts

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

handlebars-layouts - npm Package Compare versions

Comparing version 3.1.1 to 3.1.2

27

index.js

@@ -36,11 +36,17 @@ 'use strict';

function applyAction(val, action) {
var context = this;
function fn() {
return action.fn(context, action.options);
}
switch (action.mode) {
case 'append': {
return val + action.fn(this);
return val + fn();
}
case 'prepend': {
return action.fn(this) + val;
return fn() + val;
}
case 'replace': {
return action.fn(this);
return fn();
}

@@ -104,8 +110,6 @@ default: {

var fn = options.fn || noop,
context = handlebars.createFrame(this || {}),
context = mixin({}, this, customContext, options.hash),
data = handlebars.createFrame(options.data),
template = handlebars.partials[name];
// Mix custom context and hash into context
mixin(context, customContext, options.hash);
// Partial template required

@@ -125,3 +129,3 @@ if (template == null) {

// Render partial
return template(context);
return template(context, { data: data });
},

@@ -139,3 +143,3 @@

embed: function () {
var context = handlebars.createFrame(this || {});
var context = mixin({}, this || {});

@@ -161,2 +165,3 @@ // Reset context

var fn = options.fn || noop,
data = handlebars.createFrame(options.data),
context = this || {};

@@ -168,3 +173,3 @@

applyAction.bind(context),
fn(context)
fn(context, { data: data })
);

@@ -186,2 +191,3 @@ },

var fn = options.fn,
data = handlebars.createFrame(options.data),
hash = options.hash || {},

@@ -200,2 +206,3 @@ mode = hash.mode || 'replace',

getActionsByName(context, name).push({
options: { data: data },
mode: mode.toLowerCase(),

@@ -202,0 +209,0 @@ fn: fn

{
"name": "handlebars-layouts",
"version": "3.1.1",
"version": "3.1.2",
"description": "Handlebars helpers which implement layout blocks similar to Jade, Jinja, Swig, and Twig.",

@@ -29,2 +29,3 @@ "keywords": [

"coveralls": "cat ./coverage/lcov.info | coveralls",
"lint": "eslint index.js gulpfile.js test/*.js",
"test": "gulp test",

@@ -34,2 +35,3 @@ "zuul": "zuul -- test/handlebars-layouts.spec.js"

"devDependencies": {
"babel-eslint": "^4.1.1",
"browserify": "^10.2.4",

@@ -36,0 +38,0 @@ "consolidate": "^0.13.1",

@@ -6,18 +6,23 @@ 'use strict';

express = require('express'),
handlebars = require('handlebars'),
fs = require('fs'),
handlebars = require('handlebars'),
path = require('path'),
data = require('./fixtures/data/users.json'),
fixtures = process.cwd() + '/fixtures',
views = fixtures + '/templates',
partials = fixtures + '/partials';
fixtures = path.join(process.cwd(), 'fixtures'),
views = path.join(fixtures, 'templates'),
partials = path.join(fixtures, 'partials');
function read(file) {
return fs.readFileSync(path.join(partials, file), 'utf8');
}
// Register helpers
handlebars.registerHelper(handlebarsLayouts(handlebars));
handlebarsLayouts.register(handlebars);
// Register partials
handlebars.registerPartial({
layout: fs.readFileSync(partials + '/layout.hbs', 'utf8'),
layout2col: fs.readFileSync(partials + '/layout2col.hbs', 'utf8'),
media: fs.readFileSync(partials + '/media.hbs', 'utf8'),
user: fs.readFileSync(partials + '/user.hbs', 'utf8')
layout: read('layout.hbs'),
layout2col: read('layout2col.hbs'),
media: read('media.hbs'),
user: read('user.hbs')
});

@@ -24,0 +29,0 @@

@@ -1,6 +0,6 @@

/*eslint-env mocha */
/* eslint-env mocha */
'use strict';
var handlebars,
handlebarsLayouts,
var handlebarsLayouts = require('../index'),
handlebars = require('handlebars'),
expect = require('expect'),

@@ -13,11 +13,13 @@ fs = require('fs'),

config = {
partials: path.join(__dirname, '/fixtures/partials/'),
fixtures: path.join(__dirname, '/fixtures/templates/'),
expected: path.join(__dirname, '/expected/templates/'),
actual: path.join(__dirname, '/actual/templates/')
partials: path.join(__dirname, 'fixtures/partials/'),
fixtures: path.join(__dirname, 'fixtures/templates/'),
expected: path.join(__dirname, 'expected/templates/'),
actual: path.join(__dirname, 'actual/templates/')
};
describe('handlebars-layouts e2e', function () {
function read(filepath) {
return fs.readFileSync(filepath, 'utf8');
var hbs;
function read() {
return fs.readFileSync(path.join.apply(path, arguments), 'utf8');
}

@@ -33,3 +35,3 @@

try {
template = handlebars.compile(String(file.contents));
template = hbs.compile(String(file.contents));
file.contents = new Buffer(template(data));

@@ -63,24 +65,16 @@ this.push(file);

beforeEach(function () {
// Delete
delete require.cache[require.resolve('handlebars')];
delete require.cache[require.resolve('../index')];
hbs = handlebars.create();
handlebarsLayouts.register(hbs);
// Reload
handlebars = require('handlebars');
handlebarsLayouts = require('../index');
// Register helpers
handlebars.registerHelper(handlebarsLayouts(handlebars));
// Register partials
handlebars.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'),
context: read(config.partials + '/context.hbs'),
'parent-context': read(config.partials + '/parent-context.hbs'),
layout: read(config.partials + '/layout.hbs'),
layout2col: read(config.partials + '/layout2col.hbs'),
media: read(config.partials + '/media.hbs'),
user: read(config.partials + '/user.hbs')
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')
});

@@ -99,6 +93,2 @@ });

it('should preserve context', function (done) {
testWithFile('context.html', {root: 'root'}, done);
});
it('should embed layouts', function (done) {

@@ -110,2 +100,6 @@ var data = require('./fixtures/data/users.json');

it('should preserve context', function (done) {
testWithFile('context.html', {root: 'root'}, done);
});
it('should append content', function (done) {

@@ -112,0 +106,0 @@ testWithFile('append.html', { title: 'append' }, done);

@@ -1,2 +0,2 @@

/*eslint-env mocha */
/* eslint-env mocha */
'use strict';

@@ -3,0 +3,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc