UNPKG

4.49 kBMarkdownView Raw
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>>= 0.10</td>
14</tr>
15<tr>
16<td>Gulp Version</td>
17<td>3.x</td>
18</tr>
19</table>
20
21
22Compile [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. Currently i'm looking into [atpl.js](https://github.com/soywiz/atpl.js) as well.
23
24You can use this plugin with [gulp-data](https://www.npmjs.com/package/gulp-data).
25
26## Usage
27
28### Install
29
30```bash
31npm 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
77var gulp = require('gulp');
78
79gulp.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
96gulp.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**functions**: [array] *extends Twig with given function objects. (default to undefined)*
117```javascript
118[
119 {
120 name: "nameOfFunction",
121 func: function (args) {
122 return "the function";
123 }
124 }
125]
126```
127
128**filters**: [array] *extends Twig with given filter objects. (default to undefined)*
129```javascript
130[
131 {
132 name: "nameOfFilter",
133 func: function (args) {
134 return "the filter";
135 }
136 }
137]
138```
139### LICENSE
140
141(MIT License)
142
143Copyright (c) 2015 Simon de Turck <simon@zimmen.com> www.zimmen.com
144
145Permission is hereby granted, free of charge, to any person obtaining
146a copy of this software and associated documentation files (the
147"Software"), to deal in the Software without restriction, including
148without limitation the rights to use, copy, modify, merge, publish,
149distribute, sublicense, and/or sell copies of the Software, and to
150permit persons to whom the Software is furnished to do so, subject to
151the following conditions:
152
153The above copyright notice and this permission notice shall be
154included in all copies or substantial portions of the Software.
155
156THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
157EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
158MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
159NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
160LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
161OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
162WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
163