Skip to content

Commit d95a1a1

Browse files
authored
Merge pull request #76 from baqudo/master
Update: pug template, gulpfile output
2 parents 6aa630d + e3e22cd commit d95a1a1

File tree

4 files changed

+137
-97
lines changed

4 files changed

+137
-97
lines changed

generators/app/templates/gulp/tasks/pug.js

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,31 @@
1-
var gulp = require('gulp');
2-
var pug = require('gulp-pug');
3-
var plumber = require('gulp-plumber');
4-
var changed = require('gulp-changed');
5-
var gulpif = require('gulp-if');
6-
var frontMatter = require('gulp-front-matter');
7-
var prettify = require('gulp-prettify');
8-
var config = require('../config');
9-
10-
function renderHtml(onlyChanged) {
11-
return gulp
12-
.src([config.src.templates + '/[^_]*.pug'])
13-
.pipe(plumber({ errorHandler: config.errorHandler }))
14-
.pipe(gulpif(onlyChanged, changed(config.dest.html, { extension: '.html' })))
15-
.pipe(frontMatter({ property: 'data' }))
16-
.pipe(pug())
17-
.pipe(prettify({
18-
indent_size: 2,
19-
wrap_attributes: 'auto', // 'force'
20-
preserve_newlines: true,
21-
// unformatted: [],
22-
end_with_newline: true
23-
}))
24-
.pipe(gulp.dest(config.dest.html));
1+
import gulp from 'gulp';
2+
import pug from 'gulp-pug';
3+
import plumber from 'gulp-plumber'
4+
import changed from 'gulp-changed';
5+
import gulpif from 'gulp-if';
6+
import frontMatter from 'gulp-front-matter';
7+
import prettify from 'gulp-prettify';
8+
import config from '../config';
9+
10+
const renderHtml = (onlyChanged) => {
11+
return gulp
12+
.src([config.src.templates + '/[^_]*.pug'])
13+
.pipe(plumber({ errorHandler: config.errorHandler }))
14+
.pipe(gulpif(onlyChanged, changed(config.dest.html, { extension: '.html' })))
15+
.pipe(frontMatter({ property: 'data' }))
16+
.pipe(pug())
17+
.pipe(prettify({
18+
indent_size: 2,
19+
wrap_attributes: 'auto', // 'force'
20+
preserve_newlines: true,
21+
// unformatted: [],
22+
end_with_newline: true
23+
}))
24+
.pipe(gulp.dest(config.dest.html));
2525
}
2626

27-
gulp.task('pug', function() {
28-
return renderHtml();
29-
});
30-
31-
gulp.task('pug:changed', function() {
32-
return renderHtml(true);
33-
});
34-
35-
gulp.task('pug:watch', function() {
36-
gulp.watch([config.src.templates + '/**/_*.pug'], ['pug']);
37-
gulp.watch([config.src.templates + '/**/[^_]*.pug'], ['pug:changed']);
38-
});
39-
27+
gulp.task('pug', () => renderHtml());
28+
gulp.task('pug:changed', () => renderHtml(true));
4029

4130
const build = gulp => gulp.parallel('pug');
4231
const watch = gulp => {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
var gulp = require('gulp');
2+
var swig = require('gulp-swig');
3+
var plumber = require('gulp-plumber');
4+
var gulpif = require('gulp-if');
5+
var changed = require('gulp-changed');
6+
var prettify = require('gulp-prettify');
7+
var frontMatter = require('gulp-front-matter');
8+
var config = require('../config');
9+
10+
function renderHtml(onlyChanged) {
11+
return gulp
12+
.src([config.src.templates + '/**/[^_]*.html'])
13+
.pipe(plumber({
14+
errorHandler: config.errorHandler
15+
}))
16+
.pipe(gulpif(onlyChanged, changed(config.dest.html)))
17+
.pipe(frontMatter({ property: 'data' }))
18+
.pipe(swig({
19+
load_json: true,
20+
json_path: config.src.templatesData,
21+
defaults: {
22+
cache: false
23+
}
24+
}))
25+
.pipe(prettify({
26+
indent_size: 2,
27+
wrap_attributes: 'auto', // 'force'
28+
preserve_newlines: true,
29+
// unformatted: [],
30+
31+
end_with_newline: true
32+
}))
33+
.pipe(gulp.dest(config.dest.html));
34+
}
35+
36+
gulp.task('swig', function() {
37+
return renderHtml();
38+
});
39+
40+
gulp.task('swig:changed', function() {
41+
return renderHtml(true);
42+
});
43+
44+
gulp.task('swig:watch', function() {
45+
gulp.watch([
46+
config.src.templates + '/**/[^_]*.html'
47+
], ['swig:changed']);
48+
49+
gulp.watch([
50+
config.src.templates + '/**/_*.html',
51+
config.src.templatesData + '/*.json'
52+
], ['swig']);
53+
});

generators/app/templates/gulpfile.babel.js

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,25 @@ import config from './gulp/config';
44
const getTaskBuild = task => require('./gulp/tasks/' + task).build(gulp);
55
const getTaskWatch = task => require('./gulp/tasks/' + task).watch(gulp);
66

7-
8-
9-
10-
11-
127
gulp.task('clean', getTaskBuild('clean'));
138
gulp.task('copy', getTaskBuild('copy'));
14-
gulp.task('nunjucks', () => getTaskBuild('nunjucks'));
15-
gulp.task('sass', () => getTaskBuild('sass'));
16-
gulp.task('server', () => getTaskBuild('server'));
17-
gulp.task('svgo', () => getTaskBuild('svgo'));
9+
gulp.task('server', () => getTaskBuild('server'));<% if (templates === 'nunjucks') { %>
10+
gulp.task('nunjucks', () => getTaskBuild('nunjucks'));<% } %><% if (templates === 'pug') { %>
11+
gulp.task('pug', () => getTaskBuild('pug'));<% } %><% if (css === 'sass') { %>
12+
gulp.task('sass', () => getTaskBuild('sass'));<% } %><% if (sprites.indexOf('svg') !== -1) { %>
13+
gulp.task('sprite:svg', () => getTaskBuild('sprite-svg'));<% } %><% if (svgo) { %>
14+
gulp.task('svgo', () => getTaskBuild('svgo'));<% } %><% if (preview) { %>
15+
gulp.task('list-pages', getTaskBuild('list-pages'));<% } %>
1816
gulp.task('webpack', getTaskBuild('webpack'));
19-
gulp.task('list-pages', getTaskBuild('list-pages'));
20-
gulp.task('sprite:svg', () => getTaskBuild('sprite-svg'));
2117

22-
gulp.task('copy:watch', getTaskWatch('copy'));
23-
gulp.task('nunjucks:watch', getTaskWatch('nunjucks'));
24-
gulp.task('sass:watch', getTaskWatch('sass'));
25-
gulp.task('svgo:watch', getTaskWatch('svgo'));
18+
gulp.task('copy:watch', getTaskWatch('copy'));<% if (templates === 'nunjucks') { %>
19+
gulp.task('nunjucks:watch', getTaskWatch('nunjucks'));<% } %><% if (templates === 'pug') { %>
20+
gulp.task('pug:watch', getTaskWatch('pug'));<% } %><% if (css === 'sass') { %>
21+
gulp.task('sass:watch', getTaskWatch('sass'));<% } %><% if (sprites.indexOf('svg') !== -1) { %>
22+
gulp.task('sprite:svg:watch', getTaskWatch('sprite-svg'));<% } %><% if (svgo) { %>
23+
gulp.task('svgo:watch', getTaskWatch('svgo'));<% } %><% if (preview) { %>
24+
gulp.task('list-pages:watch', getTaskWatch('list-pages'));<% } %>
2625
gulp.task('webpack:watch', getTaskWatch('webpack'));
27-
gulp.task('list-pages:watch', getTaskWatch('list-pages'));
28-
gulp.task('sprite:svg:watch', getTaskWatch('sprite-svg'));
2926

3027
const setmodeProd = done => {
3128
config.setEnv('production');
@@ -35,53 +32,53 @@ const setmodeProd = done => {
3532

3633
const setmodeDev = done => {
3734
config.setEnv('development');
38-
config.logEnv();
35+
config.logEnv();
3936
done();
4037
}
4138

4239
gulp.task(
4340
'build',
4441
gulp.series(
4542
setmodeProd,
46-
'clean',
47-
<% if (sprites.indexOf('svg') !== -1) { %>'sprite:svg',<% } %>
48-
<% if (svgo) { %>'svgo',<% } %>
49-
<% if (css === 'sass') { %>'sass',<% } %>
50-
<% if (templates === 'nunjucks') { %>'nunjucks',<% } %>
51-
<% if (templates === 'pug') { %>'pug',<% } %>
52-
'webpack',
53-
'copy',
54-
<% if (preview) { %>'list-pages'<% } %>
55-
)
43+
'clean',<% if (sprites.indexOf('svg') !== -1) { %>
44+
'sprite:svg',<% } %><% if (svgo) { %>
45+
'svgo',<% } %><% if (css === 'sass') { %>
46+
'sass',<% } %><% if (templates === 'nunjucks') { %>
47+
'nunjucks',<% } %><% if (templates === 'pug') { %>
48+
'pug',<% } %>
49+
'webpack',<% if (preview) { %>
50+
'list-pages',<% } %>
51+
'copy'
52+
)
5653
);
5754

5855
gulp.task(
5956
'build:dev',
6057
gulp.series(
6158
setmodeDev,
62-
'clean',
63-
<% if (sprites.indexOf('svg') !== -1) { %>'sprite:svg',<% } %>
64-
<% if (svgo) { %>'svgo',<% } %>
65-
<% if (css === 'sass') { %>'sass',<% } %>
66-
<% if (templates === 'nunjucks') { %>'nunjucks',<% } %>
67-
<% if (templates === 'pug') { %>'pug',<% } %>
68-
'webpack',
69-
<% if (preview) { %>'list-pages',<% } %>
59+
'clean',<% if (sprites.indexOf('svg') !== -1) { %>
60+
'sprite:svg',<% } %><% if (svgo) { %>
61+
'svgo',<% } %><% if (css === 'sass') { %>
62+
'sass',<% } %><% if (templates === 'nunjucks') { %>
63+
'nunjucks',<% } %><% if (templates === 'pug') { %>
64+
'pug',<% } %>
65+
'webpack',<% if (preview) { %>
66+
'list-pages',<% } %>
7067
'copy'
7168
)
7269
);
7370

7471
gulp.task(
7572
'watch',
7673
gulp.parallel(
77-
'copy:watch',
78-
<% if (templates === 'nunjucks') { %>'nunjucks:watch',<% } %>
79-
<% if (templates === 'pug') { %>'pug:watch',<% } %>
80-
<% if (sprites.indexOf('svg') !== -1) { %>'sprite:svg:watch',<% } %>
81-
<% if (svgo) { %>'svgo:watch',<% } %>
82-
<% if (preview) { %>'list-pages:watch',<% } %>
83-
'webpack:watch',
84-
<% if (css === 'sass') { %>'sass:watch'<% } %>
74+
'copy:watch',<% if (templates === 'nunjucks') { %>
75+
'nunjucks:watch',<% } %><% if (templates === 'pug') { %>
76+
'pug:watch',<% } %><% if (sprites.indexOf('svg') !== -1) { %>
77+
'sprite:svg:watch',<% } %><% if (svgo) { %>
78+
'svgo:watch',<% } %><% if (preview) { %>
79+
'list-pages:watch',<% } %>
80+
'webpack:watch',<% if (css === 'sass') { %>
81+
'sass:watch'<% } %>
8582
)
8683
);
8784

generators/app/writing.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ module.exports = function () {
3636
this.fs.copy(this.templatePath('gulp/util/handle-errors.js'),'gulp/util/handle-errors.js');
3737

3838
// common tasks
39-
this.fs.copyTpl(this.templatePath('gulp/tasks/default.js'),'gulp/tasks/default.js');
39+
// this.fs.copyTpl(this.templatePath('gulp/tasks/default.js'),'gulp/tasks/default.js');
4040
// this.fs.copyTpl(this.templatePath('gulp/tasks/build.js'),'gulp/tasks/build.js', props);
41-
4241
// this.fs.copyTpl(this.templatePath('gulp/tasks/watch.js'),'gulp/tasks/watch.js', props);
42+
4343
this.fs.copyTpl(this.templatePath('gulp/tasks/copy.js'),'gulp/tasks/copy.js', props);
44-
4544
this.fs.copy(this.templatePath('gulp/tasks/clean.js'),'gulp/tasks/clean.js');
4645
this.fs.copy(this.templatePath('gulp/tasks/server.js'),'gulp/tasks/server.js');
4746

48-
this.fs.copy(this.templatePath('gulp/tasks/index/index.html'),'gulp/tasks/index/index.html');
49-
this.fs.copy(this.templatePath('gulp/tasks/list-pages.js'),'gulp/tasks/list-pages.js');
50-
47+
if(props.preview){
48+
this.fs.copy(this.templatePath('gulp/tasks/index/index.html'),'gulp/tasks/index/index.html');
49+
this.fs.copy(this.templatePath('gulp/tasks/list-pages.js'),'gulp/tasks/list-pages.js');
50+
}
5151

5252

5353
this.sprites = props.sprites; // or in /templates/src/sass/app.sass use options.sprites
@@ -172,27 +172,28 @@ module.exports = function () {
172172
this.fs.copyTpl(this.templatePath('src/sass/app.sss'), 'src/sass/app.sss',props);
173173
}
174174

175-
176-
177-
178-
179-
180175

181176
switch (props.templates) {
182177
case 'nunjucks':
183178
this.fs.copy(this.templatePath('src/templates-nunjucks'), 'src/templates');
184-
this.fs.delete('src/templates/page.html');
185-
this.fs.copy(this.templatePath('src/templates-nunjucks/page.html'), 'src/templates/index.html');
179+
if(!props.preview){
180+
this.fs.delete('src/templates/page.html');
181+
this.fs.copy(this.templatePath('src/templates-nunjucks/page.html'), 'src/templates/index.html');
182+
}
183+
break;
184+
case 'pug':
185+
this.fs.copy(this.templatePath('src/templates-pug'), 'src/templates');
186+
if(!props.preview){
187+
this.fs.delete('src/templates/page.pug');
188+
this.fs.copy(this.templatePath('src/templates-pug/page.pug'), 'src/templates/index.pug');
189+
}
186190
break;
187191
case 'swig':
188192
this.fs.copy(this.templatePath('src/templates-swig'), 'src/templates');
189193
break;
190194
case 'jade':
191195
this.fs.copy(this.templatePath('src/templates-jade'), 'src/templates');
192196
break;
193-
case 'pug':
194-
this.fs.copy(this.templatePath('src/templates-pug'), 'src/templates');
195-
break;
196197
case 'html':
197198
this.fs.copy(this.templatePath('src/templates-html'), 'src');
198199
break;

0 commit comments

Comments
 (0)