Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

gulp-hogan

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-hogan - npm Package Compare versions

Comparing version
1.2.1
to
2.0.0
+40
-4
index.js
'use strict';
var map = require('map-stream');
var es = require('event-stream');;
var es = require('event-stream');
var gutil = require('gulp-util');
var Hogan = require('hogan.js');
var path = require('path');
var fs = require('fs');

@@ -11,6 +12,41 @@ module.exports = function(data, options, extension) {

return es.map(function (file, cb) {
file.contents = new Buffer( Hogan.compile(file.contents.toString(), options).render(data) );
var compiled = Hogan.compile(file.contents.toString(), options);
var partialTemplates = getPartials(compiled, path.dirname(file.path), path.extname(file.path), data, options);
file.contents = new Buffer( compiled.render(data, partialTemplates) );
file.path = gutil.replaceExtension(file.path, extension);
cb(null,file);
});
};
};
function getPartials(compiled, dir, ext, data, options) {
var currentPartials = {},
partialTemplates = {},
partialPath = '',
compiledPartial;
Object.keys(compiled.partials).forEach(function (tag) {
// find the path of the partial
partialPath = path.format({
'dir': dir,
'base': compiled.partials[tag].name + ext
});
// read and compile the files contents
compiledPartial = Hogan.compile(fs.readFileSync(partialPath).toString(), options);
// if partials exist within the compiled tempalte, then
if (Object.keys(compiledPartial.partials).length !== 0) {
currentPartials = getPartials(compiledPartial, dir, ext, data, options);
}
// Assign the contents of the partial to a key of the same name
partialTemplates[compiled.partials[tag].name] = compiledPartial.render(data, currentPartials);
});
return partialTemplates;
}
+1
-2
{
"name": "gulp-hogan",
"version": "1.2.1",
"version": "2.0.0",
"description": "gulp plugin to compile mustache templates",

@@ -28,3 +28,2 @@ "main": "index.js",

"event-stream": "^3.1.7",
"map-stream": "^0.0.6",
"hogan.js": "^3.0.2"

@@ -31,0 +30,0 @@ },

@@ -31,2 +31,71 @@ # gulp-hogan [![Build status][travis-image]][travis-url]

## Template inheritance & Partials
Partials will be rendered recursively, allowing for template inheritance.
### Example:
Folder structure
```
|-- templates
|-- page.hogan
|-- body.hogan
|-- partials
| |-- header.hogan
| |-- footer.hogan
```
page.hogan
```html
<h1>Page</h1>
{{> body }}
```
body.hogan
```html
{{> partials/header }}
{{> partials/footer }}
```
header.hogan
```html
<header>
Logo {{#image}}<img>{{/image}}
</header>
```
footer.hogan
```html
<footer>
Copyright {{year}}
</footer>
```
gulpfile.js
```javascript
var hogan = require('gulp-hogan');
gulp.task('default', function(){
gulp.src('template/page.hogan', {}, '.html')
.pipe(hogan({year: '2016'}, null, '.html'))
.pipe(gulp.dest('dist'));
});
```
dist/page.html
```html
<h1>Page</h1>
<header>
Logo <img>
</header>
<footer>
Copyright 2016
</footer>
```
[travis-url]: http://travis-ci.org/hemanth/gulp-hogan

@@ -33,0 +102,0 @@ [travis-image]: https://travis-ci.org/hemanth/gulp-hogan.svg