From 482494f5036ec62af3a9ac58d2fae0fb73ae1845 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Wed, 24 Jan 2018 22:31:04 +0100 Subject: [PATCH] Update CssRule and CssGenerator --- src/code_manager/model/CssGenerator.js | 12 +++++------- src/css_composer/model/CssRule.js | 23 ++++++++++++++++++----- src/parser/model/ParserCss.js | 3 ++- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/code_manager/model/CssGenerator.js b/src/code_manager/model/CssGenerator.js index fb977267f..3b857cad0 100644 --- a/src/code_manager/model/CssGenerator.js +++ b/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); } diff --git a/src/css_composer/model/CssRule.js b/src/css_composer/model/CssRule.js index a3d410f14..7599db4a1 100644 --- a/src/css_composer/model/CssRule.js +++ b/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}}`; } diff --git a/src/parser/model/ParserCss.js b/src/parser/model/ParserCss.js index dbe6cd038..55360ec3f 100644 --- a/src/parser/model/ParserCss.js +++ b/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;