UNPKG

3.1 kBMarkdownView Raw
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
24Build 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```
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
77// gulpfile.js
78var gulp = require('gulp');
79
80gulp.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
97gulp.task('default', ['compile']);
98```
99
100## LICENSE
101
102(MIT License)
103
104Copyright (c) 2014 Simon de Turck <simon@zimmen.com> www.zimmen.com
105
106Permission is hereby granted, free of charge, to any person obtaining
107a copy of this software and associated documentation files (the
108"Software"), to deal in the Software without restriction, including
109without limitation the rights to use, copy, modify, merge, publish,
110distribute, sublicense, and/or sell copies of the Software, and to
111permit persons to whom the Software is furnished to do so, subject to
112the following conditions:
113
114The above copyright notice and this permission notice shall be
115included in all copies or substantial portions of the Software.
116
117THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
118EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
119MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
120NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
121LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
122OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
123WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
124