--------------------------------------------------------------------------------
/test/fixtures/data/example.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "This is the title from example.json",
3 | "text": "This is text from example.json."
4 | }
5 |
--------------------------------------------------------------------------------
/test/fixtures/data/home.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "This title is from a JSON file.",
3 | "description": "This description is from a JSON file."
4 | }
--------------------------------------------------------------------------------
/test/fixtures/pages/globlayout/globlayout.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | title: Using a glob layout
3 | layout: layout-globlayout.hbs
4 | ---
5 |
Hello: {{title}}
--------------------------------------------------------------------------------
/test/fixtures/pages/no-yfm.hbs:
--------------------------------------------------------------------------------
1 | There is no YAML front matter in this page.
2 |
3 |
{{noyfm.one}}
4 |
{{noyfm.two}}
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.github/contributing.md:
--------------------------------------------------------------------------------
1 | Please see the [Contributing to Assemble](http://assemble.io/contributing) guide for information on contributing to this project.
2 |
--------------------------------------------------------------------------------
/test/fixtures/pages/nested/nested-layouts.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | title: Home Page
3 | layout: two.hbs
4 | categories:
5 | - layouts
6 | ---
7 |
10 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Set default behaviour, in case users don't have core.autocrlf set.
2 | * text=lf
3 | * text eol=lf
4 | *.* eol=lf
5 |
6 | *.jpg binary
7 | *.gif binary
8 | *.png binary
9 | *.jpeg binary
--------------------------------------------------------------------------------
/test/fixtures/pages/yfm/comments.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | # This is a Comment
3 | title: Comments in YAML front matter
4 | ---
5 |
6 |
{{{title}}}
7 |
8 |
9 | Nothing.
--------------------------------------------------------------------------------
/test/fixtures/pages/no-yfm-data.hbs:
--------------------------------------------------------------------------------
1 | There is no YAML front matter in this page.
2 |
3 |
4 |
{{one}}
5 |
{{two}}
6 |
{{three}}
7 |
{{global1}}
8 |
9 |
--------------------------------------------------------------------------------
/test/fixtures/pages/layoutext/layoutext.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | title: options.layoutext
3 | layout: noext
4 | description: Allows a layout to be defined without an extension
5 | ---
6 |
{{title}}
7 |
{{description}}
--------------------------------------------------------------------------------
/test/fixtures/plugins/untitled.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | layout: none
3 | description: this page doesn't have a title in the YFM
4 | slug: assemble
5 | date: 2013-10-09
6 | ---
7 |
17 |
--------------------------------------------------------------------------------
/test/fixtures/data/data.yml:
--------------------------------------------------------------------------------
1 | # "data.yml" or "data.json" provides access to the root of the context,
2 | # which means that variables in a "data" file may be used your templates as-is,
3 | # so you can do this: {{one}} instead of this: {{data.one}}
4 | one: first
5 | two: second
6 | three: third
7 |
--------------------------------------------------------------------------------
/test/fixtures/pages/debug-helpers.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | title: Debug Helper
3 | ---
4 | {{#markdown}}
5 |
6 | ### \{{debug}} helper
7 | Uncomment the `debug` helper below, run `grunt assemble`, and watch the output in the command line to see how it works.
8 | {{!debug text}}
9 |
10 | {{/markdown}}
11 |
--------------------------------------------------------------------------------
/test/fixtures/helpers/opt.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | layout: none
3 | ---
4 |
5 |
6 |
7 | Custom Helpers example
8 |
9 |
10 |
11 | {{{bar 'Below is an example of using the opt helper and getting the name property from the passed-in assemble.options'}}}
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test/fixtures/helpers/foo.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | layout: none
3 | ---
4 |
5 |
6 |
7 | Custom Helpers example
8 |
9 |
10 |
Example using the foo helper
11 | {{{foo 'Below is an example of using the opt helper and getting the name property from the passed-in assemble.options'}}}
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test/fixtures/pages/postprocess/postprocess2.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | layout: none
3 | title: Post-Process function
4 | description: this page should be prettified.
5 | categories:
6 | - postprocess
7 | - options
8 | - prettify
9 | ---
10 | {{title}} {{> nav-main }} {{{description}}}
11 |
12 |
--------------------------------------------------------------------------------
/test/assemble_test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Assemble
3 | *
4 | * Copyright (c) 2014, Jon Schlinkert, Brian Woodward, contributors.
5 | * Licensed under the MIT License (MIT).
6 | */
7 |
8 | var expect = require('chai').expect;
9 |
10 | describe('awesome', function() {
11 | it('should run an awesome test', function() {
12 | expect(1).to.equal(1);
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/test/fixtures/pages/collections-tags.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | title: Tags Test
3 | tags:
4 | - tags
5 | - collections
6 | - one
7 | - two
8 | - three
9 | ---
10 |
12 |
13 | But none the less, whilst I have time and space,
14 | Before yet farther in this tale I pace,
15 | It seems to me accordant with reason
16 | To inform you of the condition
17 | Of all of these, as it seemed to me,
18 | And who they were, and what was their degree,
19 | And even how arrayed there at the inn;
20 | And with a knight thus will I first begin.
--------------------------------------------------------------------------------
/test/plugins/page_collection_preprocessing.js:
--------------------------------------------------------------------------------
1 |
2 | // list of functions to do pre processing on the pages
3 | // in the pages collection
4 |
5 | var relative = require('relative');
6 |
7 | module.exports = [
8 |
9 | // add an isCurrentPage flag to the page if the dest matches
10 | function isCurrentPage(page, context) {
11 | page.isCurrentPage = (page.dest === context.page.dest);
12 | },
13 |
14 | // add a relative link from the "current page" to the
15 | // page in the collection
16 | function relativeLink(page, context) {
17 | page.relativeLink = relative(context.page.dest, page.dest);
18 | }
19 | ];
20 |
--------------------------------------------------------------------------------
/test/helpers/utils/getext.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Assemble
3 | *
4 | * Copyright (c) 2014, Jon Schlinkert, Brian Woodward, contributors.
5 | * Licensed under the MIT License (MIT).
6 | */
7 | 'use strict';
8 |
9 | /**
10 | * ## Get extension
11 | *
12 | * Assemble
13 | * Copyright (c) 2013 Upstage.
14 | * Licensed under the MIT License (MIT).
15 | */
16 |
17 | var path = require('path');
18 |
19 | module.exports = function(str) {
20 | if (path.extname(str)) {
21 | str = path.extname(str);
22 | }
23 | if (str[0] === '.') {
24 | str = str.substring(1);
25 | }
26 | return str;
27 | };
28 |
--------------------------------------------------------------------------------
/test/fixtures/layouts/one.hbs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Layout name: '{{layout}}'
5 |
6 |
7 |
8 |
9 |
10 |
11 |
Layout: {{default this.layout 'No layout was used.'}}
30 |
--------------------------------------------------------------------------------
/test/plugins/untitled.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Adds "Untitled" to any page that doesn't have a title in the page context.
3 | * Use `page.title` in your templates.
4 | * @author: https://github.com/adjohnson916,
5 | * https://github.com/assemble/assemble/pull/325#issuecomment-25510116
6 | * @param {[type]} params [description]
7 | * @param {Function} callback [description]
8 | * @return {[type]} [description]
9 | */
10 |
11 | var _ = require('lodash');
12 |
13 | var untitled = function(params, callback) {
14 | var context = params.context;
15 | context.page.data = context.page.data || {};
16 | context.page.data.title = context.page.data.title || 'Untitled';
17 | _.extend(context.page, context.page.data);
18 | _.extend(context, context.page.data);
19 | callback();
20 | };
21 |
22 | module.exports = untitled;
23 |
--------------------------------------------------------------------------------
/test/fixtures/pages/yfm/associative-arrays.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | title: Associative arrays
3 |
4 | # Indented Blocks, common in YAML data files, use indentation and new lines to separate the '''key: value''' pairs
5 | people:
6 | name: John Smith
7 | age: 33
8 |
9 | # Inline Blocks, common in YAML data streams, use comma+space to separate the '''key: value''' pairs between braces
10 | morePeople: {name: Grace Jones, age: 21}
11 | ---
12 |
13 |
{{{title}}}
14 |
15 |
16 |
17 |
Associative arrays
18 |
19 | {{#people}}
20 |
Name:
{{name}}
21 |
Age:
{{age}}
22 | {{/people}}
23 | {{#morePeople}}
24 |
Name:
{{name}}
25 |
Age:
{{age}}
26 | {{/morePeople}}
27 |
28 |
--------------------------------------------------------------------------------
/test/fixtures/pages/yfm-context.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | title: This title is from the YFM of the current page
3 | description: This description is from the YFM of the current page
4 | categories:
5 | - yfm
6 | - yaml
7 | - context
8 | ---
9 |
10 |
11 |
{{{default home.title "Title from home.json didn't render."}}}
12 |
{{{default home.description "Description from home.json didn't render."}}}
Note that templates \{{one}}, \{{two}} and \{{three}} get their data from "test/fixtures/data.yml".
2 | When a data file is created with the name "data", it gives you access to the root of the context.
3 |
4 |
5 |
{{one}}
6 |
{{two}}
7 |
{{three}}
8 |
9 |
10 |
11 |
person.yml
12 |
{{person.name}}
13 |
14 |
15 |
16 |
contact.yml
17 |
{{contact.phone}}
18 |
19 |
20 |
21 |
animal.json
22 |
{{animal.type}}
23 |
{{animal.description}}
24 |
25 |
26 |
27 |
example.json
28 |
{{example.content}}
29 |
30 |
31 |
32 |
example.yml
33 |
{{example.info}}
34 |
35 |
--------------------------------------------------------------------------------
/test/fixtures/pages/yfm/variables.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | title: YAML Variables
3 |
4 | one: &DOOWB This is an example YAML variable. Variables need to be the first thing in the line. If it shows up in the result, it worked!
5 | two: *DOOWB
6 | ---
7 |
8 |
{{{title}}}
9 |
10 |
11 | {{{two}}}
12 |
13 | {{#markdown}}
14 | This would output the variable as literal text.
15 | ``` yaml
16 | three: But this doesn't work. *DOOWB
17 | ```
18 | And this would throw an error:
19 |
20 | ``` yaml
21 | three: *DOOWB But this doesn't work.
22 | ```
23 |
24 | YAML supports **variables**, or **repeated nodes**. The simplest explanation is that you define something as a variable by preceding it with "&NAME value" and you can refer to it with "*NAME" e.g.:
25 |
26 | ``` yaml
27 | # YAML
28 | some_thing: &NAME foobar
29 | other_thing: *NAME
30 | ```
31 | Parses to:
32 | ``` json
33 | {"other_thing": "foobar", "some_thing": "foobar"}
34 | ```
35 | {{/markdown}}
--------------------------------------------------------------------------------
/test/fixtures/partials/nav-main.hbs:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/docs/examples.md:
--------------------------------------------------------------------------------
1 | Simple example of using data files in both `.json` and `.yml` format to build Handlebars templates.
2 |
3 | ```javascript
4 | assemble: {
5 | options: {
6 | data: 'src/data/**/*.{json,yml}'
7 | },
8 | docs: {
9 | files: {
10 | 'dist/': ['src/templates/**/*.hbs']
11 | }
12 | }
13 | }
14 | ```
15 |
16 | ### Using multiple targets
17 |
18 | ```js
19 | assemble: {
20 | options: {
21 | assets: 'assets',
22 | layoutdir: 'docs/layouts'
23 | partials: ['docs/includes/**/*.hbs'],
24 | data: ['docs/data/**/*.{json,yml}']
25 | },
26 | site: {
27 | options: {
28 | layout: 'default.hbs'
29 | },
30 | src: ['templates/site/*.hbs'],
31 | dest: './'
32 | },
33 | blog: {
34 | options: {
35 | layout: 'blog-layout.hbs'
36 | },
37 | src: ['templates/blog/*.hbs'],
38 | dest: 'articles/'
39 | },
40 | docs: {
41 | options: {
42 | layout: 'docs-layout.hbs'
43 | },
44 | src: ['templates/docs/*.hbs'],
45 | dest: 'docs/'
46 | }
47 | },
48 | ```
49 |
50 | Visit [Assemble's documentation](http://assemble.io) for many more examples and pointers on getting started.
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors.
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 |
--------------------------------------------------------------------------------
/test/fixtures/pages/yfm/data-types.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | title: Data Types
3 |
4 | dataTypes:
5 | a: 123 # an integer
6 | b: "123" # a string, disambiguated by quotes
7 | c: 123.0 # a float
8 | # d throws an error
9 | # d: !!float 123 # also a float via explicit data type prefixed by (!!)
10 | e: !!str 123 # a string, disambiguated by explicit type
11 | f: !!str Yes # a string via explicit type
12 | g: Yes # a boolean True
13 | h: Yes we have No bananas # a string, "Yes" and "No" disambiguated by context.
14 | ---
15 |
Note that templates \{{one}}, \{{two}} and \{{three}} get their data from "test/fixtures/data.yml".
5 | When a data file is created with the name "data", it gives you access to the root of the context.
6 |
7 |
8 |
{{one}}
9 |
{{two}}
10 |
{{three}}
11 |
12 |
13 |
14 |
person.yml
15 |
{{person.name}}
16 |
17 |
18 |
19 |
person.yml - YFM
20 |
jon: {{jon}}
21 |
page.jon: {{page.jon}}
22 |
underscore.jon: {{underscore.jon}}
23 |
data.jon: {{data.jon}}
24 |
underscore.data.jon: {{underscore.data.jon}}
25 |
26 |
27 |
28 |
contact.yml
29 |
{{contact.phone}}
30 |
31 |
32 |
33 |
animal.json
34 |
{{animal.type}}
35 |
{{animal.description}}
36 |
37 |
38 |
39 |
example.json
40 |
{{example.content}}
41 |
42 |
43 |
44 |
example.yml
45 |
{{example.info}}
46 |
47 |
--------------------------------------------------------------------------------
/test/helpers/logging.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Assemble
3 | *
4 | * Copyright (c) 2014-2017, Jon Schlinkert, Brian Woodward, contributors.
5 | * Licensed under the MIT License (MIT).
6 | */
7 |
8 | var sort = require('sort-object');
9 |
10 | module.exports.register = function(Handlebars) {
11 | 'use strict';
12 |
13 | Handlebars.registerHelper('inspect', function(context, options) {
14 | var hash = options.hash || {};
15 | var ext = hash.ext || '.html';
16 | context = JSON.stringify(sort(context), null, 2);
17 |
18 | // Wrap the returned JSON in either markdown code fences
19 | // or HTML, depending on the extension.
20 | var md = '\n```json\n' + context + '\n```';
21 | var html = '
\n' + context + '\n
';
22 | var result = switchOutput(ext, md, html);
23 | return new Handlebars.SafeString(result);
24 | });
25 | };
26 |
27 | function switchOutput(ext, markdown, html) {
28 | var output;
29 | switch (ext) {
30 | // return markdown
31 | case '.markdown':
32 | case '.md':
33 | output = markdown;
34 | break;
35 |
36 | // return HTML
37 | case '.html':
38 | case '.htm':
39 | output = html;
40 | break;
41 |
42 | default:
43 | output = html;
44 | }
45 | return output;
46 | }
47 |
--------------------------------------------------------------------------------
/docs/getting-started.md:
--------------------------------------------------------------------------------
1 | Assemble requires Grunt `~0.4.1`
2 |
3 | _If you haven't used [grunt][] before, be sure to check out the [Getting Started][] guide._
4 |
5 | From the same directory as your project's [Gruntfile][Getting Started] and [package.json][], install Assemble with the following command:
6 |
7 | ```bash
8 | npm install {%= name %} --save-dev
9 | ```
10 |
11 | Once that's done, add this line to your project's Gruntfile:
12 |
13 | ```js
14 | grunt.loadNpmTasks('{%= name %}');
15 | ```
16 |
17 | ## The "assemble" task
18 | _Run the "assemble" task with the `grunt assemble` command._
19 |
20 | Task targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide.
21 |
22 | In your project's Gruntfile, add a section named `assemble` to the data object passed into `grunt.initConfig()`.
23 |
24 | ```js
25 | assemble: {
26 | options: {
27 | assets: 'assets',
28 | plugins: ['permalinks'],
29 | partials: ['includes/**/*.hbs'],
30 | layout: ['layouts/default.hbs'],
31 | data: ['data/*.{json,yml}']
32 | },
33 | site: {
34 | src: ['docs/*.hbs'],
35 | dest: './'
36 | }
37 | },
38 | ```
39 |
40 | [grunt]: http://gruntjs.com/
41 | [Getting Started]: https://github.com/gruntjs/grunt/blob/devel/docs/getting_started.md
42 | [package.json]: https://npmjs.org/doc/json.html
43 |
--------------------------------------------------------------------------------
/test/fixtures/layouts/post.hbs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Layout name: '{{layout}}'
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | {{pager pagination}}
19 |
20 |
21 |
22 |
23 |
24 |
25 |
Layout: {{default this.layout 'No layout was used.'}}
67 | <script src="https://gist.github.com/5898072.js"></script>
68 | This "content" property is optional and would get passed into the `body` tag. But if you only need to pass the page"s metadata to the layout then the content property is unnecessary.
69 |
67 | <script src="https://gist.github.com/5898072.js"></script>
68 | This 'content' property is optional and would get passed into the `body` tag. But if you only need to pass the page"s metadata to the layout then the content property is unnecessary.
69 |
67 | <script src="https://gist.github.com/5898072.js"></script>
68 | This 'content' property is optional and would get passed into the `body` tag. But if you only need to pass the page"s metadata to the layout then the content property is unnecessary.
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/.verbrc.md:
--------------------------------------------------------------------------------
1 | ---
2 | author: 'Jon Schlinkert, Brian Woodward'
3 | ---
4 | # {%= name %} {%= badge("fury") %} {%= badge("travis") %}
5 |
6 | > {%= description %}
7 |
8 | ### [Visit the website →](http://assemble.io)
9 |
10 | ### Warning!
11 |
12 | > Versions of `grunt-assemble` below `0.2.0` have been deprecated and can be found on the [`0.1.15-deprecated` branch](https://github.com/assemble/grunt-assemble/tree/0.1.15-deprecated).
13 | Versions of `grunt-assemble` at and above `0.2.0` contain the code from the original `assemble` up to version `0.4.42`.
14 |
15 | > See the [migration](#migrations) section for instructions on what to do when upgrading to a new version.
16 |
17 | ## Why use Assemble?
18 |
19 | 1. Most popular site generator for Grunt.js and Yeoman. Assemble is used to build hundreds of web projects, ranging in size from a single page to 14,000 pages (that we're aware of!). [Let us know if you use Assemble](https://github.com/assemble/assemble/issues/300).
20 | 1. Allows you to carve your HTML up into reusable fragments: partials, includes, sections, snippets... Whatever you prefer to call them, Assemble does that.
21 | 1. Optionally use `layouts` to wrap your pages with commonly used elements and content.
22 | 1. "Pages" can either be defined as HTML/templates, JSON or YAML, or directly inside the Gruntfile.
23 | 1. It's awesome. Lol just kidding. But seriously, Assemble... is... awesome! and it's fun to use.
24 |
25 | ...and of course, we use Assemble to build the project's own documentation [http://assemble.io](http://assemble.io):
26 |
27 | **For more:** hear Jon Schlinkert and Brian Woodward discuss Assemble on **Episode 98 of the [Javascript Jabber Podcast](http://javascriptjabber.com/098-jsj-assemble-io-with-brian-woodward-and-jon-schlinkert/)**.
28 |
29 |
30 | 
31 |
32 | ## The "assemble" task
33 |
34 | ### Getting Started
35 | {%= docs("getting-started") %}
36 |
37 | ### Options
38 | {%= docs("options") %}
39 |
40 | ### Usage Examples
41 | {%= docs("examples") %}
42 |
43 | ### Migrations
44 | {%= docs("v6-diffs") %}
45 |
46 | ## Contributing
47 | {%= include("contributing") %}
48 |
49 | ## Assemble plugins
50 | {%= include("assemble/repos-list") %}
51 |
52 | ## Authors
53 | {%= include("authors", {
54 | authors: [
55 | {
56 | name: 'Jon Schlinkert',
57 | username: 'jonschlinkert'
58 | },
59 | {
60 | name: 'Brian Woodward',
61 | username: 'doowb'
62 | }
63 | ]
64 | }) %}
65 |
66 | ## Release History
67 | {%= changelog() %}
68 |
69 | ## License
70 | {%= copyright() %}
71 | {%= license() %}
72 |
73 | ***
74 |
75 | {%= include("footer") %}
76 |
--------------------------------------------------------------------------------
/test/actual/pages_object/awesome-blog-post-2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Layout name: ''
7 |
8 |
9 |
10 |
11 |
\n {{> <%= component.one %> }} This project is brought to you by <%= pkg.name %>."
20 | },
21 | {
22 | "filename": "post3",
23 | "data": {
24 | "title": "Blog Post #3",
25 | "gists": ["5909393"]
26 | }
27 | }
28 | ],
29 | "two": {
30 | "sweet-blog-post-1": {
31 | "data": {
32 | "title": "Sweet Blog Post #1",
33 | "gists": ["5898072"]
34 | },
35 | "content": "This 'content' property is optional and would get passed into the `body` tag. But if you only need to pass the page\"s metadata to the layout then the content property is unnecessary."
36 | },
37 | "awesome-blog-post-2": {
38 | "data": {
39 | "title": "Awesome Blog Post #2",
40 | "subtitle": "",
41 | "gists": ["5898077", "5898078"]
42 | },
43 | "content": "
{{title}} | {{site.title}}
\n {{> <%= component.one %> }} This project is brought to you by <%= pkg.name %>."
44 | },
45 | "super-sweet-and-awesome-blog-post-3": {
46 | "data": {
47 | "title": "Super Sweet and Awesome Blog Post #3",
48 | "gists": ["5898072"]
49 | }
50 | }
51 | },
52 | "three": {
53 | "meta-sweet-blog-post-1": {
54 | "metadata": {
55 | "title": "Sweet Blog Post #1",
56 | "gists": ["5898072"]
57 | },
58 | "content": "This 'content' property is optional and would get passed into the `body` tag. But if you only need to pass the page\"s metadata to the layout then the content property is unnecessary."
59 | },
60 | "meta-awesome-blog-post-2": {
61 | "data": {
62 | "title": "Awesome Blog Post #2",
63 | "subtitle": "",
64 | "gists": ["5898077", "5898078"]
65 | },
66 | "content": "
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/test/engine_test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Assemble
3 | *
4 | * Copyright (c) 2014, Jon Schlinkert, Brian Woodward, contributors.
5 | * Licensed under the MIT License (MIT).
6 | */
7 |
8 | var assembleEngine = require('../lib/engine');
9 | var expect = require('chai').expect;
10 |
11 | var pluginParams = {
12 | grunt: require('grunt')
13 | };
14 |
15 | describe('Loading default handlebars engine', function() {
16 |
17 | it('loads handlebars engine', function(done) {
18 | done();
19 | });
20 |
21 | it('compiles a handlebars template', function(done) {
22 | var engine = assembleEngine.load('handlebars');
23 | engine.compile('{{foo}}', {}, function(err, tmpl) {
24 | if (err) {
25 | return done(err);
26 | }
27 | done();
28 | });
29 | });
30 |
31 | it('renders a template', function(done) {
32 | var engine = assembleEngine.load('handlebars');
33 | var expected = 'bar';
34 | engine.compile('{{baz}}', {}, function(err, tmpl) {
35 | if (err) {
36 | return done(err);
37 | }
38 | engine.render(tmpl, {baz: 'bar'}, function(err, content) {
39 | if (err) {
40 | return done(err);
41 | }
42 | expect(content).to.equal(expected);
43 | done();
44 | });
45 | });
46 | });
47 |
48 | describe('Loading custom helpers', function() {
49 |
50 | var runTest = function(engine, done) {
51 | var expected = '\n';
52 | engine.compile("{{{bar 'bar'}}}", {}, function(err, tmpl) {
53 | if (err) {
54 | return done(err);
55 | }
56 | engine.render(tmpl, {}, function(err, content) {
57 | if (err) {
58 | return done(err);
59 | }
60 | expect(content).to.equal(expected);
61 | done();
62 | });
63 | });
64 | };
65 |
66 | it('loads a custom helper from a file path', function(done) {
67 | var engine = assembleEngine.load('handlebars');
68 | engine.init({
69 | helpers: './test/helpers/helpers.js'
70 | }, pluginParams);
71 | runTest(engine, done);
72 | });
73 |
74 | it('loads a custom helper from a glob pattern', function(done) {
75 | var engine = assembleEngine.load('handlebars');
76 | engine.init({
77 | helpers: './test/helpers/helpers.js'
78 | }, pluginParams);
79 | runTest(engine, done);
80 | });
81 |
82 | it('loads a custom helper from the given path', function(done) {
83 | var engine = assembleEngine.load('handlebars');
84 | engine.init({helpers: './test/helpers/*.js'}, pluginParams);
85 | var expected = '';
86 |
87 | engine.compile("{{{foo 'bar'}}}", {}, function(err, tmpl) {
88 | if (err) {
89 | return done(err);
90 | }
91 | engine.render(tmpl, {}, function(err, content) {
92 | if (err) {
93 | return done(err);
94 | }
95 | expect(content).to.equal(expected);
96 | done();
97 | });
98 | });
99 | });
100 |
101 | });
102 | });
103 |
--------------------------------------------------------------------------------
/docs/v6-diffs.md:
--------------------------------------------------------------------------------
1 |
2 | ### Breaking changes between versions `0.5.0` and `0.6.0`
3 |
4 | Version 6 is using [assemble-handlebars][] version `0.4.0` which updates [handlebars-helpers][] to version `0.6.0`. Due to this update, there are some breaking changes with how some helpers are loaded and some missing/added helpers.
5 |
6 | The following list contains the breaking changes that we have noticed that may require updates to existing templates.
7 |
8 | **helpers loaded from package.json**
9 |
10 | Any helpers declared in `dependencies` or `devDependencies` and have their name in the `keywords` property will no longer be loaded automatically. To load the helpers, just include the package name in the `helpers` option for your `grunt-assemble` target:
11 |
12 | ```js
13 | assemble: {
14 | options: {
15 | helpers: ['handlebars-helper-eachitems']
16 | }
17 | }
18 | ```
19 |
20 | **new path helpers**
21 |
22 | Helpers have been added that map to methods on the built-in `path` module. Some of these helpers are also properties that `grunt-assemble` adds automatically to `page` properties. To use the page property, use the `this` keyword before the property name. To use the helper, use it like any other helper.
23 |
24 | ```handlebars
25 | {{! page property "basename" }}
26 | {{this.basename}}
27 |
28 | {{! new helper "basename" }}
29 | {{basename this.path}}
30 | ```
31 |
32 | **missing helper "inspect"**
33 |
34 | The "inspect" helper has been removed from `handlebars-helpers`. The test fixtures in this project use the "inspect" helper so it has been recreated [here](./test/helpers/logging.js).
35 |
36 | **missing helper "unless_eq"**
37 |
38 | The "unless_eq" helper has been renamed to "unlessEq".
39 |
40 | **missing helper "md" or "markdown"**
41 |
42 | There is a bug in `handlebars-helpers@0.6` that causes the `md` and `markdown` helpers to not be registered correctly. This has been fixed in newer versions of `handlebars-helpers`, however those changes have not made it here yet. There is currently a refactor of `grunt-assemble` that will include the fix, but for now, use the following work-around:
43 |
44 | Create a file and register the helpers manually:
45 |
46 | ```js
47 | // helpers/markdown.js
48 | module.exports.register = function (Handlebars) {
49 | 'use strict';
50 |
51 | Handlebars.registerHelper('markdown', require('helper-markdown')());
52 | Handlebars.registerHelper('md', require('helper-md').sync);
53 | };
54 | ```
55 |
56 | ```js
57 | // Gruntfile.js
58 | assemble: {
59 | options: {
60 | helpers: ['./helpers/*.js']
61 | }
62 | }
63 | ```
64 |
65 | **handlebars 4 changed how context depths are handled**
66 |
67 | `assemble-handlebars` is also using a newer version of handlebars that changed how the context depth is handled. Some of the block helpers that would create a new depth, no longer create the depth. This requires changing some templates that use the `{{../}}` syntax to reduce the amount of `../` segments used. This can be seen in block helpers that don't modify the context, like `{{#if}}{{/if}}` and `{{#is}}{{/is}}`.
68 |
69 |
70 | [assemble-handlebars]: https://github.com/assemble/assemble-handlebars
71 | [handlebars-helpers]: https://github.com/assemble/handlebars-helpers
72 |
--------------------------------------------------------------------------------
/test/helpers/pager.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Assemble
3 | *
4 | * Copyright (c) 2014, Jon Schlinkert, Brian Woodward, contributors.
5 | * Licensed under the MIT License (MIT).
6 | */
7 |
8 | var _ = require('lodash');
9 |
10 | module.exports.register = function(Handlebars, options) {
11 | 'use strict';
12 |
13 | var opts = options || {};
14 |
15 | /**
16 | * {{pager}}
17 | * Adds a pager to enable navigating to prev and next page/post.
18 | * @param {Object} context Context to pass to the helper, most likely `pagination`.
19 | * @param {Object} options Pass a modifier class to the helper.
20 | * @return {String} The pagination, HTML.
21 | */
22 |
23 | Handlebars.registerHelper('pager', function(context, options) {
24 | options = options || {};
25 | options.hash = options.hash || {};
26 | context = _.extend({modifier: ''}, context, opts.data, this, options.hash);
27 |
28 | var template = [
29 | '