├── .assemblerc.yml ├── .gitattributes ├── .gitignore ├── .jshintrc ├── .travis.yml ├── .verbrc.md ├── Gruntfile.js ├── LICENSE-MIT ├── README.md ├── index.js ├── package.json └── test ├── actual └── options_data │ ├── context-block.html │ ├── context-data-file.html │ ├── context-data.html │ ├── context-include-yfm-01.html │ ├── context-include-yfm-02.html │ ├── context-include-yfm-lodash.html │ ├── context-options.html │ ├── context-page-yfm.html │ ├── context-site.html │ ├── context-this-no-yfm.html │ ├── context-this-yfm.html │ ├── glob.html │ ├── multiple-yfm.html │ └── multiple.html ├── assets └── styles.css └── fixtures ├── context-block.hbs ├── context-data-file.hbs ├── context-data.hbs ├── context-include-yfm-01.hbs ├── context-include-yfm-02.hbs ├── context-include-yfm-lodash.hbs ├── context-options.hbs ├── context-page-yfm.hbs ├── context-site.hbs ├── context-this-no-yfm.hbs ├── context-this-yfm.hbs ├── data ├── bar.json ├── baz.json ├── explicit.json ├── foo.json ├── include.json ├── partial-data-file.json └── two.json ├── glob.hbs ├── includes ├── nested-yfm.hbs ├── nested.hbs ├── options-data.hbs ├── snippet-yfm-lodash.hbs ├── snippet-yfm.hbs └── snippet.hbs ├── multiple-yfm.hbs └── multiple.hbs /.assemblerc.yml: -------------------------------------------------------------------------------- 1 | ### 2 | # This file only exists for the purposes of 3 | # testing context with the {{partial}} helper. 4 | ### 5 | 6 | # Build 7 | root: _gh_pages 8 | dest: <%= site.root %> 9 | 10 | 11 | # Site metadata 12 | brand: ASSEMBLE 13 | title: Assemble 14 | lead: The most awe inspiring website in Northern Kentucky. 15 | description: > 16 | Static site generator for Grunt.js and Yeoman. Assemble makes it dead simple to build modular sites, 17 | blogs, gh-pages, components and documentation from reusable templates and data. 18 | license: 19 | type: MIT License 20 | url: ./license/index.html 21 | 22 | 23 | # URLs 24 | repo: https://github.com/assemble/assemble 25 | download: 26 | source: https://github.com/assemble/assemble/archive/master.zip -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | *.* text eol=lf 3 | *.css text eol=lf 4 | *.html text eol=lf 5 | *.js text eol=lf 6 | *.json text eol=lf 7 | *.less text eol=lf 8 | *.md text eol=lf 9 | *.yml text eol=lf 10 | 11 | *.jpg binary 12 | *.gif binary 13 | *.png binary 14 | *.jpeg binary -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Numerous always-ignore extensions 2 | *.csv 3 | *.dat 4 | *.diff 5 | *.err 6 | *.gz 7 | *.log 8 | *.orig 9 | *.out 10 | *.pid 11 | *.rar 12 | *.rej 13 | *.seed 14 | *.swo 15 | *.swp 16 | *.vi 17 | *.yo-rc.json 18 | *.zip 19 | *~ 20 | .ruby-version 21 | lib-cov 22 | npm-debug.log 23 | 24 | # Always-ignore dirs 25 | /bower_components/ 26 | /node_modules/ 27 | /temp/ 28 | /tmp/ 29 | /vendor/ 30 | _gh_pages 31 | 32 | # OS or Editor folders 33 | *.esproj 34 | *.komodoproject 35 | .komodotools 36 | *.sublime-* 37 | ._* 38 | .cache 39 | .DS_Store 40 | .idea 41 | .project 42 | .settings 43 | .tmproj 44 | nbproject 45 | Thumbs.db 46 | 47 | # grunt-html-validation 48 | validation-status.json 49 | validation-report.json 50 | 51 | # misc 52 | TODO.md -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "asi": false, 3 | "boss": true, 4 | "curly": true, 5 | "eqeqeq": true, 6 | "eqnull": true, 7 | "esnext": true, 8 | "immed": true, 9 | "latedef": true, 10 | "laxcomma": false, 11 | "newcap": true, 12 | "noarg": true, 13 | "node": true, 14 | "sub": true, 15 | "undef": true, 16 | "unused": true, 17 | "globals": { 18 | "define": true, 19 | "before": true, 20 | "after": true, 21 | "describe": true, 22 | "it": true 23 | } 24 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '0.10' -------------------------------------------------------------------------------- /.verbrc.md: -------------------------------------------------------------------------------- 1 | # {%= name %} {%= badge("fury") %} 2 | 3 | > {%= description %} 4 | 5 | ## Install 6 | Use [npm](npmjs.org) to install the package: `npm i {%= name %}`. 7 | 8 | ## Register the helper 9 | 10 | Register the helper in the `assemble` task in your project's Gruntfile to begin using it in templates: 11 | 12 | ```javascript 13 | grunt.initConfig({ 14 | assemble: { 15 | options: { 16 | // the '{%= name %}' npm module must also be listed in 17 | // devDependencies for assemble to automatically resolve the helper 18 | helpers: ['{%= name %}', 'foo/*.js'] 19 | }, 20 | files: { 21 | '_gh_pages/': ['templates/*.hbs'] 22 | } 23 | } 24 | }); 25 | ``` 26 | 27 | ## Usage 28 | 29 | ### Register includes 30 | 31 | Tell assemble where to find the includes by adding an `includes` property to the task options: 32 | 33 | ```javascript 34 | assemble: { 35 | options: { 36 | includes: ['abc.hbs', 'xyz.hbs', 'foo/*.hbs'] 37 | }, 38 | files: { 39 | '_gh_pages/': ['templates/*.hbs'] 40 | } 41 | } 42 | ``` 43 | 44 | ### Use in templates 45 | 46 | Define the name of the helper to include, without file extension: 47 | 48 | ```html 49 | {{include 'abc'}} 50 | ``` 51 | 52 | Optionally pass a context as the second parameter: 53 | 54 | ```html 55 | {{include 'xyz' this}} 56 | ``` 57 | 58 | ### Wildcard patterns 59 | 60 | Globbing patterns may also be used: 61 | 62 | ```html 63 | {{include 'chapter-*'}} 64 | ``` 65 | 66 | ## Contributing 67 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue]({%= bugs.url %}) 68 | 69 | ## Author 70 | {%= include("author") %} 71 | 72 | ## License 73 | {%= copyright() %} 74 | {%= license() %} 75 | 76 | *** 77 | 78 | {%= include("footer") %} 79 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /* 2 | * helper-include 3 | * 4 | * Copyright (c) 2014 Jon Schlinkert, contributors 5 | * Licensed under the MIT license. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | module.exports = function(grunt) { 11 | 12 | // Project configuration. 13 | grunt.initConfig({ 14 | pkg : grunt.file.readJSON('package.json'), 15 | site: grunt.file.readYAML('.assemblerc.yml'), 16 | 17 | jshint: { 18 | all: ['Gruntfile.js', 'test/*.js', '*.js'], 19 | options: { 20 | jshintrc: '.jshintrc' 21 | } 22 | }, 23 | 24 | title: 'this title is from the config (root context).', 25 | description: 'this description is from the config (root context).', 26 | 27 | // Pull down a list of repos from Github. 28 | assemble: { 29 | options: { 30 | flatten: true, 31 | site: '<%= site %>', 32 | subtitle: 'This subtitle is a custom property in the Assemble options', 33 | 34 | // Ensure that assets path calculates properly 35 | assets: 'test/assets', 36 | data: ['test/fixtures/data/*.json'], 37 | includes: ['test/fixtures/includes/*.hbs'], 38 | helpers: ['index.js'], 39 | }, 40 | 41 | tests: { 42 | options: { 43 | title: 'this title is from the options.', 44 | description: 'this description is from the options.' 45 | }, 46 | files: { 47 | 'test/actual/options_data/': ['test/fixtures/*.hbs'] 48 | } 49 | } 50 | }, 51 | 52 | clean: { 53 | test: ['test/actual/**/*.html'] 54 | } 55 | }); 56 | 57 | // These plugins provide necessary tasks. 58 | grunt.loadNpmTasks('grunt-contrib-jshint'); 59 | grunt.loadNpmTasks('grunt-contrib-clean'); 60 | grunt.loadNpmTasks('assemble'); 61 | 62 | // By default, lint and run all tests. 63 | grunt.registerTask('default', ['jshint', 'clean', 'assemble']); 64 | 65 | }; 66 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Jon Schlinkert 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # handlebars-helper-include [![NPM version](https://badge.fury.io/js/handlebars-helper-include.svg)](http://badge.fury.io/js/handlebars-helper-include) 2 | 3 | > Handlebars helper for using includes. 4 | 5 | ## Install 6 | Use [npm](npmjs.org) to install the package: `npm i handlebars-helper-include`. 7 | 8 | ## Register the helper 9 | 10 | Register the helper in the `assemble` task in your project's Gruntfile to begin using it in templates: 11 | 12 | ```javascript 13 | grunt.initConfig({ 14 | assemble: { 15 | options: { 16 | // the 'handlebars-helper-include' npm module must also be listed in 17 | // devDependencies for assemble to automatically resolve the helper 18 | helpers: ['handlebars-helper-include', 'foo/*.js'] 19 | }, 20 | files: { 21 | '_gh_pages/': ['templates/*.hbs'] 22 | } 23 | } 24 | }); 25 | ``` 26 | 27 | ## Usage 28 | 29 | ### Register includes 30 | 31 | Tell assemble where to find the includes by adding an `includes` property to the task options: 32 | 33 | ```javascript 34 | assemble: { 35 | options: { 36 | includes: ['abc.hbs', 'xyz.hbs', 'foo/*.hbs'] 37 | }, 38 | files: { 39 | '_gh_pages/': ['templates/*.hbs'] 40 | } 41 | } 42 | ``` 43 | 44 | ### Use in templates 45 | 46 | Define the name of the helper to include, without file extension: 47 | 48 | ```html 49 | {{include 'abc'}} 50 | ``` 51 | 52 | Optionally pass a context as the second parameter: 53 | 54 | ```html 55 | {{include 'xyz' this}} 56 | ``` 57 | 58 | ### Wildcard patterns 59 | 60 | Globbing patterns may also be used: 61 | 62 | ```html 63 | {{include 'chapter-*'}} 64 | ``` 65 | 66 | ## Contributing 67 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/helpers/handlebars-helper-include/issues) 68 | 69 | ## Author 70 | 71 | **Jon Schlinkert** 72 | 73 | + [github/helpers](https://github.com/helpers) 74 | + [twitter/helpers](http://twitter.com/helpers) 75 | 76 | ## License 77 | Copyright (c) 2014 Jon Schlinkert, contributors. 78 | Released under the MIT license 79 | 80 | *** 81 | 82 | _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on November 09, 2014._ -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var mapFiles = require('map-files'); 4 | var filterKeys = require('filter-keys'); 5 | var matter = require('gray-matter'); 6 | var _ = require('lodash'); 7 | var extend = _.extend; 8 | 9 | 10 | /** 11 | * {{include}}, alternative to {{> partial }} 12 | * 13 | * @param {String} `name` The name of the partial to use 14 | * @param {Object} `context` The context to pass to the partial 15 | * @return {String} Returns compiled HTML 16 | * @xample: {{include 'foo' bar}} 17 | */ 18 | 19 | module.exports.register = function (Handlebars, options, params) { 20 | var assemble = params.assemble; 21 | var grunt = params.grunt; 22 | 23 | // Assemble options 24 | var opts = options || {}; 25 | var dataFiles = grunt.config.data; 26 | 27 | // Allow the `includes` property to be used on the options 28 | var includes = mapFiles(opts.includes || assemble.partials); 29 | 30 | includes = _.reduce(includes, function (acc, value, key) { 31 | var o = matter(value.content); 32 | acc[key] = extend(value, o); 33 | return acc; 34 | }, {}); 35 | 36 | Handlebars.registerHelper('include', function(pattern, locals) { 37 | if (Object.keys(includes).length === 0) { 38 | return ''; 39 | } 40 | 41 | var matches = filterKeys(includes, pattern); 42 | var len = matches.length; 43 | var i = 0; 44 | 45 | if (len === 0) { 46 | return ''; 47 | } 48 | 49 | var stack = ''; 50 | 51 | while (i < len) { 52 | var name = matches[i++]; 53 | var include = includes[name]; 54 | 55 | // `context` = the given context (second parameter) 56 | // `metadata` = YAML front matter of the include 57 | // `opts.data[name]` = JSON/YAML data file defined in Assemble options.data 58 | // with a basename matching the name of the include, e.g 59 | // {{include 'foo'}} => foo.json 60 | // `this` = Typically either YAML front matter of the "inheriting" page, 61 | // layout, block expression, or "parent" helper wrapping this helper 62 | // `opts` = Custom properties defined in Assemble options 63 | // `grunt.config.data` = Data from grunt.config.data 64 | // (e.g. pkg: grunt.file.readJSON('package.json')) 65 | 66 | var context = {}; 67 | extend(context, this); 68 | extend(context, opts); 69 | extend(context, dataFiles); 70 | extend(context, opts.data[name]); 71 | extend(context, include.data); 72 | extend(context, locals); 73 | 74 | context = grunt.config.process(context); 75 | 76 | var fn = Handlebars.compile(include.content); 77 | var res = fn(context); 78 | 79 | // Prepend result with the filepath to the original include 80 | var includeOpts = opts.include || opts.data.include || {}; 81 | if(includeOpts.origin === true) { 82 | res = '\n' + res; 83 | } 84 | 85 | stack += res; 86 | } 87 | 88 | return new Handlebars.SafeString(stack.replace(/^\s+|\s+$/g, '')); 89 | }); 90 | }; 91 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "handlebars-helper-include", 3 | "description": "Handlebars helper for using includes.", 4 | "version": "0.2.0", 5 | "homepage": "https://github.com/helpers/handlebars-helper-include", 6 | "author": { 7 | "name": "Jon Schlinkert", 8 | "url": "https://github.com/jonschlinkert" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git://github.com/helpers/handlebars-helper-include.git" 13 | }, 14 | "bugs": { 15 | "url": "https://github.com/helpers/handlebars-helper-include/issues" 16 | }, 17 | "licenses": [ 18 | { 19 | "type": "MIT", 20 | "url": "https://github.com/helpers/handlebars-helper-include/blob/master/LICENSE-MIT" 21 | } 22 | ], 23 | "main": "index.js", 24 | "engines": { 25 | "node": ">=0.10.0" 26 | }, 27 | "devDependencies": { 28 | "assemble": "^0.4.42", 29 | "grunt": "^0.4.5", 30 | "mocha": "*", 31 | "verb": ">= 0.2.6", 32 | "grunt-contrib-clean": "^0.6.0", 33 | "grunt-contrib-jshint": "^0.10.0" 34 | }, 35 | "keywords": [ 36 | "assemble", 37 | "handlebars", 38 | "helper", 39 | "include", 40 | "partial", 41 | "templates", 42 | "view" 43 | ], 44 | "dependencies": { 45 | "filter-keys": "^0.1.2", 46 | "gray-matter": "^0.5.3", 47 | "lodash": "^2.4.1", 48 | "map-files": "^0.2.1" 49 | } 50 | } -------------------------------------------------------------------------------- /test/actual/options_data/context-block.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
5 | this title is from the config (root context). 6 | 7 |
8 |

9 |
10 | -------------------------------------------------------------------------------- /test/actual/options_data/context-data-file.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
5 | this title is from the config (root context). 6 |
7 |

this description is from the config (root context).

8 |
-------------------------------------------------------------------------------- /test/actual/options_data/context-data.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 | this title is from the config (root context). 5 | This title is from FOO.json 6 |
7 |

This description is from FOO.json

8 |
9 | 10 | 11 | 12 |
13 |
14 | this title is from the config (root context). 15 | 16 |
17 |

18 |
19 | -------------------------------------------------------------------------------- /test/actual/options_data/context-include-yfm-01.html: -------------------------------------------------------------------------------- 1 | This should use the YFM data from the include. 2 | 3 | 4 |
5 |
6 | This title is from the INCLUDE YFM (include-yfm.hbs) 7 |
8 |

This description is from the INCLUDE YFM

9 |
10 | -------------------------------------------------------------------------------- /test/actual/options_data/context-include-yfm-02.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Should use the YFM data from the include. 4 | 5 | 6 |
7 |
8 | This title is from the INCLUDE YFM (include-yfm.hbs) 9 |
10 |

This description is from the INCLUDE YFM

11 |
-------------------------------------------------------------------------------- /test/actual/options_data/context-include-yfm-lodash.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
5 | Assemble => Assemble 6 |
7 |

Static site generator for Grunt.js and Yeoman. Assemble makes it dead simple to build modular sites, blogs, gh-pages, components and documentation from reusable templates and data. 8 |

9 |

Static site generator for Grunt.js and Yeoman. Assemble makes it dead simple to build modular sites, blogs, gh-pages, components and documentation from reusable templates and data. 10 |

11 |
12 | 13 | Note that the YAML front matter is "borrowing" data from the site object, which is defined in the Grunt config. 14 | 15 | So in this example, {{title}} will yield the same result as {{site.title}}, and {{description}} will 16 | yield the same result as {{site.description}} -------------------------------------------------------------------------------- /test/actual/options_data/context-options.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 | this title is from the config (root context). 5 | This title is from FOO.json 6 |
7 |

This description is from FOO.json

8 |
-------------------------------------------------------------------------------- /test/actual/options_data/context-page-yfm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Context is page, include does not have front-matter. 4 | 5 | 6 |
7 |
8 | This title is from the PAGE YFM (page-yfm.hbs) 9 |
10 |

This description is from the PAGE YFM

11 |
12 | 13 | 14 | Context is this, include does not have front-matter. 15 | 16 | 17 |
18 |
19 | This title is from the PAGE YFM (page-yfm.hbs) 20 |
21 |

This description is from the PAGE YFM

22 |
23 | 24 | 25 | Context is page, include has front-matter. 26 | 27 | 28 |
29 |
30 | This title is from the PAGE YFM (page-yfm.hbs) 31 |
32 |

This description is from the PAGE YFM

33 |
34 | 35 | Context is this, include has front-matter. 36 | 37 | 38 |
39 |
40 | This title is from the PAGE YFM (page-yfm.hbs) 41 |
42 |

This description is from the PAGE YFM

43 |
44 | -------------------------------------------------------------------------------- /test/actual/options_data/context-site.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 | Assemble 5 |
6 |

Static site generator for Grunt.js and Yeoman. Assemble makes it dead simple to build modular sites, blogs, gh-pages, components and documentation from reusable templates and data. 7 |

8 |
-------------------------------------------------------------------------------- /test/actual/options_data/context-this-no-yfm.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 | this title is from the options. 5 |
6 |

this description is from the options.

7 |
-------------------------------------------------------------------------------- /test/actual/options_data/context-this-yfm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
5 | This title is from the PAGE YFM (page-yfm.hbs) 6 |
7 |

This description is from the PAGE YFM

8 |
9 | -------------------------------------------------------------------------------- /test/actual/options_data/glob.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helpers/handlebars-helper-include/84491633b3b9b421383d3a518ea88246e3f5e8dd/test/actual/options_data/glob.html -------------------------------------------------------------------------------- /test/actual/options_data/multiple-yfm.html: -------------------------------------------------------------------------------- 1 | 2 |

explicit context

3 | Should be from explicit.json 4 | 5 |
6 |
7 | This title is from EXPLICIT.json 8 |
9 |

This description is from EXPLICIT.json

10 |
11 | 12 | 13 |

page context

14 | Should be from the YFM of the page 15 | 16 |
17 |
18 | This title is from PAGE YFM (multiple.hbs) 19 |
20 |

This description is from PAGE YFM (multiple.hbs)

21 |
22 | 23 | 24 |

this context

25 | Should be from the YFM of the page 26 | 27 |
28 |
29 | This title is from PAGE YFM (multiple.hbs) 30 |
31 |

This description is from PAGE YFM (multiple.hbs)

32 |
33 | 34 | 35 |
36 |
37 |
38 |
39 | 40 | 41 |

snippet context

42 | Should be from the YFM of the include, snippet 43 | 44 |
45 |
46 | This title is from the INCLUDE YFM (include-yfm.hbs) 47 |
48 |

This description is from the INCLUDE YFM

49 |
50 | 51 | 52 | 53 |

snippet (lodash) context

54 | Should be resolved from the lodash templates in the YFM of the include, snippet 55 | 56 |
57 |
58 | Assemble => Assemble 59 |
60 |

Static site generator for Grunt.js and Yeoman. Assemble makes it dead simple to build modular sites, blogs, gh-pages, components and documentation from reusable templates and data. 61 |

62 |

Static site generator for Grunt.js and Yeoman. Assemble makes it dead simple to build modular sites, blogs, gh-pages, components and documentation from reusable templates and data. 63 |

64 |
65 | 66 | Note that the YAML front matter is "borrowing" data from the site object, which is defined in the Grunt config. 67 | 68 | So in this example, {{title}} will yield the same result as {{site.title}}, and {{description}} will 69 | yield the same result as {{site.description}} 70 | 71 | 72 |
73 |
74 |
75 |
76 | 77 | 78 |

this context

79 | Should be from the YFM of the page 80 | 81 |
82 |
83 | This title is from PAGE YFM (multiple.hbs) 84 |
85 |

This description is from PAGE YFM (multiple.hbs)

86 |
87 | 88 | 89 |

wrapper context

90 | Should be from the wrapper 91 | 92 | 93 |
94 |
95 | WRAPPER YFM 96 |
97 |

WRAPPER DESCRIPTION

98 |
99 | 100 | 101 |

wrapper context

102 | Should be from the wrapper 103 | 104 | 105 |
106 |
107 | WRAPPER YFM 108 |
109 |

WRAPPER DESCRIPTION

110 |
111 | 112 | 113 |

page context

114 | Should be from the YFM of the page 115 | 116 |
117 |
118 | This title is from PAGE YFM (multiple.hbs) 119 |
120 |

This description is from PAGE YFM (multiple.hbs)

121 |
122 | 123 | 124 |

include yfm context

125 | Should be from the YFM of the include 126 | 127 |
128 |
129 | This title is from the INCLUDE YFM (include-yfm.hbs) 130 |
131 |

This description is from the INCLUDE YFM

132 |
133 | 134 | 135 |
136 |
137 |
138 |
139 | 140 | 141 |

data file context

142 | Should be from the bar.json data file 143 | 144 | 145 | 146 |
147 |
148 | This title is from BAR.json 149 |
150 |

This description is from BAR.json

151 |
152 | 153 | 154 | 155 |

parent context

156 | Should be from the page. 157 | 158 | 159 | 160 |
161 |
162 | This title is from PAGE YFM (multiple.hbs) 163 |
164 |

This description is from PAGE YFM (multiple.hbs)

165 |
166 | 167 | 168 | 169 |

parent context

170 | Should be from the page. 171 | 172 | 173 | 174 |
175 |
176 | This title is from PAGE YFM (multiple.hbs) 177 |
178 |

This description is from PAGE YFM (multiple.hbs)

179 |
180 | 181 | 182 | 183 |

nested includes

184 | 185 | 186 |
187 |
188 | this title is from the config (root context). 189 |
190 |

this description is from the config (root context).

191 |
192 | 193 | 194 |
195 |
196 | this title is from the config (root context). 197 |
198 |

this description is from the config (root context).

199 |
200 | 201 |

nested includes with YFM

202 | 203 | 204 |
205 |
206 | Title for include NESTED-YFM.HBS 207 |
208 |

Description for include NESTED-YFM.HBS

209 |
210 | 211 | 212 |
213 |
214 | this title is from the config (root context). 215 |
216 |

this description is from the config (root context).

217 |
218 | -------------------------------------------------------------------------------- /test/actual/options_data/multiple.html: -------------------------------------------------------------------------------- 1 |

explicit context

2 | Should be from explicit.json 3 | 4 |
5 |
6 | This title is from EXPLICIT.json 7 |
8 |

This description is from EXPLICIT.json

9 |
10 | 11 | 12 |

root context

13 | Should be from the root context. (this page has no front matter, so `page` falls back on the root context) 14 | 15 |
16 |
17 | this title is from the config (root context). 18 |
19 |

this description is from the config (root context).

20 |
21 | 22 | 23 |

options context

24 | Should be from the options. (this page has no front matter, so `this` falls back on the `options` context) 25 | 26 |
27 |
28 | this title is from the options. 29 |
30 |

this description is from the options.

31 |
32 | 33 | 34 |
35 |
36 |
37 |
38 | 39 | 40 |

snippet context

41 | Should be from the YFM of the include, snippet 42 | 43 |
44 |
45 | This title is from the INCLUDE YFM (include-yfm.hbs) 46 |
47 |

This description is from the INCLUDE YFM

48 |
49 | 50 | 51 | 52 |

snippet (lodash) context

53 | Should be resolved from the lodash templates in the YFM of the include, snippet 54 | 55 |
56 |
57 | Assemble => Assemble 58 |
59 |

Static site generator for Grunt.js and Yeoman. Assemble makes it dead simple to build modular sites, blogs, gh-pages, components and documentation from reusable templates and data. 60 |

61 |

Static site generator for Grunt.js and Yeoman. Assemble makes it dead simple to build modular sites, blogs, gh-pages, components and documentation from reusable templates and data. 62 |

63 |
64 | 65 | Note that the YAML front matter is "borrowing" data from the site object, which is defined in the Grunt config. 66 | 67 | So in this example, {{title}} will yield the same result as {{site.title}}, and {{description}} will 68 | yield the same result as {{site.description}} 69 | 70 | 71 |
72 |
73 |
74 |
75 | 76 | 77 | 78 |

include yfm context

79 | Should be from the YFM of the include 80 | 81 |
82 |
83 | This title is from the INCLUDE YFM (include-yfm.hbs) 84 |
85 |

This description is from the INCLUDE YFM

86 |
87 | 88 | 89 |
90 |
91 |
92 |
93 | 94 | 95 |

data file context

96 | Should be from the bar.json data file 97 | 98 | 99 | 100 |
101 |
102 | This title is from BAR.json 103 |
104 |

This description is from BAR.json

105 |
106 | 107 | 108 | 109 |

parent context

110 | Should be from the options. 111 | 112 | 113 | 114 |
115 |
116 | this title is from the options. 117 |
118 |

this description is from the options.

119 |
120 | 121 | 122 | 123 |

parent context

124 | Should be from the root context. 125 | 126 | 127 | 128 |
129 |
130 | this title is from the config (root context). 131 |
132 |

this description is from the config (root context).

133 |
134 | 135 | -------------------------------------------------------------------------------- /test/assets/styles.css: -------------------------------------------------------------------------------- 1 | article { 2 | background: #eee; 3 | } -------------------------------------------------------------------------------- /test/fixtures/context-block.hbs: -------------------------------------------------------------------------------- 1 | {{#foo}} 2 | {{include 'options-data'}} 3 | {{/foo}} -------------------------------------------------------------------------------- /test/fixtures/context-data-file.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | title: This title is from the PAGE YFM (include-data-file.hbs) 3 | description: This description is from the PAGE YFM 4 | --- 5 | {{include 'snippet' data}} -------------------------------------------------------------------------------- /test/fixtures/context-data.hbs: -------------------------------------------------------------------------------- 1 | {{include 'options-data'}} 2 | 3 | {{#foo}} 4 | {{include 'options-data'}} 5 | {{/foo}} -------------------------------------------------------------------------------- /test/fixtures/context-include-yfm-01.hbs: -------------------------------------------------------------------------------- 1 | This should use the YFM data from the include. 2 | 3 | {{include 'snippet-yfm'}} 4 | -------------------------------------------------------------------------------- /test/fixtures/context-include-yfm-02.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | title: This title is from the PAGE YFM (include-yfm.hbs) 3 | description: This description is from the PAGE YFM 4 | --- 5 | 6 | Should use the YFM data from the include. 7 | 8 | {{include 'snippet-yfm'}} -------------------------------------------------------------------------------- /test/fixtures/context-include-yfm-lodash.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | title: This title is from the PAGE YFM (include-yfm.hbs) 3 | description: This description is from the PAGE YFM 4 | --- 5 | {{include 'snippet-yfm-lodash'}} -------------------------------------------------------------------------------- /test/fixtures/context-options.hbs: -------------------------------------------------------------------------------- 1 | {{include 'options-data'}} -------------------------------------------------------------------------------- /test/fixtures/context-page-yfm.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | title: This title is from the PAGE YFM (page-yfm.hbs) 3 | description: This description is from the PAGE YFM 4 | --- 5 | 6 | Context is page, include does not have front-matter. 7 | 8 | {{include 'snippet' page}} 9 | 10 | 11 | Context is this, include does not have front-matter. 12 | 13 | {{include 'snippet' this}} 14 | 15 | 16 | Context is page, include has front-matter. 17 | 18 | {{include 'snippet-yfm' page}} 19 | 20 | Context is this, include has front-matter. 21 | 22 | {{include 'snippet-yfm' this}} 23 | -------------------------------------------------------------------------------- /test/fixtures/context-site.hbs: -------------------------------------------------------------------------------- 1 | {{include 'snippet' site}} -------------------------------------------------------------------------------- /test/fixtures/context-this-no-yfm.hbs: -------------------------------------------------------------------------------- 1 | {{include 'snippet' this}} -------------------------------------------------------------------------------- /test/fixtures/context-this-yfm.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | title: This title is from the PAGE YFM (page-yfm.hbs) 3 | description: This description is from the PAGE YFM 4 | --- 5 | {{include 'snippet' this}} 6 | -------------------------------------------------------------------------------- /test/fixtures/data/bar.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "This title is from BAR.json", 3 | "description": "This description is from BAR.json", 4 | "lead": "This lead is from BAR.json" 5 | } -------------------------------------------------------------------------------- /test/fixtures/data/baz.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "JSON BAZ.JSON" 3 | } -------------------------------------------------------------------------------- /test/fixtures/data/explicit.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "This title is from EXPLICIT.json", 3 | "description": "This description is from EXPLICIT.json" 4 | } -------------------------------------------------------------------------------- /test/fixtures/data/foo.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "This title is from FOO.json", 3 | "description": "This description is from FOO.json" 4 | } -------------------------------------------------------------------------------- /test/fixtures/data/include.json: -------------------------------------------------------------------------------- 1 | { 2 | "origin": true 3 | } -------------------------------------------------------------------------------- /test/fixtures/data/partial-data-file.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "This title is from include-DATA-FILE.json", 3 | "description": "This description is from include-DATA-FILE.json" 4 | } -------------------------------------------------------------------------------- /test/fixtures/data/two.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "JSON TWO.JSON" 3 | } -------------------------------------------------------------------------------- /test/fixtures/glob.hbs: -------------------------------------------------------------------------------- 1 | {{include '**/include-*'}} -------------------------------------------------------------------------------- /test/fixtures/includes/nested-yfm.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | title: Title for include NESTED-YFM.HBS 3 | description: Description for include NESTED-YFM.HBS 4 | --- 5 |
6 |
7 | {{title}} 8 |
9 |

{{description}}

10 |
11 | 12 | {{include 'snippet' data}} -------------------------------------------------------------------------------- /test/fixtures/includes/nested.hbs: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{title}} 4 |
5 |

{{description}}

6 |
7 | 8 | {{include 'snippet'}} -------------------------------------------------------------------------------- /test/fixtures/includes/options-data.hbs: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{title}} 4 | {{foo.title}} 5 |
6 |

{{foo.description}}

7 |
-------------------------------------------------------------------------------- /test/fixtures/includes/snippet-yfm-lodash.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | title: <%= site.title %> 3 | description: <%= site.description %> 4 | --- 5 |
6 |
7 | {{title}} => {{site.title}} 8 |
9 |

{{description}}

10 |

{{site.description}}

11 |
12 | 13 | Note that the YAML front matter is "borrowing" data from the site object, which is defined in the Grunt config. 14 | 15 | So in this example, \{{title}} will yield the same result as \{{site.title}}, and \{{description}} will 16 | yield the same result as \{{site.description}} -------------------------------------------------------------------------------- /test/fixtures/includes/snippet-yfm.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | title: This title is from the INCLUDE YFM (include-yfm.hbs) 3 | description: This description is from the INCLUDE YFM 4 | --- 5 |
6 |
7 | {{title}} 8 |
9 |

{{description}}

10 |
-------------------------------------------------------------------------------- /test/fixtures/includes/snippet.hbs: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{title}} 4 |
5 |

{{description}}

6 |
-------------------------------------------------------------------------------- /test/fixtures/multiple-yfm.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | title: This title is from PAGE YFM (multiple.hbs) 3 | description: This description is from PAGE YFM (multiple.hbs) 4 | lead: This lead is from PAGE YFM (multiple.hbs) 5 | quux: This property is from PAGE YFM (multiple.hbs) 6 | wrapper: 7 | title: WRAPPER YFM 8 | description: WRAPPER DESCRIPTION 9 | --- 10 |

explicit context

11 | Should be from explicit.json 12 | {{include 'snippet' explicit}} 13 | 14 | 15 |

page context

16 | Should be from the YFM of the page 17 | {{include 'snippet' page}} 18 | 19 | 20 |

this context

21 | Should be from the YFM of the page 22 | {{include 'snippet' this}} 23 | 24 | 25 |
26 |
27 |
28 |
29 | 30 | 31 |

snippet context

32 | Should be from the YFM of the include, snippet 33 | {{include 'snippet-yfm'}} 34 | 35 | 36 | 37 |

snippet (lodash) context

38 | Should be resolved from the lodash templates in the YFM of the include, snippet 39 | {{include 'snippet-yfm-lodash'}} 40 | 41 | 42 |
43 |
44 |
45 |
46 | 47 | 48 |

this context

49 | Should be from the YFM of the page 50 | {{include 'snippet-yfm' this}} 51 | 52 | 53 |

wrapper context

54 | Should be from the wrapper 55 | {{#wrapper}} 56 | {{include 'snippet-yfm' this}} 57 | {{/wrapper}} 58 | 59 |

wrapper context

60 | Should be from the wrapper 61 | 62 | {{include 'snippet-yfm' wrapper}} 63 | 64 | 65 |

page context

66 | Should be from the YFM of the page 67 | {{include 'snippet-yfm' page}} 68 | 69 | 70 |

include yfm context

71 | Should be from the YFM of the include 72 | {{include 'snippet-yfm' data}} 73 | 74 | 75 |
76 |
77 |
78 |
79 | 80 | 81 |

data file context

82 | Should be from the bar.json data file 83 | 84 | {{#bar}} 85 | {{include 'snippet' this}} 86 | {{/bar}} 87 | 88 | 89 |

parent context

90 | Should be from the page. 91 | 92 | {{#bar}} 93 | {{include 'snippet' ../this}} 94 | {{/bar}} 95 | 96 | 97 |

parent context

98 | Should be from the page. 99 | 100 | {{#bar}} 101 | {{include 'snippet' ../page}} 102 | {{/bar}} 103 | 104 | 105 |

nested includes

106 | 107 | {{include 'nested' data}} 108 | 109 |

nested includes with YFM

110 | 111 | {{include 'nested-yfm'}} 112 | -------------------------------------------------------------------------------- /test/fixtures/multiple.hbs: -------------------------------------------------------------------------------- 1 |

explicit context

2 | Should be from explicit.json 3 | {{include 'snippet' explicit}} 4 | 5 | 6 |

root context

7 | Should be from the root context. (this page has no front matter, so `page` falls back on the root context) 8 | {{include 'snippet' page}} 9 | 10 | 11 |

options context

12 | Should be from the options. (this page has no front matter, so `this` falls back on the `options` context) 13 | {{include 'snippet' this}} 14 | 15 | 16 |
17 |
18 |
19 |
20 | 21 | 22 |

snippet context

23 | Should be from the YFM of the include, snippet 24 | {{include 'snippet-yfm'}} 25 | 26 | 27 | 28 |

snippet (lodash) context

29 | Should be resolved from the lodash templates in the YFM of the include, snippet 30 | {{include 'snippet-yfm-lodash'}} 31 | 32 | 33 |
34 |
35 |
36 |
37 | 38 | 39 | 40 |

include yfm context

41 | Should be from the YFM of the include 42 | {{include 'snippet-yfm' data}} 43 | 44 | 45 |
46 |
47 |
48 |
49 | 50 | 51 |

data file context

52 | Should be from the bar.json data file 53 | 54 | {{#bar}} 55 | {{include 'snippet' this}} 56 | {{/bar}} 57 | 58 | 59 |

parent context

60 | Should be from the options. 61 | 62 | {{#bar}} 63 | {{include 'snippet' ../this}} 64 | {{/bar}} 65 | 66 | 67 |

parent context

68 | Should be from the root context. 69 | 70 | {{#bar}} 71 | {{include 'snippet' ../page}} 72 | {{/bar}} 73 | --------------------------------------------------------------------------------