0.2.1 • Published 6 years ago

gulp-assign-to-pug v0.2.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

gulp-assign-to-pug

npm version Build Status Build status Coverage Status

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

Use npm.

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

0.3.0-6

6 years ago

0.3.0-5

6 years ago

0.3.0-4

6 years ago

0.3.0-3

6 years ago

0.3.0-2

6 years ago

0.3.0-1

6 years ago

0.3.0-0

6 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.0

8 years ago