Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Fly 2 #1

Merged
merged 2 commits into from
Mar 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
sudo: false
language: node_js
node_js:
- 4
- 5
- 7
- 6
22 changes: 15 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
const path = require('path')
const pug = require('pug')
const { join } = require('path')
const { render } = require('pug')

module.exports = function flyPug () {
return this.filter('pug', function plugin (data, options) {
module.exports = function (fly) {
fly.plugin('pug', {}, function * (file, options) {
if (!options.filename) {
options.filename = path.resolve(path.join(options.file.dir, options.file.base))
options.filename = join(file.dir, file.base)
}
try {
const result = render(file.data.toString(), options)
file.data = Buffer(result)
file.base = file.base.replace(/\.pug$/, '.html')
} catch (error) {
fly.emit('plugin_error', {
plugin: 'fly-pug',
error: error.message
})
}
delete options.file
return { ext: '.html', code: pug.render(data.toString(), options) }
})
}
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"pug"
],
"scripts": {
"test": "node_modules/.bin/ava"
"test": "ava"
},
"author": {
"name": "frantic1048",
Expand All @@ -35,13 +35,10 @@
"eslint": "^3.0.1",
"eslint-config-standard": "^5.3.1",
"eslint-plugin-promise": "^1.3.2",
"eslint-plugin-standard": "^2.0.0"
},
"peerDependencies": {
"fly": "^1.3.1"
"eslint-plugin-standard": "^2.0.0",
"fly": "^2.0.3"
},
"engines": {
"iojs": ">= 1.0.0",
"node": ">= 0.12.0"
"node": ">= 6"
}
}
35 changes: 20 additions & 15 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import Fly from 'fly'
import { extname, join } from 'path'
import test from 'ava'
import { readFileSync } from 'fs'

import flyPug from '../'

const fly = {
filter (name, plugin) {
this[name] = plugin
}
}

flyPug.call(fly)

test('rendering', t => {
const data = readFileSync('assert.pug')
const options = { file: { base: 'assert.pug', dir: '' } }
t.deepEqual(fly.pug(data, options), {
ext: '.html',
code: '<!DOCTYPE html><html lang="en"></html><head><meta charset="UTF-8"/><title>Oh Pug</title></head><body><h1>Oh my body</h1></body>'
test('rendering', async t => {
const fly = new Fly({
plugins: [
flyPug
],
tasks: {
* test (self) {
yield self.source(join(__dirname, 'assert.pug'))
.pug()
.run({
* func (file) {
t.is(file.data.toString(), '<!DOCTYPE html><html lang="en"></html><head><meta charset="UTF-8"/><title>Oh Pug</title></head><body><h1>Oh my body</h1></body>')
t.is(extname(file.base), '.html')
}
})
}
}
})
await fly.start('test')
})