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) { buildFromRule(rule, dump) {
let result = ''; let result = '';
const selectorStr = rule.selectorsToString();
const selectorStrNoAdd = rule.selectorsToString({ skipAdd: 1 }); const selectorStrNoAdd = rule.selectorsToString({ skipAdd: 1 });
const selectorsAdd = rule.get('selectorsAdd');
const singleAtRule = rule.get('singleAtRule');
let found; let found;
// This will not render a rule if there is no its component // 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')) { if ((selectorStrNoAdd && found) || selectorsAdd || singleAtRule) {
const style = rule.styleToString(); const block = rule.getDeclaration();
block && (result += block);
if (style) {
result += `${selectorStr}{${style}}`;
}
} else { } else {
dump.push(rule); 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 * @param {Object} [opts={}] Options
* @return {string} * @return {string}
*/ */
toCSS(opts = {}) { getDeclaration(opts = {}) {
let result = ''; let result = '';
const atRule = this.getAtRule();
const style = this.styleToString(opts);
const selectors = this.selectorsToString(); const selectors = this.selectorsToString();
const style = this.styleToString(opts);
const singleAtRule = this.get('singleAtRule'); const singleAtRule = this.get('singleAtRule');
if (selectors && style) { if ((selectors || singleAtRule) && style) {
result = singleAtRule ? style : `${selectors}{${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) { if (atRule && result) {
result = `${atRule}{${result}}`; result = `${atRule}{${result}}`;
} }

3
src/parser/model/ParserCss.js

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

Loading…
Cancel
Save