Skip to content

Commit

Permalink
chore: Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
phated authored and actions-user committed Jun 9, 2021
1 parent 004417e commit 53a8769
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 122 deletions.
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,37 @@ 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`.

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

Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 3 additions & 7 deletions test/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
10 changes: 3 additions & 7 deletions test/extends.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
});
});
15 changes: 7 additions & 8 deletions test/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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
);
});
});
10 changes: 3 additions & 7 deletions test/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
169 changes: 94 additions & 75 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});
});

0 comments on commit 53a8769

Please sign in to comment.