Skip to content

Commit

Permalink
add standalone processing functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
codekirei committed Mar 17, 2016
1 parent 18f7c10 commit 39c21d9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ const plugins = new Map([

const kireiCss = postcss.plugin('kirei-css', (custom = {}) => {
const instance = postcss()

plugins.forEach((opts, plugin) => instance.use(require(plugin)(
custom[plugin] ? merge(opts, custom[plugin]) : opts
)))

return instance
})

kireiCss.process = (css, opts) => postcss([kireiCss(opts)]).process(css)

export default kireiCss
20 changes: 20 additions & 0 deletions test/as-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// utils ---------------------------------------------------

import assert from 'assert'
import postcss from 'postcss'
import kireiCss from '../src'

// tests ---------------------------------------------------

const processor = postcss([kireiCss])

const expected =
`body {
background: red;
}`

exports['as-plugin'] = function* customOpts() {
const raw = postcss.parse('body{background:red;}')
const actual = yield processor.process(raw)
assert.equal(actual.css, expected)
}
5 changes: 1 addition & 4 deletions test/custom-opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import path from 'path'
import assert from 'assert'
import fs from 'mz/fs'
import postcss from 'postcss'
import kireiCss from '../src'

// tests ---------------------------------------------------
Expand All @@ -16,14 +15,12 @@ const opts = {
},
}

const processor = postcss([kireiCss(opts)])

const read = file =>
fs.readFile(path.resolve('test', 'fixtures', 'custom-opts', `${file}.css`), 'utf8')

exports['custom-opts'] = function* customOpts() {
const raw = yield read('in')
const expected = yield read('out')
const actual = yield processor.process(raw)
const actual = yield kireiCss.process(raw, opts)
assert.equal(actual.css, expected)
}
5 changes: 1 addition & 4 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
import path from 'path'
import assert from 'assert'
import fs from 'mz/fs'
import postcss from 'postcss'
import kireiCss from '../src'

// tests ---------------------------------------------------

const processor = postcss([kireiCss])

const read = (dir, file) =>
fs.readFile(path.resolve('test', 'cases', dir, `${file}.css`), 'utf8')

Expand All @@ -18,7 +15,7 @@ fs.readdirSync(path.resolve('test', 'cases'))
exports[test] = function* testGenerator() {
const raw = yield read(test, 'in')
const expected = yield read(test, 'out')
const actual = yield processor.process(raw)
const actual = yield kireiCss.process(raw)
assert.equal(actual.css, expected)
}
})
3 changes: 1 addition & 2 deletions todo.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
- obviate postcss if not using other plugins (webpack compat?)
- linting
- ci
- readme
- changelog
- npm
- check webpack compatibility

0 comments on commit 39c21d9

Please sign in to comment.