1 | # gulp-twig
|
2 | [![Build Status](https://travis-ci.org/zimmen/gulp-twig.png?branch=master)](https://travis-ci.org/zimmen/gulp-twig)
|
3 |
|
4 | ###Compile [Twig.js](https://github.com/justjohn/twig.js) templates with Gulp
|
5 |
|
6 | <table>
|
7 | <tr>
|
8 | <td>Package</td><td>gulp-twig</td>
|
9 | </tr>
|
10 | <tr>
|
11 | <td>Description</td>
|
12 | <td>Twig plugin for gulp.js, The streaming build system</td>
|
13 | </tr>
|
14 | <tr>
|
15 | <td>Node Version</td>
|
16 | <td>>= 0.9</td>
|
17 | </tr>
|
18 | <tr>
|
19 | <td>Gulp Version</td>
|
20 | <td>3.x</td>
|
21 | </tr>
|
22 | </table>
|
23 |
|
24 | Build upon [Twig.js](https://github.com/justjohn/twig.js) , the JS port of the Twig templating language by John Roepke
|
25 |
|
26 | # Usage
|
27 |
|
28 | ## Install
|
29 |
|
30 | ```
|
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 | // gulpfile.js
|
78 | var gulp = require('gulp');
|
79 |
|
80 | gulp.task('compile', function () {
|
81 | 'use strict';
|
82 | var twig = require('gulp-twig');
|
83 | return gulp.src('./index.twig')
|
84 | .pipe(twig({
|
85 | data: {
|
86 | title: 'Gulp and Twig',
|
87 | benefits: [
|
88 | 'Fast',
|
89 | 'Flexible',
|
90 | 'Secure'
|
91 | ]
|
92 | }
|
93 | }))
|
94 | .pipe(gulp.dest('./'));
|
95 | });
|
96 |
|
97 | gulp.task('default', ['compile']);
|
98 | ```
|
99 |
|
100 | ## LICENSE
|
101 |
|
102 | (MIT License)
|
103 |
|
104 | Copyright (c) 2014 Simon de Turck <simon@zimmen.com> www.zimmen.com
|
105 |
|
106 | Permission is hereby granted, free of charge, to any person obtaining
|
107 | a copy of this software and associated documentation files (the
|
108 | "Software"), to deal in the Software without restriction, including
|
109 | without limitation the rights to use, copy, modify, merge, publish,
|
110 | distribute, sublicense, and/or sell copies of the Software, and to
|
111 | permit persons to whom the Software is furnished to do so, subject to
|
112 | the following conditions:
|
113 |
|
114 | The above copyright notice and this permission notice shall be
|
115 | included in all copies or substantial portions of the Software.
|
116 |
|
117 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
118 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
119 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
120 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
121 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
122 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
123 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
124 |
|