Skip to content

Commit de2d9f7

Browse files
committed
Added twig-js and data for templating
1 parent 0b0fdaf commit de2d9f7

35 files changed

+2778
-1
lines changed

gulpfile.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var settings = {
88
scripts: true,
99
polyfills: true,
1010
styles: true,
11+
templates: true,
1112
svgs: true,
1213
copy: true,
1314
reload: true
@@ -30,6 +31,11 @@ var paths = {
3031
input: 'src/sass/**/*.{scss,sass}',
3132
output: 'dist/css/'
3233
},
34+
templates: {
35+
twig: 'src/templates/**/*.twig',
36+
html_pages: 'src/templates/pages/**/*.twig',
37+
dataJson: 'src/data/**/*.json',
38+
},
3339
svgs: {
3440
input: 'src/svg/*.svg',
3541
output: 'dist/svg/'
@@ -91,6 +97,11 @@ var sourcemaps = require('gulp-sourcemaps');
9197
var prefix = require('gulp-autoprefixer');
9298
var minify = require('gulp-cssnano');
9399

100+
// Templates
101+
var twig = require('gulp-twig'),
102+
path = require('path'),
103+
data = require('gulp-data');
104+
94105
// SVGs
95106
var svgmin = require('gulp-svgmin');
96107

@@ -221,6 +232,46 @@ var buildStyles = function (done) {
221232

222233
};
223234

235+
236+
237+
// // Generate templates
238+
// gulp.task('templates', function () {
239+
// return gulp.src(src.html_pages)
240+
// .pipe(data(function (file) {
241+
// var dataPath = '../data/' + path.join(path.relative("../templates/pages", path.dirname(file.path)), path.basename(file.path, '.twig')) + '.json';
242+
// return requireUncached(dataPath);
243+
// }))
244+
// .pipe(twig())
245+
// .pipe(prettify({indent_char: ' ', indent_size: 2}))
246+
// .pipe(gulp.dest('../'))
247+
// .on("end", reload);
248+
// });
249+
250+
// paths.
251+
// templates: {
252+
// twig: '../templates/**/*.twig',
253+
// html_pages: '../templates/pages/**/*.twig',
254+
// dataJson: '../data/**/*.json',
255+
// },
256+
257+
// Generate html from templates and data
258+
var buildTemplates = function(done) {
259+
260+
//if (!settings.templates) return done();
261+
262+
return src(paths.templates.html_pages)
263+
// .pipe(data(function (file) {
264+
// var dataPath = 'src/data/' + path.join(path.relative("src/templates/pages", path.dirname(file.path)), path.basename(file.path, '.twig')) + '.json';
265+
// return requireUncached(dataPath);
266+
// }))
267+
.pipe(twig())
268+
//.pipe(prettify({indent_char: ' ', indent_size: 2}))
269+
.pipe(dest(paths.output));
270+
};
271+
272+
273+
274+
224275
// Optimize SVG files
225276
var buildSVGs = function (done) {
226277

@@ -291,6 +342,7 @@ exports.default = series(
291342
buildScripts,
292343
lintScripts,
293344
buildStyles,
345+
buildTemplates,
294346
buildSVGs,
295347
copyFiles
296348
)

package-lock.json

Lines changed: 206 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"gulp-autoprefixer": "6.1.0",
2626
"gulp-concat": "2.6.1",
2727
"gulp-cssnano": "2.1.3",
28+
"gulp-data": "^1.3.1",
2829
"gulp-flatmap": "1.0.2",
2930
"gulp-header": "2.0.7",
3031
"gulp-jshint": "2.1.0",
@@ -34,9 +35,11 @@
3435
"gulp-sourcemaps": "^2.6.5",
3536
"gulp-svgmin": "2.2.0",
3637
"gulp-terser": "1.2.0",
38+
"gulp-twig": "^1.2.0",
3739
"jshint": "2.10.2",
3840
"jshint-stylish": "2.2.1",
3941
"lazypipe": "1.0.2",
40-
"node-normalize-scss": "^8.0.0"
42+
"node-normalize-scss": "^8.0.0",
43+
"path": "^0.12.7"
4144
}
4245
}

0 commit comments

Comments
 (0)