@videinfra/static-website-builder 1.9.1 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## [1.10.1] - 2024-02-13
8
+ ### Fixed
9
+ - TWIG config
10
+
11
+ ## [1.10.0] - 2024-02-13
12
+ ### Updated
13
+ - Changed TWIG to use async mode by default, added option
14
+ - Enabled TWIG cache for improved production builds
15
+
7
16
  ## [1.9.1] - 2023-11-01
8
17
  ### Fixed
9
18
  - Fixed public path for dynamic imports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@videinfra/static-website-builder",
3
- "version": "1.9.1",
3
+ "version": "1.10.1",
4
4
  "description": "Customizable static site project builder",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -50,11 +50,12 @@
50
50
  "gulp-sourcemaps": "^3.0.0",
51
51
  "gulp-svgmin": "^4.1.0",
52
52
  "gulp-svgstore": "^9.0.0",
53
- "gulp-twig": "^1.2.0",
53
+ "map-stream": "^0.1.0",
54
54
  "minimist": "^1.2.8",
55
55
  "nano-memoize": "1.3.0",
56
56
  "node-sass": "^7.0.3",
57
57
  "sass": "^1.65.1",
58
+ "twig": "^1.10.5",
58
59
  "webpack": "^4.46.0",
59
60
  "webpack-stream": "^5.2.1"
60
61
  },
@@ -1,4 +1,4 @@
1
- const twig = require('gulp-twig');
1
+ const twig = require('../../vendor/gulp-twig/index');
2
2
  const getConfig = require('./../../lib/get-config');
3
3
  const getPaths = require('./../../lib/get-path');
4
4
  const flattenDeep = require('lodash/flattenDeep');
package/plugins/twig.js CHANGED
@@ -27,6 +27,12 @@ exports.html = {
27
27
  },
28
28
 
29
29
  twig: {
30
+ // Async rendering
31
+ async: true,
32
+
33
+ // Disabled cache by default, it's enabled for production build only
34
+ cache: false,
35
+
30
36
  // Custom functions
31
37
  functions: [
32
38
  // require('../../plugins/twig/symfony-functions.js'),
@@ -36,7 +42,13 @@ exports.html = {
36
42
  filters: [
37
43
  // require('../../plugins/twig/lodash-filters.js'),
38
44
  // require('../../plugins/twig/symfony-functions.js'),
39
- ]
45
+ ],
46
+
47
+ // Production only settings, overwrites default settings
48
+ production: {
49
+ // Enable cache for improved performance during production build
50
+ cache: true,
51
+ },
40
52
  },
41
53
 
42
54
  // List of CDNs when using symphony filters / funtions
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Simon de Turck <simon@zimmen.com> www.zimmen.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,167 @@
1
+ [![Build Status](https://travis-ci.org/zimmen/gulp-twig.png?branch=master)](https://travis-ci.org/zimmen/gulp-twig)
2
+
3
+ <table>
4
+ <tr>
5
+ <td>Package</td><td>gulp-twig</td>
6
+ </tr>
7
+ <tr>
8
+ <td>Description</td>
9
+ <td>Twig plugin for gulp.js, The streaming build system</td>
10
+ </tr>
11
+ <tr>
12
+ <td>Node Version</td>
13
+ <td>>= 4</td>
14
+ </tr>
15
+ <tr>
16
+ <td>Gulp Version</td>
17
+ <td>3.x</td>
18
+ </tr>
19
+ </table>
20
+
21
+
22
+ Compile [Twig.js](https://github.com/justjohn/twig.js) templates with Gulp. Build upon [Twig.js](https://github.com/justjohn/twig.js) , the JS port of the Twig templating language by John Roepke.
23
+
24
+ You can use this plugin with [gulp-data](https://www.npmjs.com/package/gulp-data).
25
+
26
+ ## Usage
27
+
28
+ ### Install
29
+
30
+ ```bash
31
+ npm install gulp-twig --save
32
+ ```
33
+ ### Example
34
+
35
+ ```html
36
+ {# index.twig #}
37
+ {% extends "layout.twig" %}
38
+
39
+ {% block page %}
40
+ <header>
41
+ <h1>Gulp and Twig.js</h1>
42
+ </header>
43
+ <p>
44
+ This page is generated by Twig.js using the gulp-twig gulp plugin.
45
+ </p>
46
+ <ul>
47
+ {% for value in benefits %}
48
+ <li>{{ value }}</li>
49
+ {% endfor %}
50
+ </ul>
51
+ {% endblock %}
52
+ ```
53
+
54
+ ```html
55
+ {# layout.twig #}
56
+ <!DOCTYPE html>
57
+ <html>
58
+ <head>
59
+ <meta charset="utf-8"/>
60
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
61
+ <meta name="description" content="A demo of how to use gulp-twig"/>
62
+ <meta name="author" content="Simon de Turck"/>
63
+ <meta name="viewport" content="width=device-width,initial-scale=1">
64
+
65
+ <title>{{ title }}</title>
66
+
67
+ </head>
68
+ <body>
69
+ <section>
70
+ {% block page %}{% endblock %}
71
+ </section>
72
+ </body>
73
+ </html>
74
+ ```
75
+
76
+ ```javascript
77
+ var gulp = require('gulp');
78
+
79
+ gulp.task('compile', function () {
80
+ 'use strict';
81
+ var twig = require('gulp-twig');
82
+ return gulp.src('./index.twig')
83
+ .pipe(twig({
84
+ data: {
85
+ title: 'Gulp and Twig',
86
+ benefits: [
87
+ 'Fast',
88
+ 'Flexible',
89
+ 'Secure'
90
+ ]
91
+ }
92
+ }))
93
+ .pipe(gulp.dest('./'));
94
+ });
95
+
96
+ gulp.task('default', ['compile']);
97
+ ```
98
+
99
+ ### Options:
100
+ **data**: [object| *The data that is exposed in the twig files. Or use gulp-data to pipe files directly into gulp-twig*
101
+
102
+ **base**: [string] *sets the views base folder. Extends can be loaded relative to this path*
103
+
104
+ **errorLogToConsole**: [true|false] *logs errors to console (defaults to false)*
105
+
106
+ **onError**: [function] *handle error yourself*
107
+
108
+ **cache**: [true|false] *enables the Twig cache. (defaults to false)*
109
+
110
+ **debug**: [true|false] *enables debug info logging (defaults to false)*
111
+
112
+ **trace**: [true|false] *enables tracing info logging (defaults to false)*
113
+
114
+ **extend**: [function (Twig)] *extends Twig with new tags types. The Twig attribute is Twig.js's internal object. [Read more here](https://github.com/justjohn/twig.js/wiki/Extending-twig.js-With-Custom-Tags)*
115
+
116
+ **extname**: [string|true|false] *output file extension including the '.' like path.extname(filename). Use `true` to keep source extname and a "falsy" value to drop the file extension*
117
+
118
+ **useFileContents**: [true|false] *use file contents instead of file path (defaults to false) [Read more here](https://github.com/zimmen/gulp-twig/issues/30)*
119
+
120
+ **functions**: [array] *extends Twig with given function objects. (default to undefined)*
121
+ ```javascript
122
+ [
123
+ {
124
+ name: "nameOfFunction",
125
+ func: function (args) {
126
+ return "the function";
127
+ }
128
+ }
129
+ ]
130
+ ```
131
+
132
+ **filters**: [array] *extends Twig with given filter objects. (default to undefined)*
133
+ ```javascript
134
+ [
135
+ {
136
+ name: "nameOfFilter",
137
+ func: function (args) {
138
+ return "the filter";
139
+ }
140
+ }
141
+ ]
142
+ ```
143
+ ### LICENSE
144
+
145
+ (MIT License)
146
+
147
+ Copyright (c) 2015 Simon de Turck <simon@zimmen.com> www.zimmen.com
148
+
149
+ Permission is hereby granted, free of charge, to any person obtaining
150
+ a copy of this software and associated documentation files (the
151
+ "Software"), to deal in the Software without restriction, including
152
+ without limitation the rights to use, copy, modify, merge, publish,
153
+ distribute, sublicense, and/or sell copies of the Software, and to
154
+ permit persons to whom the Software is furnished to do so, subject to
155
+ the following conditions:
156
+
157
+ The above copyright notice and this permission notice shall be
158
+ included in all copies or substantial portions of the Software.
159
+
160
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
161
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
162
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
163
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
164
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
165
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
166
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
167
+
@@ -0,0 +1,130 @@
1
+ // 2024-02-13, Kaspars Zuks: added "options.async" support
2
+ var map = require('map-stream');
3
+ var rext = require('replace-ext');
4
+ var log = require('fancy-log');
5
+ var PluginError = require('plugin-error');
6
+
7
+ const PLUGIN_NAME = 'gulp-twig';
8
+
9
+ module.exports = function (options) {
10
+ 'use strict';
11
+ options = Object.assign({}, {
12
+ changeExt: true,
13
+ extname: '.html',
14
+ useFileContents: false,
15
+ async: true,
16
+ }, options || {});
17
+
18
+ function modifyContents(file, cb) {
19
+ var data = file.data || Object.assign({}, options.data);
20
+
21
+ if (file.isNull()) {
22
+ return cb(null, file);
23
+ }
24
+
25
+ if (file.isStream()) {
26
+ return cb(new PluginError(PLUGIN_NAME, 'Streaming not supported!'));
27
+ }
28
+
29
+ data._file = file;
30
+ if(options.changeExt === false || options.extname === true){
31
+ data._target = {
32
+ path: file.path,
33
+ relative: file.relative
34
+ }
35
+ }else{
36
+ data._target = {
37
+ path: rext(file.path, options.extname || ''),
38
+ relative: rext(file.relative, options.extname || '')
39
+ }
40
+ }
41
+
42
+ var Twig = require('twig'),
43
+ twig = Twig.twig,
44
+ twigOpts = {
45
+ path: file.path,
46
+ async: false
47
+ },
48
+ template;
49
+
50
+ if (options.debug !== undefined) {
51
+ twigOpts.debug = options.debug;
52
+ }
53
+ if (options.trace !== undefined) {
54
+ twigOpts.trace = options.trace;
55
+ }
56
+ if (options.base !== undefined) {
57
+ twigOpts.base = options.base;
58
+ }
59
+ if (options.namespaces !== undefined) {
60
+ twigOpts.namespaces = options.namespaces;
61
+ }
62
+ if (options.cache !== true) {
63
+ Twig.cache(false);
64
+ }
65
+
66
+ if (options.functions) {
67
+ options.functions.forEach(function (func) {
68
+ Twig.extendFunction(func.name, func.func);
69
+ });
70
+ }
71
+
72
+ if (options.filters) {
73
+ options.filters.forEach(function (filter) {
74
+ Twig.extendFilter(filter.name, filter.func);
75
+ });
76
+ }
77
+
78
+ if(options.extend) {
79
+ Twig.extend(options.extend);
80
+ delete options.extend;
81
+ }
82
+
83
+ if (options.useFileContents) {
84
+ var fileContents = file.contents.toString();
85
+ twigOpts.data = fileContents
86
+ }
87
+
88
+ template = twig(twigOpts);
89
+
90
+ if (options.async) {
91
+ template.renderAsync(data)
92
+ .then(function (output) {
93
+ file.contents = new Buffer(output);
94
+ file.path = data._target.path;
95
+ cb(null, file);
96
+ })
97
+ .catch(function (e) {
98
+ if (options.errorLogToConsole) {
99
+ log(PLUGIN_NAME + ' ' + e);
100
+ cb();
101
+ } else if (typeof options.onError === 'function') {
102
+ options.onError(e);
103
+ cb();
104
+ } else {
105
+ cb(new PluginError(PLUGIN_NAME, e));
106
+ }
107
+ });
108
+ } else {
109
+ try {
110
+ file.contents = new Buffer(template.render(data));
111
+ }catch(e){
112
+ if (options.errorLogToConsole) {
113
+ log(PLUGIN_NAME + ' ' + e);
114
+ return cb();
115
+ }
116
+
117
+ if (typeof options.onError === 'function') {
118
+ options.onError(e);
119
+ return cb();
120
+ }
121
+ return cb(new PluginError(PLUGIN_NAME, e));
122
+ }
123
+
124
+ file.path = data._target.path;
125
+ cb(null, file);
126
+ }
127
+ }
128
+
129
+ return map(modifyContents);
130
+ };
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "gulp-twig",
3
+ "description": "Twig.js plugin for gulp.js (gulpjs.com)",
4
+ "version": "1.2.0",
5
+ "homepage": "http://github.com/zimmen/gulp-twig",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "http://github.com/zimmen/gulp-twig.git"
9
+ },
10
+ "author": "Simon de Turck <simon@zimmen.com> (http://www.zimmen.com)",
11
+ "main": "./index.js",
12
+ "dependencies": {
13
+ "fancy-log": "^1.3.2",
14
+ "map-stream": "^0.1.0",
15
+ "plugin-error": "^0.1.2",
16
+ "replace-ext": "^1.0.0",
17
+ "twig": "^1.10.5"
18
+ },
19
+ "devDependencies": {
20
+ "mocha": "*",
21
+ "should": "*",
22
+ "vinyl": "^2.1.0"
23
+ },
24
+ "scripts": {
25
+ "test": "mocha -R spec"
26
+ },
27
+ "engines": {
28
+ "node": ">=4.0"
29
+ },
30
+ "keywords": [
31
+ "twig",
32
+ "twig.js",
33
+ "gulp",
34
+ "gulpplugin",
35
+ "gulp-plugin"
36
+ ],
37
+ "licenses": [
38
+ {
39
+ "type": "MIT",
40
+ "url": "http://github.com/zimmen/gulp-twig/raw/master/LICENSE"
41
+ }
42
+ ]
43
+ }