Skip to content
This repository has been archived by the owner on Jun 6, 2022. It is now read-only.

Commit

Permalink
Use PostCSS 4.1 plugin API
Browse files Browse the repository at this point in the history
  • Loading branch information
yisibl committed Jun 4, 2015
1 parent f6034c5 commit e020e32
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
28 changes: 15 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var postcss = require("postcss")
/**
* 匹配自定义选择器
* :--foo
Expand All @@ -8,20 +9,21 @@ var re_CUSTOM_SELECTOR = /([^,]*?)(:-{2,}[\w-]+)(.*)/g
/**
* 暴露插件
*/
module.exports = customSelector
module.exports = postcss.plugin("postcss-custom-selectors", function(options) {
/**
* 插件配置
*/
options = options || {}
var extensions = options.extensions || {}
var line_break = '\n'
var map = {}
var toRemove = []
var customSelectors = {}

/**
* 读取和替换自定义选择器
*/
function customSelector(options) {
/**
* 读取和替换自定义选择器
*/
return function(styles) {
options = options || {}
var extensions = options.extensions || {}
var line_break = '\n'
var map = {}
var toRemove = []
var customSelectors = {}

// 读取自定义选择器
styles.eachAtRule(function(rule) {
if (rule.name !== "custom-selector") {
Expand Down Expand Up @@ -80,4 +82,4 @@ function customSelector(options) {
})

}
}
})
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"postcss",
"postcss-plugins",
"selector",
"custom-selector"
"custom-selector",
"custom selector"
],
"author": "yisi",
"license": "MIT",
Expand All @@ -23,8 +24,8 @@
"index.js"
],
"devDependencies": {
"postcss": "^3.0.0",
"tape": "^3.0.0"
"postcss": "^4.1.11",
"tape": "^4.0.0"
},
"scripts": {
"test": "tape test"
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ function compareFixtures(t, name, msg, opts, postcssOpts) {
postcssOpts = postcssOpts || {}
//input
postcssOpts.from = filename("fixtures/" + name + "/input")
console.log('postcssOpts.from', postcssOpts.from)
opts = opts || {}
var actual = postcss()
.use(plugin(opts))
.process(read(postcssOpts.from), postcssOpts).css
.process(read(postcssOpts.from), postcssOpts)
.css
//output
var output = read(filename("fixtures/" + name + "/output"))
//actual
Expand Down

0 comments on commit e020e32

Please sign in to comment.