Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue converting from JSON (ordered) to CSS #18

Open
svarlitskiy opened this issue Jul 11, 2017 · 2 comments
Open

Issue converting from JSON (ordered) to CSS #18

svarlitskiy opened this issue Jul 11, 2017 · 2 comments

Comments

@svarlitskiy
Copy link

Basically I can convert the css to JSON ordered but not back to css. Here are the fixes I would recommend to allow for that to happen correctly:

In CSSJSON.js -> base.toJSON function

replace

} else if (!isEmpty(match[capEnd])) {
    // Node has finished
    return node;
}

with

} else if (!isEmpty(match[capEnd])) {
    // Node has finished
    if (args.ordered) node.length=count;
    return node;
}

replace

return node;

with

if (args.ordered) node.length=count;
return node;

In CSSJSON.js -> base.toCSS function

replace

return cssString;

with

if ( typeof node.length === "number" ) {
    for (var j = 0; j < node.length; j++) {
        cssString += base.toCSS(node[j], depth);
    }
}
else if ( typeof node.value === "object" ) {
    cssString += strNode(node.name, node.value, depth);
}
else if ( typeof node.value != undefined ) {
    cssString += strAttr(node.name, node.value, depth);
}
return cssString;

In CSSJSON.js -> strNode function

replace

var strNode = function (name, value, depth) {
    var cssString = '\t'.repeat(depth) + name + ' {\n';
    cssString += base.toCSS(value, depth + 1);
    cssString += '\t'.repeat(depth) + '}\n';
    return cssString;
};

with

var strNode = function (name, value, depth) {
    var cssIndent = '\t'.repeat(depth), 
        cssString = cssIndent + name.split(/\s*,\s*/gi).join( ',\n' + cssIndent ) + ' {\n';

    cssString += base.toCSS(value, depth + 1);
    cssString += cssIndent + '}\n';
    return cssString;
};
@Kompwu
Copy link

Kompwu commented Jul 29, 2018

@svarlitskiy Hi, can you make a PR please ?

@dozsolti
Copy link

@svarlitskiy I tried but it doesn't work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants