Skip to content

Commit

Permalink
added keepUnusedStyles functionality for media rules
Browse files Browse the repository at this point in the history
  • Loading branch information
arthuralmeidap committed Apr 25, 2018
1 parent 6a61ca2 commit cfb5752
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/code_manager/model/CssGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ module.exports = require('backbone').Model.extend({
for (let atRule in atRules) {
let rulesStr = '';
const mRules = atRules[atRule];
mRules.forEach(rule => (rulesStr += this.buildFromRule(rule, dump)));
mRules.forEach(
rule => (rulesStr += this.buildFromRule(rule, dump, opts))
);

if (rulesStr) {
code += `${atRule}{${rulesStr}}`;
Expand Down
16 changes: 16 additions & 0 deletions test/specs/grapesjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,22 @@ describe('GrapesJS', () => {
expect(css).toEqual(`${protCss}.test2{color:red;}.test3{color:blue;}`);
});

it('Keep unused css classes/selectors option for media rules', () => {
cssString =
'.test2{color:red}.test3{color:blue} @media only screen and (max-width: 620px) { .notused { color: red; } } ';
documentEl = '<style>' + cssString + '</style>' + htmlString;
config.fromElement = 1;
config.storageManager = { type: 0 };
fixture.innerHTML = documentEl;
const editor = obj.init(config);
const css = editor.getCss({ keepUnusedStyles: 1 });
const protCss = editor.getConfig().protectedCss;
expect(editor.getStyle().length).toEqual(3);
expect(css).toEqual(
`${protCss}.test2{color:red;}.test3{color:blue;}@media only screen and (max-width: 620px){.notused{color:red;}}`
);
});

it('Keep unused css classes/selectors option for init method', () => {
config.fromElement = 1;
config.storageManager = { type: 0 };
Expand Down

0 comments on commit cfb5752

Please sign in to comment.