Skip to content

Commit

Permalink
fix multiple hb instances issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusmaso committed Dec 31, 2017
1 parent 6a0a622 commit a5657ea
Show file tree
Hide file tree
Showing 19 changed files with 5,887 additions and 169 deletions.
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module.exports = function(grunt) {
},
babel: {
options: {
presets: ['es2015']
presets: ['es2015'],
plugins: ["transform-object-rest-spread", "transform-object-assign"]
},
dist: {
files: [
Expand Down
128 changes: 83 additions & 45 deletions dist/handlebars.nested.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// handlebars.nested
// -----------------
// v0.2.2
// v0.2.3
//
// Copyright (c) 2012-2017 Mateus Maso
// Distributed under MIT license
Expand All @@ -9,21 +9,36 @@


(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";
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.registerHelper = registerHelper;
exports.resolveNested = resolveNested;
exports.resolveNested = exports.registerHelper = undefined;

var _registerHelper = require('./registerHelper');

var _deps = require("../deps");
var _registerHelper2 = _interopRequireDefault(_registerHelper);

var _deps2 = _interopRequireDefault(_deps);
var _resolveNested = require('./resolveNested');

var _resolveNested2 = _interopRequireDefault(_resolveNested);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.registerHelper = _registerHelper2.default;
exports.resolveNested = _resolveNested2.default;

},{"./registerHelper":2,"./resolveNested":3}],2:[function(require,module,exports){
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = registerHelper;
function registerHelper(name, fn, inverse) {
var Handlebars = this;

var nestedFn = function nestedFn() {
var nestedArguments = [];

Expand All @@ -32,77 +47,84 @@ function registerHelper(name, fn, inverse) {

if (argument && argument.hash) {
for (var key in argument.hash) {
argument.hash[key] = resolveNested.apply(this, [argument.hash[key]]);
argument.hash[key] = Handlebars.resolveNested(argument.hash[key], this);
}

nestedArguments.push(argument);
} else {
nestedArguments.push(resolveNested.apply(this, [argument]));
nestedArguments.push(Handlebars.resolveNested(argument, this));
}
}

return fn.apply(this, nestedArguments);
};

_deps2.default.Handlebars._registerHelper.apply(this, [name, nestedFn, inverse]);
};

function resolveNested(value) {
if ((0, _deps.getUtils)().isString(value) && value.indexOf('{{') >= 0) {
value = _deps2.default.Handlebars.compile(value)(this);
}

return value;
this._registerHelper.apply(this, [name, nestedFn, inverse]);
};

},{"../deps":2}],2:[function(require,module,exports){
"use strict";
},{}],3:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getUtils = getUtils;
var deps = {};

function getUtils() {
return deps.Handlebars.Utils;
}
exports.default = resolveNested;
function resolveNested(value, context) {
if (this.Utils.isString(value) && value.indexOf('{{') >= 0) {
value = this.compile(value)(context);
}

exports.default = deps;
return value;
};

},{}],3:[function(require,module,exports){
},{}],4:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

exports.default = HandlebarsNested;

var _utils = require('./utils');

var _core = require('./core');

var _deps = require('./deps');

var _deps2 = _interopRequireDefault(_deps);
function bindAll(object, parent) {
Object.keys(object).forEach(function (key) {
if (typeof object[key] === "function") {
object[key] = object[key].bind(parent);
}
});

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
return object;
};

function HandlebarsNested(Handlebars) {
if (!_deps2.default.Handlebars) {
var extend = Handlebars.Utils.extend;
function extendRegisterHelper(Handlebars) {
var _registerHelper;

if (Handlebars._registerHelper) {
_registerHelper = Handlebars._registerHelper;
} else {
_registerHelper = Handlebars.registerHelper;
}

extend(_deps2.default, { Handlebars: Handlebars });
return {
_registerHelper: _registerHelper,
registerHelper: _core.registerHelper
};
};

extend(Handlebars, {
resolveNested: _core.resolveNested,
registerHelper: _core.registerHelper,
_registerHelper: Handlebars.registerHelper
});
function HandlebarsNested(Handlebars) {
_extends(Handlebars, bindAll(_extends({
resolveNested: _core.resolveNested
}, extendRegisterHelper(Handlebars)), Handlebars));

extend(Handlebars.Utils, { isString: _utils.isString });
}
_extends(Handlebars.Utils, bindAll({
isString: _utils.isString
}, Handlebars.Utils));

return Handlebars;
}
Expand All @@ -111,15 +133,31 @@ if (typeof window !== "undefined" && window.Handlebars) {
HandlebarsNested(window.Handlebars);
}

},{"./core":1,"./deps":2,"./utils":4}],4:[function(require,module,exports){
},{"./core":1,"./utils":5}],5:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isString = undefined;

var _isString = require('./isString');

var _isString2 = _interopRequireDefault(_isString);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.isString = _isString2.default;

},{"./isString":6}],6:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isString = isString;
exports.default = isString;
function isString(object) {
return toString.call(object) == '[object String]';
}

},{}]},{},[3]);
},{}]},{},[4]);
4 changes: 2 additions & 2 deletions dist/handlebars.nested.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 9 additions & 35 deletions lib/core/index.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,19 @@
"use strict";
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.registerHelper = registerHelper;
exports.resolveNested = resolveNested;
exports.resolveNested = exports.registerHelper = undefined;

var _deps = require("../deps");
var _registerHelper = require('./registerHelper');

var _deps2 = _interopRequireDefault(_deps);
var _registerHelper2 = _interopRequireDefault(_registerHelper);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function registerHelper(name, fn, inverse) {
var nestedFn = function nestedFn() {
var nestedArguments = [];

for (var index = 0; index < arguments.length; index++) {
var argument = arguments[index];

if (argument && argument.hash) {
for (var key in argument.hash) {
argument.hash[key] = resolveNested.apply(this, [argument.hash[key]]);
}
var _resolveNested = require('./resolveNested');

nestedArguments.push(argument);
} else {
nestedArguments.push(resolveNested.apply(this, [argument]));
}
}
var _resolveNested2 = _interopRequireDefault(_resolveNested);

return fn.apply(this, nestedArguments);
};

_deps2.default.Handlebars._registerHelper.apply(this, [name, nestedFn, inverse]);
};

function resolveNested(value) {
if ((0, _deps.getUtils)().isString(value) && value.indexOf('{{') >= 0) {
value = _deps2.default.Handlebars.compile(value)(this);
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

return value;
};
exports.registerHelper = _registerHelper2.default;
exports.resolveNested = _resolveNested2.default;
31 changes: 31 additions & 0 deletions lib/core/registerHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = registerHelper;
function registerHelper(name, fn, inverse) {
var Handlebars = this;

var nestedFn = function nestedFn() {
var nestedArguments = [];

for (var index = 0; index < arguments.length; index++) {
var argument = arguments[index];

if (argument && argument.hash) {
for (var key in argument.hash) {
argument.hash[key] = Handlebars.resolveNested(argument.hash[key], this);
}

nestedArguments.push(argument);
} else {
nestedArguments.push(Handlebars.resolveNested(argument, this));
}
}

return fn.apply(this, nestedArguments);
};

this._registerHelper.apply(this, [name, nestedFn, inverse]);
};
13 changes: 13 additions & 0 deletions lib/core/resolveNested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = resolveNested;
function resolveNested(value, context) {
if (this.Utils.isString(value) && value.indexOf('{{') >= 0) {
value = this.compile(value)(context);
}

return value;
};
13 changes: 0 additions & 13 deletions lib/deps/index.js

This file was deleted.

Loading

0 comments on commit a5657ea

Please # to comment.