Skip to content

Commit

Permalink
Do not require quotes on rules creation
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Jun 14, 2017
1 parent f40da13 commit c4da800
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 47 deletions.
36 changes: 18 additions & 18 deletions src/createICSSRules.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import postcss from 'postcss'
import postcss from "postcss";

const createImports = imports => {
return Object.keys(imports).map(path => {
const aliases = imports[path]
const aliases = imports[path];
const declarations = Object.keys(aliases).map(key =>
postcss.decl({
prop: key,
value: aliases[key],
raws: { before: '\n ' }
raws: { before: "\n " }
})
)
);
return postcss
.rule({
selector: `:import(${path})`,
raws: { after: '\n' }
selector: `:import('${path}')`,
raws: { after: "\n" }
})
.append(declarations)
})
}
.append(declarations);
});
};

const createExports = exports => {
const declarations = Object.keys(exports).map(key =>
postcss.decl({
prop: key,
value: exports[key],
raws: { before: '\n ' }
raws: { before: "\n " }
})
)
);
if (declarations.length === 0) {
return []
return [];
}
const rule = postcss
.rule({
selector: `:export`,
raws: { after: '\n' }
raws: { after: "\n" }
})
.append(declarations)
return [rule]
}
.append(declarations);
return [rule];
};

const createICSSRules = (imports, exports) => [
...createImports(imports),
...createExports(exports)
]
];

export default createICSSRules
export default createICSSRules;
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as replaceValueSymbols } from './replaceValueSymbols.js'
export { default as replaceSymbols } from './replaceSymbols.js'
export { default as extractICSS } from './extractICSS.js'
export { default as createICSSRules } from './createICSSRules.js'
export { default as replaceValueSymbols } from "./replaceValueSymbols.js";
export { default as replaceSymbols } from "./replaceSymbols.js";
export { default as extractICSS } from "./extractICSS.js";
export { default as createICSSRules } from "./createICSSRules.js";
45 changes: 20 additions & 25 deletions test/createICSSRules.test.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,47 @@
import postcss from 'postcss'
import { createICSSRules } from '../src'
/* eslint-env jest */
import postcss from "postcss";
import { createICSSRules } from "../src";

const run = (imports, exports) => {
return postcss.root().append(createICSSRules(imports, exports)).toString()
}
return postcss.root().append(createICSSRules(imports, exports)).toString();
};

test('create :import statement', () => {
test("create :import statement", () => {
expect(
run(
{
colors: {
a: 'b',
c: 'd'
},
'"path/file"': {
e: 'f'
"path/file": {
e: "f"
}
},
{}
)
).toEqual(
':import(colors) {\n a: b;\n c: d\n}\n:import("path/file") {\n e: f\n}'
)
})
).toEqual(":import('path/file') {\n e: f\n}");
});

test('create :export statement', () => {
test("create :export statement", () => {
expect(
run(
{},
{
a: 'b',
c: 'd'
a: "b",
c: "d"
}
)
).toEqual(':export {\n a: b;\n c: d\n}')
})
).toEqual(":export {\n a: b;\n c: d\n}");
});

test('create :import and :export', () => {
test("create :import and :export", () => {
expect(
run(
{
colors: {
a: 'b'
a: "b"
}
},
{
c: 'd'
c: "d"
}
)
).toEqual(':import(colors) {\n a: b\n}\n:export {\n c: d\n}')
})
).toEqual(":import('colors') {\n a: b\n}\n:export {\n c: d\n}");
});

0 comments on commit c4da800

Please sign in to comment.