0.2.1 • Published 6 years ago
gulp-assign-to-pug v0.2.1
gulp-assign-to-pug
gulp plugin to assign file contents to the Pug template as a local variable
const {task} = require('gulp');
const assignToPug = require('gulp-assign-to-pug');
task('default', () => {
return gulp.src('contents.txt') // contents.txt : 'Hello'
.pipe(assignToPug('layout.pug')) // layout.pug : 'div= contents'
.pipe(gulp.dest('dest')) // dest/contents.html: '<div>Hello</div>'
});
Installation
npm install --save-dev gulp-assign-to-pug
API
const assignToPug = require('gulp-assign-to-pug');
assignToPug(templatePath , options)
templatePath: string
(path to a .jade
file)
options: Object
(directly passed to gulp-pug options)
Return: 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 {basename} = require('path');
const gulp = require('gulp');
const assignToPug = require('gulp-assign-to-pug');
const data = require('gulp-data');
const setTitle = file => ({title: basename(file.path)});
gulp.task('default', () => {
return gulp.src('src.txt') // src.txt : 'Hi'
.pipe(data(setTitle))
.pipe(assignToPug('layout.pug', { // template.pug: 'h1= title\np= body'
varName: 'body'
}))
.pipe(gulp.dest('dest')); // dest/src.html: '<h1>src</h1><p>Hi</p>'
});
License
ISC License © 2018 Shinnosuke Watanabe