Assign file contents to the Pug template as a local variable
npm install gulp-pngquant-openmp





gulp plugin to assign file contents to the Pug template as a local variable
``javascript
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: '
Installation
`
npm install --save-dev gulp-assign-to-pug
`API
`javascript
const assignToJade = require('gulp-assign-to-pug');
`$3
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: contentsSets the variable name to which the file contents will be assigned.
`javascript
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: '
src
Hi
'
});
``Copyright (c) 2015 - 2016 Shinnosuke Watanabe
Licensed under the MIT License.