├── .verb.md ├── .gitattributes ├── .travis.yml ├── .editorconfig ├── .gitignore ├── appveyor.yml ├── Gruntfile.js ├── LICENSE ├── index.js ├── package.json ├── test └── core_test.js ├── .eslintrc.json └── README.md /.verb.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | ```js 4 | var assembleHandlebars = require('{%= name %}'); 5 | ``` 6 | 7 | ## API 8 | {%= apidocs('index.js') %} 9 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | install: npm install -g grunt-cli && npm install 4 | node_js: 5 | - node 6 | - '7.7' 7 | - '7' 8 | - '6.10' 9 | - '6' 10 | - '5' 11 | - '4.8' 12 | - '4' 13 | - '0.12' 14 | - '0.10' 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 12 | trim_trailing_whitespace = false 13 | insert_final_newline = false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | *.sublime-* 4 | 5 | # test related, or directories generated by tests 6 | test/actual 7 | actual 8 | coverage 9 | .nyc* 10 | 11 | # npm 12 | node_modules 13 | npm-debug.log 14 | 15 | # yarn 16 | yarn.lock 17 | yarn-error.log 18 | 19 | # misc 20 | _gh_pages 21 | _draft 22 | _drafts 23 | bower_components 24 | vendor 25 | temp 26 | tmp 27 | TODO.md 28 | 29 | examples/*/dist 30 | examples/*/site 31 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # Test against this version of Node.js 2 | environment: 3 | matrix: 4 | # node.js 5 | - nodejs_version: "7.0" 6 | - nodejs_version: "6.0" 7 | - nodejs_version: "5.0" 8 | - nodejs_version: "4.0" 9 | - nodejs_version: "0.12" 10 | - nodejs_version: "0.10" 11 | 12 | # Install scripts. (runs after repo cloning) 13 | install: 14 | # Get the latest stable version of Node.js or io.js 15 | - ps: Install-Product node $env:nodejs_version 16 | # install modules 17 | - npm install 18 | 19 | # Post-install test scripts. 20 | test_script: 21 | # Output useful info for debugging. 22 | - node --version 23 | - npm --version 24 | # run tests 25 | - npm test 26 | 27 | # Don't actually build. 28 | build: off 29 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * assemble-handlebars 3 | * 4 | * Copyright (c) 2013-2015, Brian Woodward. 5 | * Licensed under the MIT License. 6 | */ 7 | 8 | module.exports = function(grunt) { 9 | 'use strict'; 10 | 11 | // Project configuration. 12 | grunt.initConfig({ 13 | eslint: { 14 | src: ['*.js', 'test/*.js'] 15 | }, 16 | 17 | mochaTest: { 18 | tests: { 19 | options: { 20 | reporter: 'progress' 21 | }, 22 | src: ['test/**/*_test.js'] 23 | } 24 | } 25 | }); 26 | 27 | grunt.loadNpmTasks('gruntify-eslint'); 28 | grunt.loadNpmTasks('grunt-mocha-test'); 29 | 30 | grunt.registerTask('test', ['mochaTest']); 31 | grunt.registerTask('lint', ['eslint']); 32 | grunt.registerTask('default', ['lint', 'test']); 33 | }; 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2015, 2017, Assemble, Brian Woodward 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * assemble-handlebars 3 | * 4 | * Copyright (c) 2013-2017, Brian Woodward. 5 | * Licensed under the MIT License. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var helpers = require('handlebars-helpers'); 11 | var handlebars = require('handlebars'); 12 | 13 | // register built-in helpers 14 | exports.init = function(options, params) { 15 | options = options || {}; 16 | if (options.handlebars) { 17 | handlebars = options.handlebars; 18 | } 19 | helpers(options); 20 | }; 21 | 22 | exports.compile = function(str, context, cb) { 23 | var fn; 24 | try { 25 | fn = handlebars.compile(str, context); 26 | } catch (err) { 27 | return cb(err); 28 | } 29 | cb(null, fn); 30 | }; 31 | 32 | exports.render = function(template, context, cb) { 33 | var res; 34 | try { 35 | if (typeof template === 'string') { 36 | template = handlebars.compile(template, context); 37 | } 38 | res = template(context); 39 | } catch (err) { 40 | return cb(err); 41 | } 42 | cb(null, res); 43 | }; 44 | 45 | exports.registerFunctions = function(fns) { 46 | fns = fns || {}; 47 | 48 | for (var key in fns) { 49 | if (fns.hasOwnProperty(key)) { 50 | handlebars.registerHelper(key, fns[key]); 51 | } 52 | } 53 | }; 54 | 55 | exports.registerPartial = function(name, str) { 56 | try { 57 | handlebars.registerPartial(name, str); 58 | } catch (err) {} 59 | }; 60 | 61 | exports.handlebars = handlebars; 62 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "assemble-handlebars", 3 | "description": "Handlebars engine plugin for grunt-assemble. This is only used in grunt-assemble and versions of assemble below 0.4.x.", 4 | "version": "0.4.1", 5 | "homepage": "https://github.com/assemble/assemble-handlebars", 6 | "author": "Brian Woodward (https://github.com/doowb)", 7 | "maintainers": [ 8 | "Brian Woodward (https://github.com/doowb)", 9 | "Jon Schlinkert (https://github.com/jonschlinkert)" 10 | ], 11 | "contributors": [ 12 | "Anders D. Johnson (https://andrz.me)", 13 | "Brian Woodward (https://twitter.com/doowb)", 14 | "Jon Schlinkert (http://twitter.com/jonschlinkert)", 15 | "Laurent Goderre (https://github.com/LaurentGoderre)", 16 | "Paul Welsh (paulwelsh.info)" 17 | ], 18 | "repository": "assemble/assemble-handlebars", 19 | "bugs": { 20 | "url": "https://github.com/assemble/assemble-handlebars/issues" 21 | }, 22 | "license": "MIT", 23 | "files": [ 24 | "./index.js", 25 | "index.js" 26 | ], 27 | "main": "./index.js", 28 | "engines": { 29 | "node": ">= 0.8.0" 30 | }, 31 | "scripts": { 32 | "test": "grunt test" 33 | }, 34 | "dependencies": { 35 | "handlebars": "^4.0.6", 36 | "handlebars-helpers": "^0.8.0" 37 | }, 38 | "devDependencies": { 39 | "grunt": "^1.0.1", 40 | "grunt-mocha-test": "^0.13.2", 41 | "gruntify-eslint": "^3.1.0", 42 | "gulp-format-md": "^0.1.11", 43 | "mocha": "^3.2.0" 44 | }, 45 | "keywords": [ 46 | "assemble", 47 | "assembleengine", 48 | "handlebars", 49 | "helpers", 50 | "template", 51 | "templates" 52 | ], 53 | "verb": { 54 | "toc": false, 55 | "layout": "default", 56 | "tasks": [ 57 | "readme" 58 | ], 59 | "plugins": [ 60 | "gulp-format-md" 61 | ], 62 | "related": { 63 | "list": [ 64 | "assemble", 65 | "grunt", 66 | "grunt-assemble", 67 | "handlebars-helpers" 68 | ] 69 | }, 70 | "lint": { 71 | "reflinks": true 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test/core_test.js: -------------------------------------------------------------------------------- 1 | require('mocha'); 2 | var assert = require('assert'); 3 | 4 | describe('Init', function() { 5 | it('initializes the engine', function() { 6 | var engine = require('../index'); 7 | engine.init({}); 8 | // TODO: Add test with actual options 9 | assert.equal(typeof engine, 'object'); 10 | }); 11 | }); 12 | 13 | describe('Compile', function() { 14 | it('creates a template object', function(done) { 15 | var engine = require('../index'); 16 | engine.compile('{{baz}}', {}, function(err, tmpl) { 17 | if (err) { 18 | return done(err); 19 | } 20 | assert.equal(typeof tmpl, 'function'); 21 | assert.deepEqual(Object.keys(tmpl), ['_setup', '_child']); 22 | assert.equal(typeof tmpl._setup, 'function'); 23 | assert.equal(typeof tmpl._child, 'function'); 24 | done(); 25 | }); 26 | }); 27 | }); 28 | 29 | describe('Render', function() { 30 | it('renders a simple template', function(done) { 31 | var engine = require('../index'); 32 | engine.compile('{{baz}}', {}, function(err, tmpl) { 33 | if (err) { 34 | return done(err); 35 | } 36 | engine.render(tmpl, {baz: 'bar'}, function(err, content) { 37 | if (err) { 38 | return done(err); 39 | } 40 | assert.equal(content, 'bar'); 41 | done(); 42 | }); 43 | }); 44 | }); 45 | 46 | // TODO: Fix this tests (the loading of helpers) 47 | it('renders a template with a helper', function(done) { 48 | var engine = require('../index'); 49 | engine.init({}); 50 | engine.compile('{{addCommas 2222222}}', {}, function(err, tmpl) { 51 | if (err) { 52 | return done(err); 53 | } 54 | engine.render(tmpl, {}, function(err, content) { 55 | if (err) { 56 | return done(err); 57 | } 58 | assert.equal(content, '2,222,222'); 59 | done(); 60 | }); 61 | }); 62 | }); 63 | }); 64 | 65 | describe('Register Function', function() { 66 | it('Creates a template object', function(done) { 67 | var engine = require('../index'); 68 | engine.registerFunctions({ 69 | test: function() { 70 | return 'test'; 71 | } 72 | }); 73 | engine.compile('{{test}}', {}, function(err, tmpl) { 74 | if (err) { 75 | return done(err); 76 | } 77 | engine.render(tmpl, {}, function(err, content) { 78 | if (err) { 79 | return done(err); 80 | } 81 | assert.equal(content, 'test'); 82 | done(); 83 | }); 84 | }); 85 | }); 86 | }); 87 | 88 | describe('Register Partial', function() { 89 | it('renders a template with a partial', function(done) { 90 | var engine = require('../index'); 91 | engine.registerPartial('head', 'foo'); 92 | engine.compile('{{>head}} bar', {}, function(err, tmpl) { 93 | if (err) { 94 | return done(err); 95 | } 96 | engine.render(tmpl, {}, function(err, content) { 97 | if (err) { 98 | return done(err); 99 | } 100 | assert.equal(content, 'foo bar'); 101 | done(); 102 | }); 103 | }); 104 | }); 105 | }); 106 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "modules": true, 4 | "experimentalObjectRestSpread": true 5 | }, 6 | 7 | "env": { 8 | "browser": false, 9 | "es6": true, 10 | "node": true, 11 | "mocha": true 12 | }, 13 | 14 | "globals": { 15 | "document": false, 16 | "navigator": false, 17 | "window": false 18 | }, 19 | 20 | "rules": { 21 | "accessor-pairs": 2, 22 | "arrow-spacing": [2, { "before": true, "after": true }], 23 | "block-spacing": [2, "always"], 24 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 25 | "comma-dangle": [2, "never"], 26 | "comma-spacing": [2, { "before": false, "after": true }], 27 | "comma-style": [2, "last"], 28 | "constructor-super": 2, 29 | "curly": [2, "multi-line"], 30 | "dot-location": [2, "property"], 31 | "eol-last": 2, 32 | "eqeqeq": [2, "allow-null"], 33 | "generator-star-spacing": [2, { "before": true, "after": true }], 34 | "handle-callback-err": [2, "^(err|error)$" ], 35 | "indent": [2, 2, { "SwitchCase": 1 }], 36 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 37 | "keyword-spacing": [2, { "before": true, "after": true }], 38 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 39 | "new-parens": 2, 40 | "no-array-constructor": 2, 41 | "no-caller": 2, 42 | "no-class-assign": 2, 43 | "no-cond-assign": 2, 44 | "no-const-assign": 2, 45 | "no-control-regex": 2, 46 | "no-debugger": 2, 47 | "no-delete-var": 2, 48 | "no-dupe-args": 2, 49 | "no-dupe-class-members": 2, 50 | "no-dupe-keys": 2, 51 | "no-duplicate-case": 2, 52 | "no-empty-character-class": 2, 53 | "no-eval": 2, 54 | "no-ex-assign": 2, 55 | "no-extend-native": 2, 56 | "no-extra-bind": 2, 57 | "no-extra-boolean-cast": 2, 58 | "no-extra-parens": [2, "functions"], 59 | "no-fallthrough": 2, 60 | "no-floating-decimal": 2, 61 | "no-func-assign": 2, 62 | "no-implied-eval": 2, 63 | "no-inner-declarations": [2, "functions"], 64 | "no-invalid-regexp": 2, 65 | "no-irregular-whitespace": 2, 66 | "no-iterator": 2, 67 | "no-label-var": 2, 68 | "no-labels": 2, 69 | "no-lone-blocks": 2, 70 | "no-mixed-spaces-and-tabs": 2, 71 | "no-multi-spaces": 2, 72 | "no-multi-str": 2, 73 | "no-multiple-empty-lines": [2, { "max": 1 }], 74 | "no-native-reassign": 0, 75 | "no-negated-in-lhs": 2, 76 | "no-new": 2, 77 | "no-new-func": 2, 78 | "no-new-object": 2, 79 | "no-new-require": 2, 80 | "no-new-wrappers": 2, 81 | "no-obj-calls": 2, 82 | "no-octal": 2, 83 | "no-octal-escape": 2, 84 | "no-proto": 0, 85 | "no-redeclare": 2, 86 | "no-regex-spaces": 2, 87 | "no-return-assign": 2, 88 | "no-self-compare": 2, 89 | "no-sequences": 2, 90 | "no-shadow-restricted-names": 2, 91 | "no-spaced-func": 2, 92 | "no-sparse-arrays": 2, 93 | "no-this-before-super": 2, 94 | "no-throw-literal": 2, 95 | "no-trailing-spaces": 0, 96 | "no-undef": 2, 97 | "no-undef-init": 2, 98 | "no-unexpected-multiline": 2, 99 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 100 | "no-unreachable": 2, 101 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 102 | "no-useless-call": 0, 103 | "no-with": 2, 104 | "one-var": [0, { "initialized": "never" }], 105 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 106 | "padded-blocks": [0, "never"], 107 | "quotes": [2, "single", "avoid-escape"], 108 | "radix": 2, 109 | "semi": [2, "always"], 110 | "semi-spacing": [2, { "before": false, "after": true }], 111 | "space-before-blocks": [2, "always"], 112 | "space-before-function-paren": [2, "never"], 113 | "space-in-parens": [2, "never"], 114 | "space-infix-ops": 2, 115 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 116 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 117 | "use-isnan": 2, 118 | "valid-typeof": 2, 119 | "wrap-iife": [2, "any"], 120 | "yoda": [2, "never"] 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # assemble-handlebars [![NPM version](https://img.shields.io/npm/v/assemble-handlebars.svg?style=flat)](https://www.npmjs.com/package/assemble-handlebars) [![NPM monthly downloads](https://img.shields.io/npm/dm/assemble-handlebars.svg?style=flat)](https://npmjs.org/package/assemble-handlebars) [![NPM total downloads](https://img.shields.io/npm/dt/assemble-handlebars.svg?style=flat)](https://npmjs.org/package/assemble-handlebars) [![Linux Build Status](https://img.shields.io/travis/assemble/assemble-handlebars.svg?style=flat&label=Travis)](https://travis-ci.org/assemble/assemble-handlebars) [![Windows Build Status](https://img.shields.io/appveyor/ci/assemble/assemble-handlebars.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/assemble/assemble-handlebars) 2 | 3 | > Handlebars engine plugin for grunt-assemble. This is only used in grunt-assemble and versions of assemble below 0.4.x. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | ```sh 10 | $ npm install --save assemble-handlebars 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```js 16 | var assembleHandlebars = require('assemble-handlebars'); 17 | ``` 18 | 19 | ## About 20 | 21 | ### Related projects 22 | 23 | * [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit") 24 | * [grunt-assemble](https://www.npmjs.com/package/grunt-assemble): Static site generator for Grunt.js, Yeoman and Node.js. Used by Zurb Foundation, Zurb Ink, H5BP/Effeckt… [more](http://assemble.io) | [homepage](http://assemble.io "Static site generator for Grunt.js, Yeoman and Node.js. Used by Zurb Foundation, Zurb Ink, H5BP/Effeckt, Less.js / lesscss.org, Topcoat, Web Experience Toolkit, and hundreds of other projects to build sites, themes, components, documentation, blogs and gh") 25 | * [grunt](https://www.npmjs.com/package/grunt): The JavaScript Task Runner | [homepage](http://gruntjs.com/ "The JavaScript Task Runner") 26 | * [handlebars-helpers](https://www.npmjs.com/package/handlebars-helpers): More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate… [more](https://github.com/assemble/handlebars-helpers) | [homepage](https://github.com/assemble/handlebars-helpers "More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.") 27 | 28 | ### Contributing 29 | 30 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 31 | 32 | ### Contributors 33 | 34 | | **Commits** | **Contributor** | 35 | | --- | --- | 36 | | 70 | [doowb](https://github.com/doowb) | 37 | | 26 | [jonschlinkert](https://github.com/jonschlinkert) | 38 | | 6 | [LaurentGoderre](https://github.com/LaurentGoderre) | 39 | | 2 | [adjohnson916](https://github.com/adjohnson916) | 40 | | 1 | [spacedawwwg](https://github.com/spacedawwwg) | 41 | 42 | ### Building docs 43 | 44 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ 45 | 46 | To generate the readme, run the following command: 47 | 48 | ```sh 49 | $ npm install -g verbose/verb#dev verb-generate-readme && verb 50 | ``` 51 | 52 | ### Running tests 53 | 54 | Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: 55 | 56 | ```sh 57 | $ npm install && npm test 58 | ``` 59 | 60 | ### Author 61 | 62 | **Brian Woodward** 63 | 64 | * [github/doowb](https://github.com/doowb) 65 | * [twitter/doowb](https://twitter.com/doowb) 66 | 67 | ### License 68 | 69 | Copyright © 2017, [Brian Woodward](https://github.com/doowb). 70 | Released under the [MIT License](LICENSE). 71 | 72 | *** 73 | 74 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.3, on March 17, 2017._ --------------------------------------------------------------------------------