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

Commit

Permalink
Add lineBreak option
Browse files Browse the repository at this point in the history
  • Loading branch information
Ҽ˿ committed Dec 6, 2014
1 parent de408ab commit 4813a5b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# 1.0.0 - 2014-12-04
# 1.0.0 - 2014-12-06

First release
First release
26 changes: 25 additions & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,31 @@ gulp.watch('src/*.css', ['default']);

### 选项

**`extensions`** (default: `{}`)
#### 1. **`lineBreak`**(default: `true`)

设置多个选择器是否换行,默认开启换行。

关闭换行:

```js
var options = {
lineBreak: false
}

var output = postcss(selector(options))
.process(css)
.css
```

「示例1」中的 `input.css` 将输出为:

```css
article h1 + p, article h2 + p, article h3 + p, article h4 + p, article h5 + p, article h6 + p {
margin-top: 0;
}
```

#### 2. **`extensions`** (default: `{}`)

该选项允许你自定义一个对象来设置 `<extension-name>`(选择器别名)和 `<selector>`,这些定义将覆盖 CSS 中相同别名的 `@custom-selector`

Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,31 @@ gulp.watch('src/*.css', ['default']);

### Options

**`extensions`** (default: `{}`)
#### 1. **`lineBreak`**(default: `true`)

Setting multiple selector whether wrap.

Close the line breaks.

```js
var options = {
lineBreak: false
}

var output = postcss(selector(options))
.process(css)
.css
```

In the 'Example 1' `input.css` will output:

```css
article h1 + p, article h2 + p, article h3 + p, article h4 + p, article h5 + p, article h6 + p {
margin-top: 0;
}
```

#### 2. **`extensions`** (default: `{}`)

This option allows you to customize an object to set the `<extension-name>` (selector alias) and `<selector>`, these definitions will cover the same alias of `@custom-selector` in CSS.

Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function customSelector(options) {
return function(styles) {
options = options || {}
var extensions = options.extensions || {}
var line_break = '\n'
var map = {}
var toRemove = []
var customSelectors = {}
Expand Down Expand Up @@ -47,6 +48,11 @@ function customSelector(options) {
customSelectors[extension] = extensions[extension]
})

//控制选择器是否换行
if (!options.lineBreak && options.lineBreak == false) {
line_break = ' '
}

// 转换自定义的选择器别名
styles.eachRule(function(rule) {
for (var prop in customSelectors) {
Expand All @@ -58,7 +64,7 @@ function customSelector(options) {
if ($2 == prop) {
return customSelector.split(",").map(function(selector) {
return $1 + selector.trim() + $3
}).join(", ")
}).join("," + line_break)
}
})

Expand Down

0 comments on commit 4813a5b

Please sign in to comment.