Skip to content

Commit

Permalink
now accepts for its data
Browse files Browse the repository at this point in the history
  • Loading branch information
colynb committed Jun 17, 2014
1 parent ea456eb commit cf7d160
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ gulp.task('templates', function() {
});
```

### ** NEW **

Inject data into your templates via the new [gulp-data](https://npmjs.org/package/gulp-data) plugin. It creates a ```file.data``` property with the data you need. This new method makes it much easier and less restrictive for getting data, than the methods below it. I'd recommend using this new method.


```javascript
var getJsonData = function(file, cb) {
var jsonPath = './examples/' + path.basename(file.path) + '.json';
cb(require(jsonPath));
};

gulp.task('json-test', function() {
return gulp.src('./examples/test1.html')
.pipe(data(getJsonData))
.pipe(swig())
.pipe(gulp.dest('build'));
});
```

### ** PRE version 0.7.0 (but still works) **

Inject variables from data object into templates

```javascript
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ module.exports = function(options) {

var data = opts.data || {}, jsonPath;

if (file.data) {
data = extend(file.data, data);
}

if (typeof data === 'function') {
data = data(file);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-swig",
"version": "0.6.0",
"version": "0.7.0",
"description": "Swig Plugin for Gulp",
"keywords": [
"gulpplugin",
Expand Down

0 comments on commit cf7d160

Please sign in to comment.