-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGruntfile.js
268 lines (243 loc) · 6.98 KB
/
Gruntfile.js
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/**
* Handlebars Helper: {{compose}}
* https://github.com/helpers/handlebars-helper-compose
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* https://github.com/jonschlinkert
* Licensed under the MIT license.
*/
module.exports = function(grunt) {
'use strict';
require('time-grunt')(grunt);
// Project configuration.
grunt.initConfig({
book: grunt.file.readYAML('test/fixtures/data/book.yml'),
blog: grunt.file.readYAML('test/fixtures/data/blog.yml'),
config: grunt.file.readYAML('_config.yml'),
// Lint JavaScript
jshint: {
all: ['Gruntfile.js', 'index.js'],
options: {
jshintrc: '.jshintrc'
}
},
assemble: {
options: {
flatten: true,
config: '<%= config %>',
data: ['<%= config.data %>'],
helpers: ['./index.js', 'test/helpers/*.js'],
partials: ['<%= config.includes %>'],
layoutdir: '<%= config.layouts %>',
layoutext: '<%= config.layoutext %>',
layout: '<%= config.layout %>'
},
// No options defined
dynamic: {
options: {
flatten: false,
compose: {
sortBy: 'title',
sortOrder: 'desc'
}
},
files: [{
expand: true,
cwd: '<%= config.templates %>/dynamic',
src: ['**/*.{hbs,md}'],
dest: '<%= config.dest %>/dynamic/',
ext: '.html'
}]
},
// Should convert markdown to HTML and use a
// custom template for headings (anchors)
markdown: {
options: {
marked: {
process: true,
heading: 'test/heading.tmpl'
}
},
src: ['<%= config.pages %>/markdown-*.md'],
dest: '<%= config.dest %>/md/'
},
// Should
dynamic_src_dest_pairings: {
options: {
flatten: false,
compose: {
sortBy: 'title',
sortOrder: 'desc'
}
},
expand: true,
cwd: '<%= config.templates %>/dynamic',
src: ['**/*.{hbs,md}'],
dest: '<%= config.dest %>/dynamic_src_dest/',
ext: '.html'
},
// Should filter src files using custom function
filter_fn: {
options: {
flatten: false,
compose: {
filter: function(arr) {
return arr.slice(Math.max(arr.length - 2, 0));
},
sortBy: 'title',
sortOrder: 'desc'
}
},
files: [{
expand: true,
cwd: '<%= config.templates %>/dynamic',
src: ['**/*.{hbs,md}'],
dest: '<%= config.dest %>/filter_fn/',
ext: '.html'
}]
},
// Should process templates in different contexts
// Should also render code comment with template
// origin above each include
context: {
options: {
compose: {
sortBy: 'title',
sortOrder: 'desc',
cwd: '<%= config.book %>',
sep: '<!-- chapter -->',
origin: true
}
},
src: ['<%= config.pages %>/context-*.hbs'],
dest: '<%= config.dest %>/context/',
},
book: {
options: {
compose: {
sortBy: 'number',
sortOrder: 'desc',
cwd: '<%= config.book %>',
sep: '<!-- chapter -->'
}
},
src: ['<%= config.pages %>/{book,toc}.hbs'],
dest: '<%= config.dest %>/book/',
},
// No options defined
bogus_options: {
options: {
compose: {
foo: 'bar'
}
},
src: ['<%= config.pages %>/full_path.hbs'],
dest: '<%= config.dest %>/bogus_options/',
},
// No options defined
no_opts_defined: {
options: {
compose: {}
},
src: ['<%= config.pages %>/full_path.hbs'],
dest: '<%= config.dest %>/no_opts_defined/',
},
// Should use cwd defined in task options (Gruntfile)
opts_cwd: {
options: {
compose: {
sortBy: 'basename',
cwd: '<%= config.posts %>',
sep: '<!-- article -->'
}
},
src: ['<%= config.pages %>/opts_cwd.hbs'],
dest: '<%= config.dest %>/opts_cwd/',
},
// Should use cwd from options hash
opts_hash_cwd: {
options: {
compose: {process: true}
},
src: ['<%= config.posts %>/opts_hash_cwd.hbs'],
dest: '<%= config.dest %>/opts_hash_cwd/'
},
// Should use a custom separator between sections
custom_separator_opts: {
options: {
compose: {
cwd: '<%= config.posts %>',
sep: '<!-- CUSTOM SEPARATOR -->'
}
},
src: ['<%= config.pages %>/custom_sep_opts.hbs'],
dest: '<%= config.dest %>/custom_separator_opts/',
},
// Should use a custom separator between sections
custom_separator_hash: {
options: {
compose: {
cwd: '<%= config.posts %>'
}
},
src: ['<%= config.pages %>/custom_sep_hash.hbs'],
dest: '<%= config.dest %>/custom_separator_hash/',
},
// Basic compare function
compare_fn_index: {
src: ['<%= config.pages %>/toc-sorting.hbs'],
dest: '<%= config.dest %>/compare_fn_index/',
options: {
compose: {
cwd: '<%= config.book %>',
sep: '<!-- chapter -->',
compare: function(a, b) {
return a.data.index >= b.data.index ? 1 : -1;
}
}
}
},
// Basic compare function
compare_fn_custom_prop: {
src: ['<%= config.pages %>/toc-sorting.hbs'],
dest: '<%= config.dest %>/compare_fn_custom_prop/',
options: {
compose: {
cwd: '<%= config.book %>',
sep: '<!-- chapter -->',
compare: function(a, b) {
return a.data.custom >= b.data.custom ? 1 : -1;
}
}
}
},
// Alternative compare function
compare_fn_chapter: {
src: ['<%= config.pages %>/toc-sorting.hbs'],
dest: '<%= config.dest %>/compare_fn_chapter/',
options: {
compose: {
cwd: '<%= config.book %>',
sep: '<!-- chapter -->',
compare: function(a, b) {
return a.data.chapter >= b.data.chapter ? 1 : -1;
},
debug: 'tmp/obj.json'
}
}
}
},
// Before generating any new files,
// remove files from previous build.
clean: {
example: ['<%= config.dest %>/**']
}
});
// Load npm plugins to provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-sync-pkg');
grunt.loadNpmTasks('assemble');
// Default to tasks to run with the "grunt" command.
grunt.registerTask('default', ['clean', 'jshint', 'assemble', 'sync']);
};