/
Options.md.hbs
246 lines (168 loc) · 9.03 KB
/
Options.md.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
---
title: Options Overview
area: docs
section: configuration
---
> Comprehensive list of options available in Assemble
Most options are defined in the `assemble` task or target options in the Gruntfile, some options may only be defined inside the [YAML front matter][yaml-front-matter] of a file, and some may be defined in either location.
Additionally, options may be defined in "external" [JSON][] or [YAML][] configuration files.
For the purposes of clarity, we will refer to options that are defined in the Gruntfile as "configuration" options, and options that are defined in the YFM as "page" options.
## Configuration options
These options are defined in the `assemble` task in your project's Gruntfile. Any option may be defined at the [task or target][tasks-and-targets] level.
| Option | Description |
| -------- | ----------- |
| [assets][options-assets] | directory that contains commonly used "assets" for a project, such as images, fonts, javascripts and stylesheets. Assemble will generate a relative path from dest files to the given `assets` directory. |
| [collections][options-collections] | Built-in collections for `tags`, `categories` and `pages` are available at the root of the context. |
| [data][options-data] | path to data files to supply the data that will be passed into templates. |
| [engine][options-engine] | engine to be used for processing templates. Handlebars is the default. |
| [ext][options-ext] | extension to be used for `dest` files. |
| [helpers][options-helpers] | path to custom helper(s) to be registered and used by the current template engine. Handlebars is the default. |
| [layout][options-layout]** * ** | [Layouts][] are optional and assemble will build [pages][] without one. However, when a layout is specified the file _must contain a `\{{> body }}`_ tag, since this tag indicates where the content from each file in a target should be inserted. |
| [layoutdir][options-layoutdir]** * ** | [Layouts][] are optional and assemble will build [pages][] without one. However, when a layout is specified the file _must contain a `\{{> body }}`_ tag, since this tag indicates where the content from each file in a target should be inserted. |
| [partials][options-partials] | the partials or "includes" to be used with [pages][]. |
***Note** that when a layout is used the [\{{> body }}][Layouts] tag must be included inside the layout in order for content from pages to be "pulled in".
## Task Options
These options are defined in the `assemble` task in your Gruntfile.
### [options.data][options-data]
Type: `String|Array` (optional)
Default: `src/data`
Retrieves data from any specified `JSON` and/or `YAML` files to populate the templates when rendered. Data gets passed through the `data` object to the options on the assemble task, and then to the context in your templates. Also useful for specifying [configuration][] data.
``` js
options: { data: 'src/data/**/*.{json,yml}' }
```
Note that `assemble` merges the task and target-level data for `options.data`.
> Learn more about [data][data] →
### [options.layout][options-layout]
Type: `String` (optional)
Default: `undefined`
Layouts are optional and may be defined at the task and/or [target][tasks-and-targets] level. _Unlike Jekyll_, Assemble requires a file extension since you are not limited to using a single file type.
``` js
options: { layout: 'src/layouts/default.hbs' }
```
> Learn more about [layouts][layouts] →
### [options.layoutdir][options-layoutdir]
Type: `String`|`False`|`None` (optional)
Default: `undefined`
Path to the directory that is to be used as the "cwd" for layouts.
``` js
options: { layoutdir: 'src/layouts' }
```
When `layoutdir` is defined, then a `layout` may defined without the path:
``` js
options: { layout: 'default.hbs' }
```
or
```yaml
---
layout: default.hbs
---
```
### [options.assets][options-assets]
Type: `String` (optional)
Default: `undefined`
Path to the "assets" or "public" directory that will be used by dest files. Assemble uses path in the `assets` option to generate a relative path from dest files to the given "assets" directory. The "assets" folder commonly contains the CSS, JavaScripts, images and other similar files for a project. The `assets` option may be defined at the task or target-level.
``` js
options: { assets: 'docs/assets' }
```
### [options.partials][options-partials]
Type: `String|Array` (optional)
Default: `undefined`
Specifies the Handlebars partials files, or paths to the directories of files to be used.
``` js
options: { partials: 'src/partials/**/*.hbs' }
```
_**Note that `assemble` merges the task and target-level data for `options.partials`.**_
> Learn more about [partials][partials] →
### [options.ext][options-ext]
Type: `String` (optional)
Default: `.html`
Specify the file extension to be used for destination files. For example:
``` js
assemble: {
// Build sitemap from JSON and templates
sitemap: {
options: { ext: '.xml'},
files: {
'.': ['path/to/sitemap.tmpl']
}
},
// Build README from YAML and templates
readme: {
options: { ext: '.md' },
files: {
'.': ['path/to/readme.tmpl']
}
}
}
```
> Learn more about the [ext option][options-ext] →
### [options.engine][options-engine]
Type: `String` (optional)
Default: `handlebars`
The engine to use for processing client-side templates. Assemble ships Handlebars as the default template engine, to learn more about adding other template engines please read the documentation on [assemble methods][methods].
Also, we welcome pull requests for additional template engines. If you have questions please create an [Issue][assemble-issues].
### [options.helpers][options-helpers]
Type: `String|Array` (optional)
Default: 100+ helpers from [handlebars-helpers][]
Assemble depends on [handlebars-helpers][], an external library which includes more than **100 Handlebars helpers**. So any helpers from that project may be used in your templates.
If you wish for Assemble to use custom helpers with Handlebars or any specified template engine, just provide the path to the helper or helpers in `options.helpers` :
``` js
options: { helpers: 'your/custom/helpers' }
```
### options.removeHbsWhitespace
Type: `Boolean`
Default: `false`
Remove extraneous whitespace added by Handlebars in rendered files. _Use at your own risk, this is an experimental option and may be removed._
## [YAML Front-Matter Options][yaml-front-matter]
These options are defined in the [YAML front matter][yaml-front-matter] of a page.
### [options.layout][options-layout]
type: `string`
default: `undefined`
Specifies the [layout][Layouts] file to be used. Layouts defined in [YFM][yaml-front-matter] will override layouts defined in the Gruntfile.
### options.published
type: `boolean`
default: true
Defining `published: false` in the [YAML front matter][yaml-front-matter] of a page will:
* Prevent the page from rendering
* Omit the page from the `pages` collection.
## Custom Options
Custom, user-defined variables may be specified in the [Options][options-overview] of the assemble task or target. Any variables defined in the options will be added to the _root of the data context_ and thus they will also be available in any templates.
### Example usage
A common use case for defining custom variables in the options is for easily including or excluding content based on current "development status".
For example, assuming we have defined a custom option, `production`:
``` js
assemble: {
options: {
production: false
},
files: {
'site/': ['src/pages/*.hbs']
}
}
```
And we add the `production` variable to our templates:
``` html
\{{#if production}}
<script src="dist/assets/script.min.js"></script>
\{{else}}
<script src="dist/assets/script.js"></script>
\{{/if}}
```
Since `production: false` is defined in the Assemble [task options][options], the following HTML will be rendered with the _non-minified_ version of the script:
``` html
<script src="dist/assets/script.js"></script>
```
## [Grunt.js][tasks-and-targets] Options
The following is just a handful of options that can be used in your Gruntfile. Please visit the [Grunt documentation](http://gruntjs.com/api/grunt.file) to learn more.
* `expand` Set to `true` to enable the following options:
* `cwd` All `src` matches are relative to (but don't include) this path.
* `src` Pattern(s) to match, relative to the `cwd`.
* `dest` Destination path prefix.
* `ext` Replace any existing extension with this value in generated `dest` paths.
* `flatten` Remove all path parts from generated `dest` paths.
* `rename` This function is called for each matched `src` file, (after extension renaming and flattening). The `dest` and matched `src` path are passed in, and this function must return a new `dest` value. If the same `dest` is returned more than once, each `src` which used it will be added to an array of sources for it.
## Related info:
* [Variables][built-in-variables]
{{#draft}}* [Markdown Options][Markdown]{{/draft}}
* [YAML Options][YAML]
[tasks-and-targets]: http://gruntjs.com/configuring-tasks#task-configuration-and-targets