Make updates to theme parser logic and tool

This commit is contained in:
Garen Torikian 2012-09-11 17:05:36 -07:00
commit e467665909
44 changed files with 1250 additions and 974 deletions

View file

@ -77,6 +77,10 @@
%keyword.operator%
}
.%cssClass% .ace_keyword.ace_other.ace_unit {
%keyword.other.unit%
}
.%cssClass% .ace_constant, .%cssClass% .ace_constant.ace_other {
%constant%
}
@ -89,6 +93,10 @@
%constant.character.escape%
}
.%cssClass% .ace_constant.ace_character.ace_entity {
%constant.character.entity%
}
.%cssClass% .ace_constant.ace_language {
%constant.language%
}
@ -105,6 +113,10 @@
%constant.other%
}
.%cssClass% .ace_constant.ace_other.ace_color {
%constant.other.color%
}
.%cssClass% .ace_invalid {
%invalid%
}
@ -125,6 +137,10 @@
%support.constant%
}
.%cssClass% support.constant.property-value {
%support.constant.property-value%
}
.%cssClass% .ace_fold {
background-color: %fold%;
border-color: %foreground%;
@ -210,6 +226,10 @@
%ace.meta.tag.input%
}
.%cssClass% .ace_meta.ace_selector {
%meta.selector%
}
.%cssClass% .ace_entity.ace_other.ace_attribute-name {
%entity.other.attribute-name%
}
@ -222,6 +242,14 @@
%entity.name.function%
}
.%cssClass% .ace_entity.ace_other.ace_inherited-class {
%entity.other.inherited-class%
}
.%cssClass% .ace_entity.ace_name.ace_tag {
%entity.name.tag%
}
.%cssClass% .ace_markup.ace_underline {
text-decoration:underline;
}

View file

@ -2,6 +2,8 @@
"name": "ace-tools",
"version": "0.1.0",
"dependencies": {
"plist": ""
"plist": "",
"css-parse": "",
"css-stringify": ""
}
}

View file

@ -1,4 +1,8 @@
var fs = require("fs");
var path = require("path");
var util = require("util");
var cssParse = require("css-parse");
var cssStringify = require("css-stringify");
var parseString = require("plist").parseString;
function parseTheme(themeXml, callback) {
@ -7,9 +11,12 @@ function parseTheme(themeXml, callback) {
});
}
var unsupportedScopes = { };
var supportedScopes = {
"keyword": "keyword",
"keyword.operator": "keyword.operator",
"keyword.other.unit": "keyword.other.unit",
"constant": "constant",
"constant.language": "constant.language",
@ -17,6 +24,7 @@ var supportedScopes = {
"constant.numeric": "constant.numeric",
"constant.character" : "constant.character",
"constant.character.escape" : "constant.character.escape",
"constant.character.entity": "constant.character.entity",
"constant.other" : "constant.other",
"support": "support",
@ -25,6 +33,7 @@ var supportedScopes = {
"support.function.firebug": "support.firebug",
"support.function.constant": "support.function.constant",
"support.constant": "support.constant",
"support.constant.property-value": "support.constant.property-value",
"support.class": "support.class",
"support.type": "support.type",
"support.other": "support.other",
@ -53,11 +62,12 @@ var supportedScopes = {
"meta": "meta",
"meta.tag.sgml.doctype": "xml_pe",
"meta.tag": "meta.tag",
"meta.tag.form": "meta.tag.form",
"meta.selector": "meta.selector",
"entity.other.attribute-name": "entity.other.attribute-name",
"entity.name.function": "entity.name.function",
"entity.name": "entity.name",
"entity.name.tag": "entity.name.tag",
"markup.heading": "markup.heading",
"markup.heading.1": "markup.heading.1",
@ -68,7 +78,9 @@ var supportedScopes = {
"markup.heading.6": "markup.heading.6",
"markup.list": "markup.list",
"collab.user1": "collab.user1"
"collab.user1": "collab.user1",
"text": "text"
};
function extractStyles(theme) {
@ -90,18 +102,26 @@ function extractStyles(theme) {
};
for (var i=1; i<theme.settings.length; i++) {
var element = theme.settings[i];
if (!element.scope)
continue;
var scopes = element.scope.split(/\s*[|,]\s*/g);
for (var j=0; j<scopes.length; j++) {
var scope = scopes[j];
if (supportedScopes[scope]) {
colors[supportedScopes[scope]] = parseStyles(element.settings);
} else {
//console.log(scope + " is not supported!");
}
var element = theme.settings[i];
if (!element.scope)
continue;
var scopes = element.scope.split(/\s*[|,]\s*/g);
for (var j=0; j<scopes.length; j++) {
var scope = scopes[j];
var style = parseStyles(element.settings);
if (supportedScopes[scope]) {
colors[supportedScopes[scope]] = style;
}
else if (style.length > 0) {
if (unsupportedScopes[scope] === undefined) {
unsupportedScopes[scope] = 1;
}
else {
unsupportedScopes[scope] = unsupportedScopes[scope] + 1;
}
}
}
}
if (!colors.fold)
@ -224,10 +244,57 @@ function convertTheme(name) {
isDark: styles.isDark
});
// we're going to look for NEW rules in the parsed content only
// if such a rule exists, add it to the destination file
// this way, we preserve all hand-modified rules in the <theme>.css rules,
// (because some exist, for collab1 and ace_indentation_guide
try {
var outThemeCss = fs.readFileSync(__dirname + "/../lib/ace/theme/" + name + ".css");
var parsedExistingFile = cssParse(outThemeCss);
var parsedPotentialFile = cssParse(css);
for (var r = 0; r < parsedPotentialFile.stylesheet.rules.length; r++) {
var potentialSelectors = parsedPotentialFile.stylesheet.rules[r].selectors;
var found = false;
for (var e = 0; e < parsedExistingFile.stylesheet.rules.length; e++) {
var existingSelectors = parsedExistingFile.stylesheet.rules[e].selectors;
if (existingSelectors.join(",") === potentialSelectors.join(",")) {
found = true;
break;
}
}
if (!found) {
console.log("Adding NEW rule: ", parsedPotentialFile.stylesheet.rules[r])
parsedExistingFile.stylesheet.rules.splice(r, 0, parsedPotentialFile.stylesheet.rules[r]);
}
}
css = cssStringify(parsedExistingFile, { compress: false });
} catch(e) {
console.log("Creating new file: " + name + ".css")
}
fs.writeFileSync(__dirname + "/../lib/ace/theme/" + name + ".js", js);
fs.writeFileSync(__dirname + "/../lib/ace/theme/" + name + ".css", css);
})
}
for (var name in themes)
convertTheme(name);
for (var name in themes) {
convertTheme(name);
}
var sortedUnsupportedScopes = {};
for (var u in unsupportedScopes) {
var value = unsupportedScopes[u];
if (sortedUnsupportedScopes[value] === undefined) {
sortedUnsupportedScopes[value] = [];
}
sortedUnsupportedScopes[value].push(u);
}
console.log("I found these unsupported scopes:");
console.log(sortedUnsupportedScopes);
console.log("It's safe to ignore these, but they may affect your syntax highlighting if your mode depends on any of these rules.");
console.log("Refer to the docs on ace.ajax.org for information on how to add a scope to the CSS generator.");