handlebars-layouts
Advanced tools
Comparing version 3.1.2 to 3.1.3
@@ -0,1 +1,14 @@ | ||
## 3.1.3 | ||
Bugfixes: | ||
- Added support for objects with a null prototype. ([#27](https://github.com/shannonmoeller/handlebars-layouts/issues/27), [#28](https://github.com/shannonmoeller/handlebars-layouts/pull/28)) | ||
## 3.1.2 | ||
Bugfixes: | ||
- Handlebars wasn't playing nice with Object.create, so all cases have been removed in favor of property copying. | ||
- Now using `handlebars.createFrame` with `options.data` and using the result with partials. | ||
## 3.1.1 | ||
@@ -2,0 +15,0 @@ |
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.handlebarsLayouts = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
'use strict'; | ||
var hasOwn = Object.prototype.hasOwnProperty; | ||
function noop() { | ||
@@ -37,12 +39,21 @@ return ''; | ||
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(); | ||
} | ||
default: { | ||
@@ -68,3 +79,3 @@ return val; | ||
// istanbul ignore else | ||
if (arg.hasOwnProperty(key)) { | ||
if (hasOwn.call(arg, key)) { | ||
target[key] = arg[key]; | ||
@@ -106,8 +117,6 @@ } | ||
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 | ||
@@ -127,3 +136,3 @@ if (template == null) { | ||
// Render partial | ||
return template(context); | ||
return template(context, { data: data }); | ||
}, | ||
@@ -141,3 +150,3 @@ | ||
embed: function () { | ||
var context = handlebars.createFrame(this || {}); | ||
var context = mixin({}, this || {}); | ||
@@ -163,2 +172,3 @@ // Reset context | ||
var fn = options.fn || noop, | ||
data = handlebars.createFrame(options.data), | ||
context = this || {}; | ||
@@ -170,3 +180,3 @@ | ||
applyAction.bind(context), | ||
fn(context) | ||
fn(context, { data: data }) | ||
); | ||
@@ -188,2 +198,3 @@ }, | ||
var fn = options.fn, | ||
data = handlebars.createFrame(options.data), | ||
hash = options.hash || {}, | ||
@@ -202,2 +213,3 @@ mode = hash.mode || 'replace', | ||
getActionsByName(context, name).push({ | ||
options: { data: data }, | ||
mode: mode.toLowerCase(), | ||
@@ -204,0 +216,0 @@ fn: fn |
'use strict'; | ||
var hasOwn = Object.prototype.hasOwnProperty; | ||
function noop() { | ||
@@ -46,8 +48,11 @@ return ''; | ||
} | ||
case 'prepend': { | ||
return fn() + val; | ||
} | ||
case 'replace': { | ||
return fn(); | ||
} | ||
default: { | ||
@@ -73,3 +78,3 @@ return val; | ||
// istanbul ignore else | ||
if (arg.hasOwnProperty(key)) { | ||
if (hasOwn.call(arg, key)) { | ||
target[key] = arg[key]; | ||
@@ -76,0 +81,0 @@ } |
{ | ||
"name": "handlebars-layouts", | ||
"version": "3.1.2", | ||
"version": "3.1.3", | ||
"description": "Handlebars helpers which implement layout blocks similar to Jade, Jinja, Swig, and Twig.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -122,2 +122,10 @@ /* eslint-env mocha */ | ||
it('should pass through non-object values', function (done) { | ||
var data = Object.create(null); | ||
data.key = 'value'; | ||
testWithFile('non-object.html', data, done); | ||
}); | ||
it('should throw an error if partial is not registered', function (done) { | ||
@@ -124,0 +132,0 @@ testWithFile('error.html', {}, done); |
74833
49
924