Make style generation module more loosely coupled by only caring about tags and class definitions

master
Sven Slootweg 7 years ago
parent 863a93e381
commit 17909f2ed1

@ -1,15 +1,15 @@
'use strict'; 'use strict';
module.exports = function generateItemStyle(item, options) { module.exports = function generateItemStyle(tags, classes) {
let style = Object.assign({}, options.defaultStyle); let style = {};
item.tags.forEach((tag) => { tags.forEach((tag) => {
if (tag.type === "class") { if (tag.type === "class") {
tag.classNames.forEach((className) => { tag.classNames.forEach((className) => {
if (options.classes[className] == null) { if (classes[className] == null) {
throw new Error(`Encountered unrecognized class ${className} in text`); throw new Error(`Encountered unrecognized class ${className} in text`);
} else { } else {
Object.assign(style, options.classes[className]); Object.assign(style, classes[className]);
} }
}); });
} }

Loading…
Cancel
Save