Skip to content

Commit 9686ec0

Browse files
committed
Initial commit
0 parents  commit 9686ec0

9 files changed

+148
-0
lines changed

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
npm-debug.log

.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.gitignore
2+
node_modules/
3+
test.js
4+
.travis.yml

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- iojs
5+
- "0.12"
6+
- "0.10"

LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright 2015 Mark Dalgleish <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[![Build Status][ci-img]][ci]
2+
3+
# PostCSS Local Scope
4+
5+
*WARNING: This plugin is still a work in progress and not yet ready for production.*
6+
7+
[PostCSS] plugin to transform global selectors into the [local scope] format of [Webpack]'s [css-loader].
8+
9+
[PostCSS]: https://github.com/postcss/postcss
10+
[ci-img]: https://img.shields.io/travis/markdalgleish/postcss-local-scope/master.svg?style=flat-square
11+
[ci]: https://travis-ci.org/markdalgleish/postcss-local-scope
12+
[Webpack]: http://webpack.github.io
13+
[css-loader]: https://github.com/webpack/css-loader
14+
[local scope]: https://github.com/webpack/css-loader#local-scope
15+
16+
```css
17+
.foo { /* ... */ }
18+
```
19+
20+
```css
21+
.local[foo] { /* ... */ }
22+
```
23+
24+
## Usage
25+
26+
```js
27+
postcss([ require('postcss-local-scope') ])
28+
```
29+
30+
See [PostCSS] docs for examples for your environment.

index.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var postcss = require('postcss');
2+
3+
module.exports = postcss.plugin('postcss-local-scope', function () {
4+
return function(css) {
5+
css.eachRule(function(rule) {
6+
// source: http://stackoverflow.com/questions/448981/what-characters-are-valid-in-css-class-names-selectors
7+
rule.selector = rule.selector.replace(/.(-?[_a-zA-Z]+[_a-zA-Z0-9-]*)/g, '.local[$1]');
8+
});
9+
};
10+
});

package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "postcss-local-scope",
3+
"version": "0.0.0",
4+
"description": "PostCSS plugin to transform global selectors into the local scope format of Webpack's css-loader",
5+
"keywords": [
6+
"postcss",
7+
"css",
8+
"postcss-plugin",
9+
"webpack",
10+
"css-loader"
11+
],
12+
"author": "Mark Dalgleish",
13+
"license": "MIT",
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/markdalgleish/postcss-local-scope.git"
17+
},
18+
"dependencies": {
19+
"postcss": "^4.1.5"
20+
},
21+
"devDependencies": {
22+
"tape": "^4.0.0"
23+
},
24+
"scripts": {
25+
"test": "tape test.js"
26+
}
27+
}

test.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var test = require('tape');
2+
var postcss = require('postcss');
3+
var plugin = require('./');
4+
var name = require('./package.json').name;
5+
6+
var tests = [
7+
{
8+
should: 'scope selectors',
9+
input: '.foobar {}',
10+
expected: '.local[foobar] {}'
11+
},
12+
{
13+
should: 'scope multiple selectors',
14+
input: '.foo, .baz {}',
15+
expected: '.local[foo], .local[baz] {}'
16+
}
17+
];
18+
19+
function process (css, options) {
20+
return postcss(plugin(options)).process(css).css;
21+
}
22+
23+
test(name, function (t) {
24+
t.plan(tests.length);
25+
26+
tests.forEach(function (test) {
27+
var options = test.options || {};
28+
t.equal(process(test.input, options), test.expected, 'should ' + test.should);
29+
});
30+
});
31+
32+
test('should use the postcss plugin api', function (t) {
33+
t.plan(2);
34+
t.ok(plugin().postcssVersion, 'should be able to access version');
35+
t.equal(plugin().postcssPlugin, name, 'should be able to access name');
36+
});

0 commit comments

Comments
 (0)