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
18 changes: 11 additions & 7 deletions lib/cssModules.es6
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ function getCssClassName(cssModulesPath, cssModuleName) {
}

const cssModules = getCssModules(path.resolve(cssModulesPath));
const cssClassName = _get(cssModules, cssModuleName);
if (! cssClassName) {
throw getError('CSS module "' + cssModuleName + '" is not found');
} else if (typeof cssClassName !== 'string') {
throw getError('CSS module "' + cssModuleName + '" is not a string');
}

return cssClassName;
return cssModuleName.split(' ')
.map(cssModuleName => {
const cssClassName = _get(cssModules, cssModuleName);
if (! cssClassName) {
throw getError('CSS module "' + cssModuleName + '" is not found');
} else if (typeof cssClassName !== 'string') {
throw getError('CSS module "' + cssModuleName + '" is not a string');
}
return cssClassName;
})
.join(' ');
}


Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"babel-preset-es2015": "^6.3.13",
"eslint": "^2.0.0",
"expect": "^1.14.0",
"mocha": "^2.4.5",
"posthtml": "^0.8.2",
"mocha": "^3.2.0",
"posthtml": "^0.9.2",
"rimraf": "^2.5.2"
},
"repository": {
Expand Down
1 change: 1 addition & 0 deletions test/classes.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"title": "__title __heading",
"color": "__color",
"user": {
"profile": {
"photo": "__user__profile__photo"
Expand Down
8 changes: 8 additions & 0 deletions test/cssModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ describe('posthtml-css-modules', () => {
);
});

it('should inline CSS module from the file (multiple classes)', () => {
return init(
'<div class="foob" css-module="title color"></div>',
'<div class="foob __title __heading __color"></div>',
classesPath
);
});


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