Skip to content

Commit

Permalink
Initial commit, prouf of concept
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksim Koretskiy committed Aug 25, 2015
0 parents commit fa9efc0
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
@@ -0,0 +1,3 @@
{
"stage": 0
}
13 changes: 13 additions & 0 deletions .editorconfig
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
3 changes: 3 additions & 0 deletions .eslintrc
@@ -0,0 +1,3 @@
{
"extends": "airbnb"
}
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules/
npm-debug.log
8 changes: 8 additions & 0 deletions .npmignore
@@ -0,0 +1,8 @@
.gitignore

test/
.travis.yml

gulpfile.js

.eslintrc
44 changes: 44 additions & 0 deletions package.json
@@ -0,0 +1,44 @@
{
"name": "postcss-reset",
"version": "1.0.0",
"description": "PostCSS plugin for partial styles reset",
"main": "dist/index.js",
"scripts": {
"prepublish": "babel src --out-dir dist",
"lint": "eslint .",
"tape": "babel-tape-runner 'test/*.js' | tap-spec",
"test": "npm run lint && npm run tape"
},
"repository": {
"type": "git",
"url": "https://github.com/maximkoretskiy/postcss-reset.git"
},
"keywords": [
"postcss",
"postcss-plugin",
"css",
"reset",
"isolation"
],
"author": "Maksim Koretskiy",
"license": "MIT",
"files": [
"dist",
"README.md"
],
"bugs": {
"url": "https://github.com/maximkoretskiy/postcss-reset/issues"
},
"homepage": "https://github.com/maximkoretskiy/postcss-reset",
"devDependencies": {
"babel": "^5.8.21",
"babel-eslint": "^4.0.10",
"babel-tape-runner": "^1.2.0",
"eslint": "^1.2.1",
"tap-spec": "^4.1.0",
"tape": "^4.2.0"
},
"dependencies": {
"postcss": "^5.0.2"
}
}
16 changes: 16 additions & 0 deletions src/index.js
@@ -0,0 +1,16 @@
import postcss from 'postcss';

export default postcss.plugin('postcss-autoreset', ()=> {
return (css) => {
css.walkRules( (rule)=> {
const firstNode = rule.nodes[0];
if (firstNode) {
firstNode.cloneAfter({prop: 'all', value: 'unset'});
}else {
rule.nodes.push(
postcss.decl({prop: 'all', value: 'unset'})
);
}
});
};
});
7 changes: 7 additions & 0 deletions test/fixtures/default.css
@@ -0,0 +1,7 @@
.selector-first {
padding: 1em;
}


.selector-second{
}
8 changes: 8 additions & 0 deletions test/fixtures/default.expected.css
@@ -0,0 +1,8 @@
.selector {
padding: 1em;
all: unset;
}

.selector-second{
all: reset;
}
28 changes: 28 additions & 0 deletions test/index.js
@@ -0,0 +1,28 @@
import fs from 'fs';
import test from 'tape';
import postcss from 'postcss';
import plugin from '../src';

function f(name) {
const fullName = 'test/fixtures/' + name + '.css';
return fs.readFileSync(fullName, 'utf8');
}

function makeCompareFn(t) {
return (input, output, opts = {}) => {
const css = postcss()
.use(plugin(opts))
.process(input).css;
t.equal(css, output);
};
}

test('postcss-autoreset', (t)=> {
const compare = makeCompareFn(t);

compare(
f('default'),
f('default.expected')
);
t.end();
});

0 comments on commit fa9efc0

Please sign in to comment.