Skip to content

Commit ebc1b49

Browse files
authored
Merge pull request #8 from GitScrum/master
[feat]: add multiple classes
2 parents 3b61293 + 18340d5 commit ebc1b49

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

lib/cssModules.es6

+11-7
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,18 @@ function getCssClassName(cssModulesPath, cssModuleName) {
3535
}
3636

3737
const cssModules = getCssModules(path.resolve(cssModulesPath));
38-
const cssClassName = _get(cssModules, cssModuleName);
39-
if (! cssClassName) {
40-
throw getError('CSS module "' + cssModuleName + '" is not found');
41-
} else if (typeof cssClassName !== 'string') {
42-
throw getError('CSS module "' + cssModuleName + '" is not a string');
43-
}
4438

45-
return cssClassName;
39+
return cssModuleName.split(' ')
40+
.map(cssModuleName => {
41+
const cssClassName = _get(cssModules, cssModuleName);
42+
if (! cssClassName) {
43+
throw getError('CSS module "' + cssModuleName + '" is not found');
44+
} else if (typeof cssClassName !== 'string') {
45+
throw getError('CSS module "' + cssModuleName + '" is not a string');
46+
}
47+
return cssClassName;
48+
})
49+
.join(' ');
4650
}
4751

4852

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
"babel-preset-es2015": "^6.3.13",
3737
"eslint": "^2.0.0",
3838
"expect": "^1.14.0",
39-
"mocha": "^2.4.5",
40-
"posthtml": "^0.8.2",
39+
"mocha": "^3.2.0",
40+
"posthtml": "^0.9.2",
4141
"rimraf": "^2.5.2"
4242
},
4343
"repository": {

test/classes.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"title": "__title __heading",
3+
"color": "__color",
34
"user": {
45
"profile": {
56
"photo": "__user__profile__photo"

test/cssModules.js

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ describe('posthtml-css-modules', () => {
2525
);
2626
});
2727

28+
it('should inline CSS module from the file (multiple classes)', () => {
29+
return init(
30+
'<div class="foob" css-module="title color"></div>',
31+
'<div class="foob __title __heading __color"></div>',
32+
classesPath
33+
);
34+
});
35+
2836

2937
it('should inline CSS module from the directory', () => {
3038
return init(

0 commit comments

Comments
 (0)