diff --git a/README.md b/README.md index b1bac69..6050f13 100644 --- a/README.md +++ b/README.md @@ -18,23 +18,25 @@ const pug = require('gulp-pug'); exports.views = () => { return src('./src/*.pug') - .pipe(pug({ - // Your options in here. - })) - .pipe(dest('./dist')) -} + .pipe( + pug({ + // Your options in here. + }) + ) + .pipe(dest('./dist')); +}; ``` ## API ### `pug([opts])` - - `opts` (`Object`): Any options from [Pug's API][api] in addition to `pug`'s own options. - - `opts.locals` (`Object`): Locals to compile the Pug with. You can also provide locals through the `data` field of the file object, e.g. with [`gulp-data`][gulp-data]. They will be merged with `opts.locals`. - - `opts.data` (`Object`): Same as `opts.locals`. - - `opts.client` (`Boolean`): Compile Pug to JavaScript code. - - `opts.pug`: A custom instance of Pug for `gulp-pug` to use. - - `opts.verbose`: display name of file from stream that is being compiled. +- `opts` (`Object`): Any options from [Pug's API][api] in addition to `pug`'s own options. +- `opts.locals` (`Object`): Locals to compile the Pug with. You can also provide locals through the `data` field of the file object, e.g. with [`gulp-data`][gulp-data]. They will be merged with `opts.locals`. +- `opts.data` (`Object`): Same as `opts.locals`. +- `opts.client` (`Boolean`): Compile Pug to JavaScript code. +- `opts.pug`: A custom instance of Pug for `gulp-pug` to use. +- `opts.verbose`: display name of file from stream that is being compiled. To change `opts.filename` use [`gulp-rename`][gulp-rename] before `gulp-pug`. @@ -42,11 +44,11 @@ Returns a stream that compiles Vinyl files as Pug. ## Also See - - [`pug`][pug] - - [`gulp-data`][gulp-data]: Using locals in your Pug templates easier. - - [`gulp-rename`][gulp-rename]: Change `opts.filename` passed into Pug. - - [`gulp-wrap-amd`][gulp-wrap-amd]: Wrap your Pug in an AMD wrapper. - - [`gulp-frontmatter-wrangler`][gulp-frontmatter-wrangler]: Useful if you need YAML frontmatter at the top of your Pug file. +- [`pug`][pug] +- [`gulp-data`][gulp-data]: Using locals in your Pug templates easier. +- [`gulp-rename`][gulp-rename]: Change `opts.filename` passed into Pug. +- [`gulp-wrap-amd`][gulp-wrap-amd]: Wrap your Pug in an AMD wrapper. +- [`gulp-frontmatter-wrangler`][gulp-frontmatter-wrangler]: Useful if you need YAML frontmatter at the top of your Pug file. ## License diff --git a/index.d.ts b/index.d.ts index 17c93c1..3527a5e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,5 @@ -import { Transform } from "stream"; -import { Options as PugOptions } from "pug"; +import { Transform } from 'stream'; +import { Options as PugOptions } from 'pug'; /** * Returns a stream that compiles Vinyl files as Pug. diff --git a/test/error.js b/test/error.js index e63f24e..e0097f1 100644 --- a/test/error.js +++ b/test/error.js @@ -6,13 +6,9 @@ const PluginError = require('plugin-error'); const task = require('../'); const { getFixture } = require('./get-fixture'); -describe('error', function() { - it('should emit errors of pug correctly', function(done) { - pipe([ - from.obj([getFixture('pug-error.pug')]), - task(), - concat(), - ], (err) => { +describe('error', function () { + it('should emit errors of pug correctly', function (done) { + pipe([from.obj([getFixture('pug-error.pug')]), task(), concat()], (err) => { expect(err).toBeInstanceOf(PluginError); done(); }); diff --git a/test/extends.js b/test/extends.js index 91d0201..78118f8 100644 --- a/test/extends.js +++ b/test/extends.js @@ -5,8 +5,8 @@ const { concat, from, pipe } = require('mississippi'); const task = require('../'); const { getFixture } = require('./get-fixture'); -describe('extends', function() { - it('should compile a pug template with an extends', function(done) { +describe('extends', function () { + it('should compile a pug template with an extends', function (done) { function assert(files) { expect(files.length).toEqual(1); const newFile = files[0]; @@ -15,10 +15,6 @@ describe('extends', function() { }); } - pipe([ - from.obj([getFixture('extends.pug')]), - task(), - concat(assert), - ], done); + pipe([from.obj([getFixture('extends.pug')]), task(), concat(assert)], done); }); }); diff --git a/test/filters.js b/test/filters.js index 0702957..bc50f5e 100644 --- a/test/filters.js +++ b/test/filters.js @@ -7,14 +7,14 @@ const { getFixture } = require('./get-fixture'); const options = { filters: { - shout: function(str) { + shout: function (str) { return str.toUpperCase() + '!!!!'; }, }, }; -describe('filters', function() { - it('should compile a pug template with a custom pug instance with filters', function(done) { +describe('filters', function () { + it('should compile a pug template with a custom pug instance with filters', function (done) { function assert(files) { expect(files.length).toEqual(1); const newFile = files[0]; @@ -23,10 +23,9 @@ describe('filters', function() { }); } - pipe([ - from.obj([getFixture('filters.pug')]), - task(options), - concat(assert), - ], done); + pipe( + [from.obj([getFixture('filters.pug')]), task(options), concat(assert)], + done + ); }); }); diff --git a/test/stream.js b/test/stream.js index e1c36ba..e65aba0 100644 --- a/test/stream.js +++ b/test/stream.js @@ -19,13 +19,9 @@ const file = new Vinyl({ contents: fs.createReadStream(filePath), }); -describe('stream', function() { - it('should error if contents is a stream', function(done) { - pipe([ - from.obj([file]), - task(), - concat(), - ], (err) => { +describe('stream', function () { + it('should error if contents is a stream', function (done) { + pipe([from.obj([file]), task(), concat()], (err) => { expect(err).toBeInstanceOf(PluginError); done(); }); diff --git a/test/test.js b/test/test.js index 4cdeb80..e5b9f66 100644 --- a/test/test.js +++ b/test/test.js @@ -43,124 +43,143 @@ function assertStream(options) { return concat((files) => files.forEach(assert)); } -describe('test', function() { - it('should compile my pug files into HTML', function(done) { - pipe([ - from.obj([getFixture('helloworld.pug')]), - task(), - assertStream(), - ], done); +describe('test', function () { + it('should compile my pug files into HTML', function (done) { + pipe( + [from.obj([getFixture('helloworld.pug')]), task(), assertStream()], + done + ); }); - it('should compile my pug files into HTML with locals', function(done) { + it('should compile my pug files into HTML with locals', function (done) { const options = { locals: { title: 'Yellow Curled', }, }; - pipe([ - from.obj([getFixture('helloworld.pug')]), - task(options), - assertStream(options), - ], done); + pipe( + [ + from.obj([getFixture('helloworld.pug')]), + task(options), + assertStream(options), + ], + done + ); }); - it('should compile my pug files into HTML with data', function(done) { + it('should compile my pug files into HTML with data', function (done) { const options = { data: { title: 'Yellow Curled', }, }; - pipe([ - from.obj([getFixture('helloworld.pug')]), - task(options), - assertStream(options), - ], done); + pipe( + [ + from.obj([getFixture('helloworld.pug')]), + task(options), + assertStream(options), + ], + done + ); }); - it('should compile my pug files into HTML with data property', function(done) { - pipe([ - from.obj([getFixture('helloworld.pug')]), - setData(), - task(), - assertStream({ data: { title: 'Greetings' } }), - ], done); + it('should compile my pug files into HTML with data property', function (done) { + pipe( + [ + from.obj([getFixture('helloworld.pug')]), + setData(), + task(), + assertStream({ data: { title: 'Greetings' } }), + ], + done + ); }); - it('should compile my pug files into HTML with data from options and data property', function(done) { - pipe([ - from.obj([getFixture('helloworld.pug')]), - setData(), - task({ data: { foo: 'bar' } }), - assertStream({ data: { title: 'Greetings', foo: 'bar' } }), - ], done); + it('should compile my pug files into HTML with data from options and data property', function (done) { + pipe( + [ + from.obj([getFixture('helloworld.pug')]), + setData(), + task({ data: { foo: 'bar' } }), + assertStream({ data: { title: 'Greetings', foo: 'bar' } }), + ], + done + ); }); - it('should overwrite data option fields with data property fields when compiling my pug files to HTML', function(done) { - pipe([ - from.obj([getFixture('helloworld.pug')]), - setData(), - task({ data: { title: 'Yellow Curled' } }), - assertStream({ data: { title: 'Greetings' } }), - ], done); + it('should overwrite data option fields with data property fields when compiling my pug files to HTML', function (done) { + pipe( + [ + from.obj([getFixture('helloworld.pug')]), + setData(), + task({ data: { title: 'Yellow Curled' } }), + assertStream({ data: { title: 'Greetings' } }), + ], + done + ); }); - it('should not extend data property fields of other files', function(done) { - pipe([ - from.obj([ - getFixture('helloworld.pug'), - getFixture('helloworld2.pug'), - ]), - through.obj((file, _enc, cb) => { - if (path.basename(file.path) === 'helloworld.pug') { - file.data = { - title: 'Greetings!', - }; - } - cb(null, file); - }), - task(), - assertStream(), - ], done); + it('should not extend data property fields of other files', function (done) { + pipe( + [ + from.obj([getFixture('helloworld.pug'), getFixture('helloworld2.pug')]), + through.obj((file, _enc, cb) => { + if (path.basename(file.path) === 'helloworld.pug') { + file.data = { + title: 'Greetings!', + }; + } + cb(null, file); + }), + task(), + assertStream(), + ], + done + ); }); - it('should compile my pug files into JS', function(done) { + it('should compile my pug files into JS', function (done) { const options = { client: true }; - pipe([ - from.obj([getFixture('helloworld.pug')]), - task(options), - assertStream(options), - ], done); + pipe( + [ + from.obj([getFixture('helloworld.pug')]), + task(options), + assertStream(options), + ], + done + ); }); - it('should always return contents as buf with client = true', function(done) { + it('should always return contents as buf with client = true', function (done) { function assert(files) { expect(files.length).toEqual(1); const newFile = files[0]; expect(newFile.contents).toBeInstanceOf(Buffer); } - pipe([ - from.obj([getFixture('helloworld.pug')]), - task({ client: true }), - concat(assert), - ], done); + pipe( + [ + from.obj([getFixture('helloworld.pug')]), + task({ client: true }), + concat(assert), + ], + done + ); }); - it('should always return contents as buf with client = false', function(done) { + it('should always return contents as buf with client = false', function (done) { function assert(files) { expect(files.length).toEqual(1); const newFile = files[0]; expect(newFile.contents).toBeInstanceOf(Buffer); } - pipe([ - from.obj([getFixture('helloworld.pug')]), - task(), - concat(assert), - ], done); + pipe( + [from.obj([getFixture('helloworld.pug')]), task(), concat(assert)], + done + ); }); });