Skip to content

Commit 4459f3a

Browse files
committed
Add HTML Preprocessors (Jade, Haml and Handlebars)
1 parent 8a65c72 commit 4459f3a

File tree

16 files changed

+219
-34
lines changed

16 files changed

+219
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ The root directory generated for a app with name `gulpAngular` :
119119
* *CSS pre-processor*: Less, Sass with Ruby and Node, Stylus, none
120120
* *Bootstrap directives* : UI Bootstrap, Angular Strap, official Bootstrap JavaScript, none (only if you chose Bootstrap)
121121
* **TODO** JS preprocessor: CoffeeScript, TypeScript, ECMAScript6 (Traceur and 6to5)
122-
* **TODO** HTML preprocessor: Jade ?
122+
* *HTML pre-processor*: Jade, Handlebars, Haml
123123
* **TODO** Script loader: Require, Browserify, ES6 with Require?, none
124124
* **TODO** Test framework: Jasmine, Mocha, Qunit
125125

app/files.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"bower.json",
2525

2626
"gulp/build.js",
27+
"gulp/consolidate.js",
2728
"gulp/watch.js",
2829
"gulp/wiredep.js",
2930

app/prompts.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,5 +288,48 @@
288288
"name": "None, only the good old CSS"
289289
}
290290
]
291+
},
292+
{
293+
"type": "checkbox",
294+
"name": "htmlPreprocessors",
295+
"message": "Which html template engine would you want to have?",
296+
"choices": [
297+
{
298+
"value": {
299+
"key": "jade",
300+
"consolidate": ["jade", {"pretty": " "}],
301+
"extension": "jade",
302+
"npm": {
303+
"jade": "~1.8.1"
304+
}
305+
},
306+
"name": "Jade (*.jade)",
307+
"checked": false
308+
},
309+
{
310+
"value": {
311+
"key": "haml",
312+
"consolidate": ["hamljs"],
313+
"extension": "haml",
314+
"npm": {
315+
"hamljs": "~0.6.2"
316+
}
317+
},
318+
"name": "Haml (*.haml)",
319+
"checked": false
320+
},
321+
{
322+
"value": {
323+
"key": "handlebars",
324+
"consolidate": ["handlebars"],
325+
"extension": "hbs",
326+
"npm": {
327+
"handlebars": "~2.0.0"
328+
}
329+
},
330+
"name": "Handlebars (*.hbs)",
331+
"checked": false
332+
}
333+
]
291334
}
292335
]

app/src/format.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ module.exports = function () {
4444
return tech !== 'default' && tech !== 'css' && tech !== 'official' && tech !== 'none';
4545
});
4646

47+
_.forEach(this.props.htmlPreprocessors, function(preprocessor) {
48+
usedTechs.push(preprocessor.key);
49+
});
50+
4751
var techsContent = _.map(usedTechs, function(value) {
4852
return listTechs[value];
4953
});
@@ -131,4 +135,24 @@ module.exports = function () {
131135
var styleVendorSource = 'src/app/__' + this.props.ui.key + '-vendor.' + this.props.cssPreprocessor.extension;
132136
this.styleCopies[styleVendorSource] = 'src/app/vendor.' + this.props.cssPreprocessor.extension;
133137
}
138+
139+
function dependencyString(dep, version) {
140+
return '"' + dep + '": ' + '"' + version + '"';
141+
}
142+
143+
this.consolidateExtensions = [];
144+
145+
this.npmDevDependencies = [];
146+
this.consolidateParameters = [];
147+
_.forEach(this.props.htmlPreprocessors, function(preprocessor) {
148+
_.forEach(preprocessor.npm, function(version, dep) {
149+
this.npmDevDependencies.push(dependencyString(dep, version));
150+
}.bind(this));
151+
this.consolidateParameters.push(
152+
JSON.stringify(preprocessor.consolidate).
153+
replace(/"/g,'\'')); // Replace " with ' and assume this won't break anything.
154+
this.consolidateExtensions.push(preprocessor.extension);
155+
}.bind(this));
156+
157+
134158
};

app/techs.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,27 @@
102102
"url": "http://learnboost.github.io/stylus/",
103103
"description": "Stylus is a revolutionary new language, providing an efficient, dynamic, and expressive way to generate CSS. Supporting both an indented syntax and regular CSS style.",
104104
"logo": "stylus.png"
105+
},
106+
"jade": {
107+
"key": "jade",
108+
"title": "Jade",
109+
"url": "http://jade-lang.com/",
110+
"description": "Jade is a high performance template engine heavily influenced by Haml and implemented with JavaScript for node.",
111+
"logo": "jade.png"
112+
},
113+
"haml": {
114+
"key": "haml",
115+
"title": "HAML",
116+
"url": "http://haml.info/",
117+
"description": "Beautiful, DRY, well-indented, clear markup: templating haiku.",
118+
"logo": "haml.png"
119+
},
120+
"handlebars": {
121+
"key": "handlebars",
122+
"title": "Handlebars",
123+
"url": "http://handlebarsjs.com/",
124+
"description": "Handlebars provides the power necessary to let you build semantic templates effectively with no frustration.",
125+
"logo": "handlebars.png"
105126
}
106127
}
107128

app/templates/_package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"gulp-angular-filesort": "~1.0.4",
99
"gulp-angular-templatecache": "~1.4.2",
1010
"del": "~0.1.3",
11+
"gulp-consolidate": "~0.1.2",
1112
"gulp-csso": "~0.2.9",
1213
"gulp-filter": "~1.0.2",
1314
"gulp-flatten": "~0.0.4",
@@ -19,6 +20,7 @@
1920
"gulp-useref": "~1.0.2",
2021
"gulp-ng-annotate": "~0.3.6",
2122
"gulp-replace": "~0.5.0",
23+
"gulp-rename": "~1.2.0",
2224
"gulp-rev": "~2.0.1",
2325
"gulp-rev-replace": "~0.3.1",
2426
"gulp-minify-html": "~0.1.7",
@@ -39,7 +41,8 @@
3941
"http-proxy": "~1.7.0",
4042
"chalk": "~0.5.1",
4143
"protractor": "~1.4.0",
42-
"uglify-save-license": "~0.4.1"
44+
"uglify-save-license": "~0.4.1"<% if(npmDevDependencies.length > 0) { %>,<% } %>
45+
<%= npmDevDependencies.join(',\n ') %>
4346
},
4447
"engines": {
4548
"node": ">=0.10.0"

app/templates/gulp/_build.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ gulp.task('jshint', function () {
7979
});
8080

8181
gulp.task('injector:js', ['jshint', 'injector:css'], function () {
82-
return gulp.src('src/index.html')
82+
return gulp.src(['src/index.html', '.tmp/index.html'])
8383
.pipe($.inject(gulp.src([
8484
'src/{app,components}/**/*.js',
8585
'!src/{app,components}/**/*.spec.js',
@@ -91,8 +91,8 @@ gulp.task('injector:js', ['jshint', 'injector:css'], function () {
9191
.pipe(gulp.dest('src/'));
9292
});
9393

94-
gulp.task('partials', function () {
95-
return gulp.src('src/{app,components}/**/*.html')
94+
gulp.task('partials', <% if (!_.isEmpty(props.htmlPreprocessors)) { %>['consolidate'], <% } %>function () {
95+
return gulp.src(['src/{app,components}/**/*.html', '.tmp/{app,components}/**/*.html'])
9696
.pipe($.minifyHtml({
9797
empty: true,
9898
spare: true,
@@ -110,7 +110,7 @@ gulp.task('html', ['wiredep', 'injector:css', 'injector:js', 'partials'], functi
110110
var cssFilter = $.filter('**/*.css');
111111
var assets;
112112

113-
return gulp.src('src/*.html')
113+
return gulp.src(['src/*.html', '.tmp/*.html'])
114114
.pipe($.inject(gulp.src('.tmp/inject/templateCacheHtml.js', {read: false}), {
115115
starttag: '<!-- inject:partials -->',
116116
ignorePath: '.tmp',

app/templates/gulp/_consolidate.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
var consolidate = require('gulp-consolidate');
4+
var rename = require('gulp-rename');
5+
var gulp = require('gulp');
6+
7+
var engines = [
8+
<%= consolidateParameters.join(',\n ') %>
9+
];
10+
11+
function buildTemplates(engine, src, dest) {
12+
return gulp.src(src)
13+
.pipe(consolidate.apply(this, engine))
14+
.pipe(rename(function (path) {path.extname = '.html';}))
15+
.pipe(gulp.dest(dest));
16+
}
17+
18+
function buildTaskFunction(engine) {
19+
return function() {
20+
buildTemplates(engine, 'src/app/**/*.jade', '.tmp/app/');
21+
buildTemplates(engine, 'src/components/**/*.jade', '.tmp/components/');
22+
};
23+
}
24+
25+
var tasks = [];
26+
27+
for (var i=0, l=engines.length; i < l; i++) {
28+
var engine = engines[i];
29+
30+
gulp.task('consolidate:' + engine[0] + ':app', buildTemplates.bind(this, engine, 'src/app/**/*.jade', '.tmp/app/'));
31+
gulp.task('consolidate:' + engine[0] + ':components', buildTemplates.bind(this, engine, 'src/components/**/*.jade', '.tmp/components/'));
32+
gulp.task('consolidate:' + engine[0], ['consolidate:' + engine[0] + ':app', 'consolidate:' + engine[0] + ':components' ]);
33+
34+
tasks.push('consolidate:' + engine[0]);
35+
}
36+
37+
gulp.task('consolidate', tasks);

app/templates/gulp/_watch.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
var gulp = require('gulp');
44

5-
gulp.task('watch', ['wiredep', 'injector:css', 'injector:js'] ,function () {<% if (props.cssPreprocessor.key === 'less') { %>
5+
gulp.task('watch', [<% if (!_.isEmpty(props.htmlPreprocessors)) { %>'consolidate', <% } %>'wiredep', 'injector:css', 'injector:js'] ,function () {<% if (props.cssPreprocessor.key === 'less') { %>
66
gulp.watch('src/{app,components}/**/*.less', ['injector:css']);<% } else if (props.cssPreprocessor.key === 'node-sass' || props.cssPreprocessor.key === 'ruby-sass') { %>
77
gulp.watch('src/{app,components}/**/*.scss', ['injector:css']);<% } else if (props.cssPreprocessor.key === 'stylus') { %>
88
gulp.watch('src/{app,components}/**/*.styl', ['injector:css']);<% } else { %>
99
gulp.watch('src/{app,components}/**/*.css', ['injector:css']);<% } %>
1010
gulp.watch('src/{app,components}/**/*.js', ['injector:js']);
11+
gulp.watch('src/{app,components}/**/*.js', ['injector:js']);
1112
gulp.watch('src/assets/images/**/*', ['images']);
12-
gulp.watch('bower.json', ['wiredep']);
13+
gulp.watch('bower.json', ['wiredep']);<% _.forEach(consolidateExtensions, function(extension) {%>
14+
gulp.watch('src/{app,components}/**/*.<%= extension %>', ['consolidate:<%= extension %>']);<% }); %>
1315
});

app/templates/gulp/server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ gulp.task('serve', ['watch'], function () {
3939
], [
4040
'.tmp/{app,components}/**/*.css',
4141
'src/assets/images/**/*',
42+
'.tmp/*.html',
43+
'.tmp/{app,components}/**/*.html',
4244
'src/*.html',
4345
'src/{app,components}/**/*.html',
4446
'src/{app,components}/**/*.js'

0 commit comments

Comments
 (0)