gulp-pngquant-openmp
v0.0.0
Published
Assign file contents to the Pug template as a local variable
Downloads
3
Maintainers
Readme
gulp-assign-to-pug
gulp plugin to assign file contents to the Pug template as a local variable
const gulp = require('gulp');
const assignToPug = require('gulp-assign-to-pug');
gulp.task('default', () => {
return gulp.src('contents.txt') // contents.txt : 'Hello'
.pipe(assignToPug('layout.jade')) // layout.jade : 'div= contents'
.pipe(gulp.dest('dest')) // dest/contents.html: '<div>Hello</div>'
});
Installation
npm install --save-dev gulp-assign-to-pug
API
const assignToJade = require('gulp-assign-to-pug');
assignToPug(templatePath [, options])
templatePath: String
(path to a .jade
file)
options: Object
(directly passed to gulp-jade options)
Return: Object
(stream.Transform)
It compiles the Pug 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 assignToPug = require('gulp-assign-to-pug');
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(assignToPug('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 - 2016 Shinnosuke Watanabe
Licensed under the MIT License.