@videinfra/static-website-builder 2.0.2 → 2.0.4
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/.prettierrc +11 -11
- package/CHANGELOG.md +214 -210
- package/README.md +102 -102
- package/bin/builder.js +40 -40
- package/eslint.config.js +39 -39
- package/gulpfile.js +63 -63
- package/init/default/config/config.js +44 -44
- package/init/default/src/html/data/global.js +9 -9
- package/init/default/src/javascripts/_entries.js +14 -14
- package/init/index.js +63 -63
- package/init/test/.env +6 -6
- package/init/test/.env.local +3 -2
- package/init/test/config/config.js +71 -67
- package/init/test/src/html/404.twig +12 -12
- package/init/test/src/html/data/global.js +10 -10
- package/init/test/src/html/env.twig +21 -21
- package/init/test/src/html/layouts/base.twig +1 -1
- package/init/test/src/html/other.twig +9 -9
- package/init/test/src/html/preposition.twig +4 -4
- package/init/test/src/javascripts/_entries-alt.js +10 -10
- package/init/test/src/javascripts/_entries.js +19 -19
- package/init/test/src/javascripts/common.js +13 -13
- package/init/test/src/javascripts/main.js +8 -8
- package/init/test/src/javascripts/something.ts +9 -9
- package/init/test/src/stylesheets/autoprefixer-test.scss +3 -3
- package/init/test/src/stylesheets/env-test.scss +28 -28
- package/init/test/src/stylesheets/ignore-test.scss +4 -4
- package/init/test/src/stylesheets/nested-calc-test.scss +3 -3
- package/init/test/src/stylesheets/sub-folder/import-test.scss +2 -2
- package/lib/camelize-file-name.js +21 -21
- package/lib/generate-gulp-tasks.js +85 -85
- package/lib/get-config.js +203 -204
- package/lib/get-file-names.js +23 -23
- package/lib/get-path.js +102 -102
- package/lib/globs-helper.js +243 -243
- package/lib/gulp/dynamic-task.js +8 -8
- package/lib/gulp/resolve-dynamic-task.js +11 -11
- package/lib/gulp/task-before-dest.js +8 -8
- package/lib/gulp/task-end.js +10 -10
- package/lib/gulp/task-start.js +12 -12
- package/lib/gulp/task-watch.js +66 -66
- package/lib/init/copy-folder.js +50 -50
- package/lib/init/folder-exists.js +10 -10
- package/lib/init/get-folder-list.js +16 -16
- package/lib/init/merge-package.js +17 -17
- package/lib/init/read-package.js +17 -17
- package/lib/log-error.js +15 -15
- package/lib/merge.js +27 -27
- package/lib/run-preprocess.js +32 -32
- package/lib/task-order.js +19 -19
- package/package.json +68 -68
- package/plugins/example/preprocess-config.js +17 -17
- package/plugins/example/task.js +55 -55
- package/plugins/example.js +38 -38
- package/plugins/sass-engine/preprocess-config.js +59 -59
- package/plugins/sass.js +41 -41
- package/plugins/twig/lodash-filters/filters.js +91 -91
- package/plugins/twig/lodash-filters.js +14 -14
- package/plugins/twig/symfony-filters/filters.js +102 -102
- package/plugins/twig/symfony-filters/preposition_nbsp.js +77 -77
- package/plugins/twig/symfony-filters.js +14 -14
- package/plugins/twig/symfony-functions/functions.js +31 -31
- package/plugins/twig/symfony-functions.js +14 -14
- package/plugins/twig-engine/preprocess-config.js +53 -53
- package/plugins/twig.js +74 -74
- package/tasks/browser-sync/config.js +39 -39
- package/tasks/browser-sync/preprocess-config.js +32 -32
- package/tasks/browser-sync/task.js +9 -9
- package/tasks/clean/config.js +20 -20
- package/tasks/clean/preprocess-config.js +19 -19
- package/tasks/clean/task.js +7 -7
- package/tasks/data/config.js +34 -34
- package/tasks/data/data-loader-js.js +14 -14
- package/tasks/data/data-loader-json.js +5 -5
- package/tasks/data/get-data.js +96 -96
- package/tasks/env/config.js +26 -23
- package/tasks/env/get-env.js +113 -81
- package/tasks/fonts/config.js +24 -24
- package/tasks/fonts/task.js +47 -47
- package/tasks/global/config.js +7 -7
- package/tasks/html/config.js +42 -42
- package/tasks/html/task.js +91 -91
- package/tasks/icons/config.js +47 -47
- package/tasks/icons/preprocess-config.js +60 -60
- package/tasks/icons/task.js +56 -56
- package/tasks/images/config.js +27 -27
- package/tasks/images/task.js +46 -46
- package/tasks/javascripts/config.js +69 -69
- package/tasks/javascripts/preprocess-config.js +109 -109
- package/tasks/javascripts/task.js +86 -86
- package/tasks/sitemap/config.js +48 -48
- package/tasks/sitemap/preprocess-config.js +18 -18
- package/tasks/sitemap/task.js +69 -69
- package/tasks/sizereport/config.js +23 -23
- package/tasks/sizereport/task.js +16 -16
- package/tasks/static/config.js +27 -27
- package/tasks/static/task.js +46 -46
- package/tasks/stylesheets/config.js +85 -85
- package/tasks/stylesheets/preprocess-config.js +41 -41
- package/tasks/stylesheets/task.js +73 -73
- package/tests/build/build.test.js +153 -153
- package/tests/camelize-file-name.test.js +11 -11
- package/tests/generate-gulp-tasks.test.js +78 -78
- package/tests/glob-helper.test.js +99 -99
- package/tests/merge.test.js +10 -10
- package/tests/preposition_nbsp.test.js +50 -50
- package/tests/run-preprocess.test.js +90 -90
- package/tests/sass-stringify.test.js +24 -24
- package/tests/sitemap.test.js +12 -12
- package/vendor/gulp-rolldown/index.js +151 -151
- package/vendor/gulp-rolldown/plugin-raw.js +17 -17
- package/vendor/gulp-rolldown/plugin-virtual-entry.js +30 -30
- package/vendor/gulp-sass/CHANGELOG.md +168 -168
- package/vendor/gulp-sass/LICENSE +20 -20
- package/vendor/gulp-sass/README.md +187 -187
- package/vendor/gulp-sass/index.js +208 -208
- package/vendor/gulp-sass/package.json +61 -61
- package/vendor/gulp-sass/sass-stringify.js +32 -32
- package/vendor/gulp-twig/LICENSE +20 -20
- package/vendor/gulp-twig/README.md +167 -167
- package/vendor/gulp-twig/index.js +138 -138
- package/vendor/gulp-twig/package.json +44 -44
|
@@ -1,167 +1,167 @@
|
|
|
1
|
-
[](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
|
-
|
|
1
|
+
[](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
|
+
|
|
@@ -1,138 +1,138 @@
|
|
|
1
|
-
// 2024-02-13, Kaspars Zuks: added "options.async" support
|
|
2
|
-
import map from 'map-stream';
|
|
3
|
-
import rext from 'replace-ext';
|
|
4
|
-
import log from 'fancy-log';
|
|
5
|
-
import PluginError from 'plugin-error';
|
|
6
|
-
import Twig from 'twig';
|
|
7
|
-
|
|
8
|
-
const PLUGIN_NAME = 'gulp-twig';
|
|
9
|
-
|
|
10
|
-
export default function (options) {
|
|
11
|
-
'use strict';
|
|
12
|
-
options = Object.assign(
|
|
13
|
-
{},
|
|
14
|
-
{
|
|
15
|
-
changeExt: true,
|
|
16
|
-
extname: '.html',
|
|
17
|
-
useFileContents: false,
|
|
18
|
-
async: true,
|
|
19
|
-
},
|
|
20
|
-
options || {},
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
function modifyContents(file, cb) {
|
|
24
|
-
var data = file.data || Object.assign({}, options.data);
|
|
25
|
-
|
|
26
|
-
if (file.isNull()) {
|
|
27
|
-
return cb(null, file);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (file.isStream()) {
|
|
31
|
-
return cb(new PluginError(PLUGIN_NAME, 'Streaming not supported!'));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
data._file = file;
|
|
35
|
-
if (options.changeExt === false || options.extname === true) {
|
|
36
|
-
data._target = {
|
|
37
|
-
path: file.path,
|
|
38
|
-
relative: file.relative,
|
|
39
|
-
};
|
|
40
|
-
} else {
|
|
41
|
-
data._target = {
|
|
42
|
-
path: rext(file.path, options.extname || ''),
|
|
43
|
-
relative: rext(file.relative, options.extname || ''),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
var twig = Twig.twig,
|
|
48
|
-
twigOpts = {
|
|
49
|
-
path: file.path,
|
|
50
|
-
async: false,
|
|
51
|
-
},
|
|
52
|
-
template;
|
|
53
|
-
|
|
54
|
-
if (options.debug !== undefined) {
|
|
55
|
-
twigOpts.debug = options.debug;
|
|
56
|
-
}
|
|
57
|
-
if (options.trace !== undefined) {
|
|
58
|
-
twigOpts.trace = options.trace;
|
|
59
|
-
}
|
|
60
|
-
if (options.base !== undefined) {
|
|
61
|
-
twigOpts.base = options.base;
|
|
62
|
-
}
|
|
63
|
-
if (options.namespaces !== undefined) {
|
|
64
|
-
twigOpts.namespaces = options.namespaces;
|
|
65
|
-
}
|
|
66
|
-
if (options.rethrow !== undefined) {
|
|
67
|
-
twigOpts.rethrow = options.rethrow;
|
|
68
|
-
}
|
|
69
|
-
if (options.cache !== true) {
|
|
70
|
-
Twig.cache(false);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (options.functions) {
|
|
74
|
-
options.functions.forEach(function (func) {
|
|
75
|
-
Twig.extendFunction(func.name, func.func);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (options.filters) {
|
|
80
|
-
options.filters.forEach(function (filter) {
|
|
81
|
-
Twig.extendFilter(filter.name, filter.func);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (options.extend) {
|
|
86
|
-
Twig.extend(options.extend);
|
|
87
|
-
delete options.extend;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (options.useFileContents) {
|
|
91
|
-
var fileContents = file.contents.toString();
|
|
92
|
-
twigOpts.data = fileContents;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
template = twig(twigOpts);
|
|
96
|
-
|
|
97
|
-
if (options.async) {
|
|
98
|
-
template
|
|
99
|
-
.renderAsync(data)
|
|
100
|
-
.then(function (output) {
|
|
101
|
-
file.contents = new Buffer(output);
|
|
102
|
-
file.path = data._target.path;
|
|
103
|
-
cb(null, file);
|
|
104
|
-
})
|
|
105
|
-
.catch(function (e) {
|
|
106
|
-
if (options.errorLogToConsole) {
|
|
107
|
-
log(PLUGIN_NAME + ' ' + e);
|
|
108
|
-
cb();
|
|
109
|
-
} else if (typeof options.onError === 'function') {
|
|
110
|
-
options.onError(e);
|
|
111
|
-
cb();
|
|
112
|
-
} else {
|
|
113
|
-
cb(new PluginError(PLUGIN_NAME, e));
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
} else {
|
|
117
|
-
try {
|
|
118
|
-
file.contents = new Buffer(template.render(data));
|
|
119
|
-
} catch (e) {
|
|
120
|
-
if (options.errorLogToConsole) {
|
|
121
|
-
log(PLUGIN_NAME + ' ' + e);
|
|
122
|
-
return cb();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (typeof options.onError === 'function') {
|
|
126
|
-
options.onError(e);
|
|
127
|
-
return cb();
|
|
128
|
-
}
|
|
129
|
-
return cb(new PluginError(PLUGIN_NAME, e));
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
file.path = data._target.path;
|
|
133
|
-
cb(null, file);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return map(modifyContents);
|
|
138
|
-
}
|
|
1
|
+
// 2024-02-13, Kaspars Zuks: added "options.async" support
|
|
2
|
+
import map from 'map-stream';
|
|
3
|
+
import rext from 'replace-ext';
|
|
4
|
+
import log from 'fancy-log';
|
|
5
|
+
import PluginError from 'plugin-error';
|
|
6
|
+
import Twig from 'twig';
|
|
7
|
+
|
|
8
|
+
const PLUGIN_NAME = 'gulp-twig';
|
|
9
|
+
|
|
10
|
+
export default function (options) {
|
|
11
|
+
'use strict';
|
|
12
|
+
options = Object.assign(
|
|
13
|
+
{},
|
|
14
|
+
{
|
|
15
|
+
changeExt: true,
|
|
16
|
+
extname: '.html',
|
|
17
|
+
useFileContents: false,
|
|
18
|
+
async: true,
|
|
19
|
+
},
|
|
20
|
+
options || {},
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
function modifyContents(file, cb) {
|
|
24
|
+
var data = file.data || Object.assign({}, options.data);
|
|
25
|
+
|
|
26
|
+
if (file.isNull()) {
|
|
27
|
+
return cb(null, file);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (file.isStream()) {
|
|
31
|
+
return cb(new PluginError(PLUGIN_NAME, 'Streaming not supported!'));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
data._file = file;
|
|
35
|
+
if (options.changeExt === false || options.extname === true) {
|
|
36
|
+
data._target = {
|
|
37
|
+
path: file.path,
|
|
38
|
+
relative: file.relative,
|
|
39
|
+
};
|
|
40
|
+
} else {
|
|
41
|
+
data._target = {
|
|
42
|
+
path: rext(file.path, options.extname || ''),
|
|
43
|
+
relative: rext(file.relative, options.extname || ''),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var twig = Twig.twig,
|
|
48
|
+
twigOpts = {
|
|
49
|
+
path: file.path,
|
|
50
|
+
async: false,
|
|
51
|
+
},
|
|
52
|
+
template;
|
|
53
|
+
|
|
54
|
+
if (options.debug !== undefined) {
|
|
55
|
+
twigOpts.debug = options.debug;
|
|
56
|
+
}
|
|
57
|
+
if (options.trace !== undefined) {
|
|
58
|
+
twigOpts.trace = options.trace;
|
|
59
|
+
}
|
|
60
|
+
if (options.base !== undefined) {
|
|
61
|
+
twigOpts.base = options.base;
|
|
62
|
+
}
|
|
63
|
+
if (options.namespaces !== undefined) {
|
|
64
|
+
twigOpts.namespaces = options.namespaces;
|
|
65
|
+
}
|
|
66
|
+
if (options.rethrow !== undefined) {
|
|
67
|
+
twigOpts.rethrow = options.rethrow;
|
|
68
|
+
}
|
|
69
|
+
if (options.cache !== true) {
|
|
70
|
+
Twig.cache(false);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (options.functions) {
|
|
74
|
+
options.functions.forEach(function (func) {
|
|
75
|
+
Twig.extendFunction(func.name, func.func);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (options.filters) {
|
|
80
|
+
options.filters.forEach(function (filter) {
|
|
81
|
+
Twig.extendFilter(filter.name, filter.func);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (options.extend) {
|
|
86
|
+
Twig.extend(options.extend);
|
|
87
|
+
delete options.extend;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (options.useFileContents) {
|
|
91
|
+
var fileContents = file.contents.toString();
|
|
92
|
+
twigOpts.data = fileContents;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
template = twig(twigOpts);
|
|
96
|
+
|
|
97
|
+
if (options.async) {
|
|
98
|
+
template
|
|
99
|
+
.renderAsync(data)
|
|
100
|
+
.then(function (output) {
|
|
101
|
+
file.contents = new Buffer(output);
|
|
102
|
+
file.path = data._target.path;
|
|
103
|
+
cb(null, file);
|
|
104
|
+
})
|
|
105
|
+
.catch(function (e) {
|
|
106
|
+
if (options.errorLogToConsole) {
|
|
107
|
+
log(PLUGIN_NAME + ' ' + e);
|
|
108
|
+
cb();
|
|
109
|
+
} else if (typeof options.onError === 'function') {
|
|
110
|
+
options.onError(e);
|
|
111
|
+
cb();
|
|
112
|
+
} else {
|
|
113
|
+
cb(new PluginError(PLUGIN_NAME, e));
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
} else {
|
|
117
|
+
try {
|
|
118
|
+
file.contents = new Buffer(template.render(data));
|
|
119
|
+
} catch (e) {
|
|
120
|
+
if (options.errorLogToConsole) {
|
|
121
|
+
log(PLUGIN_NAME + ' ' + e);
|
|
122
|
+
return cb();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (typeof options.onError === 'function') {
|
|
126
|
+
options.onError(e);
|
|
127
|
+
return cb();
|
|
128
|
+
}
|
|
129
|
+
return cb(new PluginError(PLUGIN_NAME, e));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
file.path = data._target.path;
|
|
133
|
+
cb(null, file);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return map(modifyContents);
|
|
138
|
+
}
|