Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

values example #10

Merged
merged 1 commit into from
Mar 28, 2016
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
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const plugin = require('postcss').plugin;
const queue = require('async').queue;
const promisify = require('promisify-api');
const readFile = require('fs').readFile;
const replaceSymbols = require('icss-replace-symbols').default;
const resolveDeps = require('./lib/resolveDeps');
const updateExports = require('./lib/updateExports');
const walkImports = require('./lib/walkImports');
Expand Down Expand Up @@ -36,6 +37,7 @@ const postcssResolveDeps = plugin('resolve-dependency-imports', function () {
});

return Promise.all(pending)
.then(() => replaceSymbols(tree, translations))
.then(() => updateExports(tree, translations));
};
});
Expand Down Expand Up @@ -85,6 +87,7 @@ module.exports = plugin(nameOfTheCurrentPlugin, function (opts) {
});

return Promise.all(pending)
.then(() => replaceSymbols(tree, translations))
.then(() => updateExports(tree, translations))
.then(() => resolveDeps(processFile.traces))
.then(files => {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
"homepage": "https://github.com/sullenor/postcss-modules-resolve-imports#readme",
"dependencies": {
"async": "^1.5.2",
"icss-replace-symbols": "^1.0.2",
"lodash": "^4.6.1",
"postcss": "^5.0.19",
"postcss-modules-extract-exports": "^1.0.0",
"postcss-modules-values": "^1.1.2",
"promisify-api": "^1.1.0",
"resolve": "^1.1.7"
},
Expand Down
4 changes: 4 additions & 0 deletions test/cases/values/borders.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.dashed
{
border: 4px dashed;
}
3 changes: 3 additions & 0 deletions test/cases/values/breakpoints.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@value small (max-width: 599px);
@value medium (min-width: 600px) and (max-width: 959px);
@value large (min-width: 960px);
20 changes: 20 additions & 0 deletions test/cases/values/colors.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@value primary: #f01;
@value secondary: #2f2;

.text-primary
{
color: primary;
}
.bg-primary
{
background-color: primary;
}

.text-secondary
{
color: secondary;
}
.bg-secondary
{
background-color: secondary;
}
43 changes: 43 additions & 0 deletions test/cases/values/expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
._test_cases_values_borders__dashed{
border: 4px dashed;
}

._test_cases_values_colors__text-primary{
color: #f01;
}

._test_cases_values_colors__bg-primary{
background-color: #f01;
}

._test_cases_values_colors__text-secondary{
color: #2f2;
}

._test_cases_values_colors__bg-secondary{
background-color: #2f2;
}
/* Imports without a "from" are just passed through */
@import url('./old-skool.css');

._test_cases_values_source__foo
{
border-color: #2f2;
box-shadow: 0 0 10px #f01;
}

@media (max-width: 599px)
{
._test_cases_values_source__foo
{
background: white;
}
}

@media (min-width: 600px) and (max-width: 959px)
{
._test_cases_values_source__foo
{
background: peru;
}
}
9 changes: 9 additions & 0 deletions test/cases/values/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"blue": "#f01",
"borders": "'./borders.css'",
"breakpoints": "'./breakpoints.css'",
"foo": "_test_cases_values_source__foo _test_cases_values_borders__dashed _test_cases_values_colors__text-secondary",
"medium": "(min-width: 600px) and (max-width: 959px)",
"secondary": "#2f2",
"small": "(max-width: 599px)"
}
31 changes: 31 additions & 0 deletions test/cases/values/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@value borders: './borders.css', breakpoints: './breakpoints.css';
@value small, medium from breakpoints;
@value secondary, primary as blue from './colors.css';

/* Imports without a "from" are just passed through */
@import url('./old-skool.css');

.foo
{
border-color: secondary;
box-shadow: 0 0 10px blue;

composes: dashed from borders;
composes: text-secondary from './colors.css';
}

@media small
{
.foo
{
background: white;
}
}

@media medium
{
.foo
{
background: peru;
}
}
2 changes: 2 additions & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ const ExtractImports = require('postcss-modules-extract-imports');
const Scope = require('postcss-modules-scope');
const ResolveImports = require('../index');
const ExtractExports = require('postcss-modules-extract-exports');
const Values = require('postcss-modules-values');

global.assert = require('assert');
global.runner = function () {
return postcss([
Values,
LocalByDefault,
ExtractImports,
new Scope({generateScopedName: (local, filename) =>
Expand Down