Skip to content

Commit

Permalink
update readme + es6 + browser/server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusmaso committed May 23, 2016
1 parent caffd48 commit 5ae11cb
Show file tree
Hide file tree
Showing 17 changed files with 371 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- "0.10"
- "5.9.0"
before_install:
- npm install -g grunt-cli
41 changes: 32 additions & 9 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,33 @@ module.exports = function(grunt) {
banner: '<%= meta.banner %>'
},
build: {
src: 'src/<%= pkg.name %>.js',
src: 'dist/<%= pkg.name %>.js',
dest: 'dist/<%= pkg.name %>.min.js'
}
},
concat: {
babel: {
options: {
presets: ['es2015']
},
dist: {
files: [
{
expand: true,
cwd: 'src/',
src: ['**/*.js'],
dest: 'lib/'
}
]
}
},
browserify: {
options: {
banner: '<%= meta.banner %>'
},
dist: {
src: ['src/**/*.js'],
dest: 'dist/<%= pkg.name %>.js'
files: {
'dist/<%= pkg.name %>.js': ['lib/index.js']
}
}
},
mochaTest: {
Expand All @@ -38,15 +54,22 @@ module.exports = function(grunt) {
reporter: 'spec',
mocha: require('mocha')
},
src: ['spec/**/*.js']
src: ['spec/index.js']
}
},
clean: ['dist']
mocha_phantomjs: {
options: {
reporter: 'spec'
},
all: ['spec/index.html']
}
});

grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-mocha-phantomjs');

grunt.registerTask('default', ['uglify', 'concat', 'mochaTest']);
grunt.registerTask('default', ['babel', 'browserify', 'uglify', 'mochaTest', 'mocha_phantomjs']);
};
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
handlebars.nested [![Build Status](https://travis-ci.org/mateusmaso/handlebars.nested.svg?branch=master)](https://travis-ci.org/mateusmaso/handlebars.nested)
=================

This library is an extension for Handlebars which allows nesting helpers and expressions in one level deep. It was first created as a workaround but turned out to be an simple and effective solution for many issues.
This is an extension for Handlebars which allows nesting helpers and expressions in one level deep. For latest versions of Handlebars, please consider using [subexpressions](http://handlebarsjs.com/expressions.html) instead.

## Features
## Install

* Nesting helpers and expressions.

## Dependencies

* handlebars.js (>= 1.0.0)
```
$ npm install --save handlebars.nested
```

## Node
## Usage

```javascript
var Handlebars = global.Handlebars = require("handlebars");
require("handlebars.nested");
var Handlebars = require("handlebars");
require("handlebars.nested").default(Handlebars);
```

## Examples
Expand All @@ -31,4 +29,4 @@ require("handlebars.nested");

## License

Copyright (c) 2012-2014 Mateus Maso. Released under an MIT license.
MIT © [Mateus Maso](http://www.mateusmaso.com)
142 changes: 103 additions & 39 deletions dist/handlebars.nested.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,125 @@
// handlebars.nested
// -----------------
// v0.1.1
// v0.2.0
//
// Copyright (c) 2012-2014 Mateus Maso
// Copyright (c) 2012-2016 Mateus Maso
// Distributed under MIT license
//
// http://github.com/mateusmaso/handlebars.nested

(function(root, factory) {

if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports)
module.exports = factory(global.Handlebars);
exports = factory(global.Handlebars);
} else {
factory(root.Handlebars);
}
(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";

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

var Utils = Handlebars.Utils;
var registerHelper = Handlebars.registerHelper;
var _deps = require("../deps");

Handlebars.Utils.isString = function(object) {
return toString.call(object) == '[object String]';
};
var _deps2 = _interopRequireDefault(_deps);

Handlebars.registerHelper = function(name, fn, inverse) {
var nestedFn = function() {
var nestedArguments = [];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

for (var index = 0; index < arguments.length; index++) {
var argument = arguments[index];
function registerHelper(name, fn, inverse) {
var nestedFn = function nestedFn() {
var nestedArguments = [];

if (argument && argument.hash) {
for (key in argument.hash) {
argument.hash[key] = Handlebars.resolveNested.apply(this, [argument.hash[key]]);
}
for (var index = 0; index < arguments.length; index++) {
var argument = arguments[index];

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

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

registerHelper.apply(this, [name, nestedFn, inverse]);
return fn.apply(this, nestedArguments);
};

Handlebars.resolveNested = function(value) {
if (Utils.isString(value) && value.indexOf('{{') >= 0) {
value = Handlebars.compile(value)(this);
}
_deps2.default.Handlebars._registerHelper.apply(this, [name, nestedFn, inverse]);
};

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

return value;
};

},{"../deps":2}],2:[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 = deps;

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

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

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

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

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

var _deps2 = _interopRequireDefault(_deps);

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

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


extend(_deps2.default, { Handlebars: Handlebars });

extend(Handlebars, {
resolveNested: _core.resolveNested,
registerHelper: _core.registerHelper,
_registerHelper: Handlebars.registerHelper
});

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

return Handlebars;
}

if (typeof window !== "undefined" && window.Handlebars) {
HandlebarsNested(window.Handlebars);
}

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

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

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

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

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

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

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

var _deps2 = _interopRequireDefault(_deps);

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]]);
}

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

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;
};
13 changes: 13 additions & 0 deletions lib/deps/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";

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

function getUtils() {
return deps.Handlebars.Utils;
}

exports.default = deps;
39 changes: 39 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

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

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

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

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

var _deps2 = _interopRequireDefault(_deps);

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

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


extend(_deps2.default, { Handlebars: Handlebars });

extend(Handlebars, {
resolveNested: _core.resolveNested,
registerHelper: _core.registerHelper,
_registerHelper: Handlebars.registerHelper
});

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

return Handlebars;
}

if (typeof window !== "undefined" && window.Handlebars) {
HandlebarsNested(window.Handlebars);
}
9 changes: 9 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

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

0 comments on commit 5ae11cb

Please # to comment.