Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
<a name="0.0.2"></a>
## 0.0.2 (2017-04-03)

* 0.0.2 ([3ba3e1d](https://github.com/GitScrum/posthtml-class-to-css-module/commit/3ba3e1d))
* typo ([0b526d6](https://github.com/GitScrum/posthtml-class-to-css-module/commit/0b526d6))
* Update readme.md ([85970a1](https://github.com/GitScrum/posthtml-class-to-css-module/commit/85970a1))
* chore(changelog): Update changelog ([359f13b](https://github.com/GitScrum/posthtml-class-to-css-module/commit/359f13b))
* chore(package): update babel-preset-env to version 1.3.2 ([2cb3ae8](https://github.com/GitScrum/posthtml-class-to-css-module/commit/2cb3ae8))
* chore(package): update clean ([06d537b](https://github.com/GitScrum/posthtml-class-to-css-module/commit/06d537b))
* chore(package): update conventional-changelog-lint to version 1.1.8 ([5936c0c](https://github.com/GitScrum/posthtml-class-to-css-module/commit/5936c0c))
* chore(package): update coveralls to version 2.13.0 ([db7f4df](https://github.com/GitScrum/posthtml-class-to-css-module/commit/db7f4df))
* chore(package): update eslint to version 3.19.0 ([8aabfb2](https://github.com/GitScrum/posthtml-class-to-css-module/commit/8aabfb2))
* chore(package): update updtr to version 1.0.0 ([b5feb6b](https://github.com/GitScrum/posthtml-class-to-css-module/commit/b5feb6b))
* chore(yarn.lock): add yarn ([5007d72](https://github.com/GitScrum/posthtml-class-to-css-module/commit/5007d72))
* test(test-plugin): add test for #9 ([274d72e](https://github.com/GitScrum/posthtml-class-to-css-module/commit/274d72e))
* docs(readme): add description for option removeClass ([648e48b](https://github.com/GitScrum/posthtml-class-to-css-module/commit/648e48b))
* feat(index): add remove class option, close #9 ([bff8bc4](https://github.com/GitScrum/posthtml-class-to-css-module/commit/bff8bc4)), closes [#9](https://github.com/GitScrum/posthtml-class-to-css-module/issues/9)



<a name="0.0.1"></a>
## 0.0.1 (2017-03-20)

Expand Down
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "posthtml-class-to-css-module",
"version": "0.0.1",
"version": "0.0.2",
"description": "A posthtml plugin for removing tags",
"license": "MIT",
"repository": "GitScrum/posthtml-class-to-css-module",
Expand All @@ -25,8 +25,8 @@
"minor": "np minor --any-branch",
"major": "np major --any-branch",
"test": "nyc ava",
"clean": "rm -rf lib && mkdir lib",
"build": "npm run clean && babel src/ -d lib/",
"clean": "rm -rf lib",
"build": "npm run clean && babel src -d lib",
"prepublish": "npm run build",
"update": "updtr && ava-codemods --force",
"testen": "testen -n -- ava"
Expand All @@ -45,21 +45,23 @@
"copy",
"css-modules"
],
"dependencies": {},
"dependencies": {
"core-js": "^2.4.1"
},
"devDependencies": {
"ava": "*",
"ava-codemods": "^0.3.2",
"babel-cli": "^6.11.4",
"babel-eslint": "^7.1.1",
"babel-plugin-add-module-exports": "^0.2.0",
"babel-preset-babili": "0.0.12",
"babel-preset-env": "^1.1.8",
"babel-preset-env": "^1.3.2",
"babel-register": "^6.11.6",
"clinton": "^0.11.0",
"conventional-changelog-cli": "^1.2.0",
"conventional-changelog-lint": "^1.0.0",
"coveralls": "^2.11.12",
"eslint": "^3.1.1",
"conventional-changelog-lint": "^1.1.8",
"coveralls": "^2.13.0",
"eslint": "^3.19.0",
"eslint-config-xo": "^0.18.1",
"eslint-formatter-pretty": "^1.1.0",
"eslint-plugin-ava": "^4.2.0",
Expand All @@ -73,7 +75,7 @@
"nyc": "^10.1.2",
"posthtml": "^0.9.0",
"testen": "^2.2.0",
"updtr": "^0.2.1"
"updtr": "^1.0.0"
},
"ava": {
"require": [
Expand Down
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ Returns the html with cloned classes in the attribute `css-module`
</html>
```

## Options

### `removeClass`
Type: `Boolean`
Default: false
Description: *Removes the `class` attribute after cloning the `class` value to an attribute `css-module`*

## LICENSE

> MIT License (MIT)
Expand Down
21 changes: 18 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import Reflect from 'core-js/fn/reflect';

const clone = tree => tree.match(
{attrs: {class: /.+/}},
node => Object.assign(node, Object.assign(node.attrs, {'css-module': node.attrs.class}))
);

const cloneClassTo = tree => Promise.resolve(tree).then(tree => clone(tree)).then(tree => tree);
const removeClass = tree => tree.match(
{attrs: {class: /.+/}},
node => {
console.log(node);
delete node.attrs.class;

return node;
}
);

const cloneClassTo = (tree, options) => Promise.resolve(tree)
.then(tree => clone(tree))
.then(tree => (Reflect.has(options, 'removeClass') && options.removeClass) ? removeClass(tree) : tree)
.then(tree => tree);

export default () => {
export default (options = {}) => {
return tree => new Promise((resolve, reject) => {
if (!Array.isArray(tree)) {
reject(new Error(`tree is not Array`));
Expand All @@ -15,6 +30,6 @@ export default () => {
resolve(tree);
}

resolve(cloneClassTo(tree));
resolve(cloneClassTo(tree, options));
});
};
10 changes: 8 additions & 2 deletions test/test-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import posthtml from 'posthtml';
import isPromise from 'is-promise';
import clone from '../src/index.js';

function processing(html) {
function processing(html, options) {
return posthtml()
.use(clone())
.use(clone(options))
.process(html);
}

Expand All @@ -26,3 +26,9 @@ test('should clone to attribute css module', async t => {
const expected = '<html><head></head><body class="my-class-to-body" css-module="my-class-to-body"></body></html>';
t.deepEqual(expected, (await processing(fixture)).html);
});

test('should remove attribute class after clone', async t => {
const fixture = '<html><head></head><body class="my-class-to-body"></body></html>';
const expected = '<html><head></head><body css-module="my-class-to-body"></body></html>';
t.deepEqual(expected, (await processing(fixture, {removeClass: true})).html);
});
Loading