gulp-assign-to-jade
v2.0.0
Published
Assign file contents to the Jade template as a local variable
Downloads
7
Maintainers
Readme
gulp-assign-to-jade
gulp plugin to assign file contents to the Jade template as a local variable
const gulp = require('gulp');
const assignToJade = require('gulp-assign-to-jade');
gulp.task('default', () => {
return gulp.src('contents.txt') // contents.txt : 'Hello'
.pipe(assignToJade('layout.jade')) // layout.jade : 'div= contents'
.pipe(gulp.dest('dest')) // dest/contents.html: '<div>Hello</div>'
});
Installation
npm install --save-dev gulp-assign-to-jade
API
const assignToJade = require('gulp-assign-to-jade');
assignToJade(templatePath [, options])
templatePath: String
(path to a .jade
file)
options: Object
(directly passed to gulp-jade options)
Return: Object
(stream.Transform)
It compiles the Jade template with passing the string of source file contents to the compiler as contents
variable. data
property of the contents are also used.
options.varName
Type: String
Default: contents
Sets the variable name to which the file contents will be assigned.
const path = require('path');
const gulp = require('gulp');
const assignToJade = require('gulp-assign-to-jade');
const data = require('gulp-data');
function setTitle(file) {
return: {title: path.basename(file.path)};
}
gulp.task('default', () => {
return gulp.src('src.txt') // src.txt : 'Hi'
.pipe(data(setTitle))
.pipe(assignToJade('layout.jade', { // template.jade: 'h1= title\np= body'
varName: 'body'
}))
.pipe(gulp.dest('dest')) // dest/src.html: '<h1>src</h1><p>Hi</p>'
});
License
Copyright (c) 2015 Shinnosuke Watanabe
Licensed under the MIT License.