Browse Source

Update CssRule and CssGenerator

pull/803/head
Artur Arseniev 9 years ago
parent
commit
482494f503
  1. 12
      src/code_manager/model/CssGenerator.js
  2. 23
      src/css_composer/model/CssRule.js
  3. 3
      src/parser/model/ParserCss.js

12
src/code_manager/model/CssGenerator.js

@ -86,8 +86,9 @@ module.exports = require('backbone').Model.extend({
*/
buildFromRule(rule, dump) {
let result = '';
const selectorStr = rule.selectorsToString();
const selectorStrNoAdd = rule.selectorsToString({ skipAdd: 1 });
const selectorsAdd = rule.get('selectorsAdd');
const singleAtRule = rule.get('singleAtRule');
let found;
// This will not render a rule if there is no its component
@ -98,12 +99,9 @@ module.exports = require('backbone').Model.extend({
}
});
if ((selectorStrNoAdd && found) || rule.get('selectorsAdd')) {
const style = rule.styleToString();
if (style) {
result += `${selectorStr}{${style}}`;
}
if ((selectorStrNoAdd && found) || selectorsAdd || singleAtRule) {
const block = rule.getDeclaration();
block && (result += block);
} else {
dump.push(rule);
}

23
src/css_composer/model/CssRule.js

@ -83,21 +83,34 @@ module.exports = Backbone.Model.extend(Styleable).extend({
},
/**
* Returns CSS string of the rule
* Get declaration block
* @param {Object} [opts={}] Options
* @return {string}
*/
toCSS(opts = {}) {
getDeclaration(opts = {}) {
let result = '';
const atRule = this.getAtRule();
const style = this.styleToString(opts);
const selectors = this.selectorsToString();
const style = this.styleToString(opts);
const singleAtRule = this.get('singleAtRule');
if (selectors && style) {
if ((selectors || singleAtRule) && style) {
result = singleAtRule ? style : `${selectors}{${style}}`;
}
return result;
},
/**
* Returns CSS string of the rule
* @param {Object} [opts={}] Options
* @return {string}
*/
toCSS(opts = {}) {
let result = '';
const atRule = this.getAtRule();
const block = this.getDeclaration(opts);
block && (result = block);
if (atRule && result) {
result = `${atRule}{${result}}`;
}

3
src/parser/model/ParserCss.js

@ -102,7 +102,7 @@ module.exports = config => ({
let singleAtRule = 0;
let atRuleType = '';
let condition = '';
// keyText if for CSSKeyframeRule
// keyText is for CSSKeyframeRule
let sels = node.selectorText || node.keyText;
const isSingleAtRule = singleAtRules.indexOf(type) >= 0;
@ -169,6 +169,7 @@ module.exports = config => ({
result.push(model);
}
}
// console.log('LAST PUSH', result[result.length - 1]);
}
return result;

Loading…
Cancel
Save