Browse Source

Start with the node check

pull/1446/head
Artur Arseniev 8 years ago
parent
commit
d473722d94
  1. 5
      src/parser/index.js
  2. 19
      src/parser/model/ParserCss.js

5
src/parser/index.js

@ -60,6 +60,11 @@ module.exports = () => {
return pHtml.parse(str, pCss);
},
/**
* Parse CSS string and return valid model
* @param {string} str CSS string
* @return {Array<Object>}
*/
parseCss(str) {
return pCss.parse(str);
}

19
src/parser/model/ParserCss.js

@ -1,3 +1,4 @@
import { isString } from 'underscore';
import BrowserCssParser from './BrowserParserCss';
module.exports = (config = {}) => ({
@ -7,7 +8,23 @@ module.exports = (config = {}) => ({
* @return {Array<Object>}
*/
parse(str) {
let result = [];
const customParser = config.parserCss;
return customParser ? customParser(str) : BrowserCssParser(str);
const nodes = customParser ? customParser(str) : BrowserCssParser(str);
nodes.forEach(node => (result = result.concat(this.checkNode(node))));
return result;
},
/**
* Check the returned node from a custom parser and transforms it to
* a valid object for the CSS composer
* @return {[type]}
*/
checkNode(node) {
if (isString(node.selectors)) {
}
return node;
}
});

Loading…
Cancel
Save