Permalink
Browse files

Make updates to theme parser logic and tool

  • Loading branch information...
1 parent 859c753 commit 4017abd825293656505b56c3ba966c81edc76112 @gjtorikian gjtorikian committed with nightwing Sep 12, 2012
Showing with 117 additions and 21 deletions.
  1. +30 −2 tool/Theme.tmpl.css
  2. +3 −1 tool/package.json
  3. +84 −18 tool/tmtheme.js
View
@@ -77,18 +77,26 @@
%keyword.operator%
}
+.%cssClass% .ace_keyword.ace_other.ace_unit {
+ %keyword.other.unit%
+}
+
.%cssClass% .ace_constant, .%cssClass% .ace_constant.ace_other {
%constant%
}
-.%cssClass% .ace_constant.ace_character {
+.%cssClass% .ace_constant.ace_character {
%constant.character%
}
-.%cssClass% .ace_constant.ace_character.ace_escape {
+.%cssClass% .ace_constant.ace_character.ace_escape {
%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
@@ -2,6 +2,8 @@
"name": "ace-tools",
"version": "0.1.0",
"dependencies": {
- "plist": ""
+ "plist": "",
+ "css-parse": "",
+ "css-stringify": ""
}
}
View
@@ -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,6 +11,8 @@ function parseTheme(themeXml, callback) {
});
}
+var unsupportedScopes = { };
+
var supportedScopes = {
"keyword": "keyword",
"keyword.operator": "keyword.operator",
@@ -90,22 +96,34 @@ 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)
- colors.fold = ((colors["entity.name.function"] || colors.keyword).match(/\:([^;]+)/)||[])[1];
+ if (!colors.fold) {
+ var foldSource = colors["entity.name.function"] || colors.keyword;
+ if (foldSource) {
+ colors.fold = foldSource.match(/\:([^;]+)/)[1];
+ }
+ }
if (!colors.selected_word_highlight)
colors.selected_word_highlight = "border: 1px solid " + colors.selection + ";";
@@ -178,7 +196,7 @@ var cssTemplate = fs.readFileSync(__dirname + "/Theme.tmpl.css", "utf8");
var jsTemplate = fs.readFileSync(__dirname + "/Theme.tmpl.js", "utf8");
var themes = {
- //"chrome": "Chrome",
+ //"chrome": "Chrome DevTools",
"clouds": "Clouds",
"clouds_midnight": "Clouds Midnight",
"cobalt": "Cobalt",
@@ -196,14 +214,15 @@ var themes = {
"pastel_on_dark": "Pastels on Dark",
"solarized_dark": "Solarized-dark",
"solarized_light": "Solarized-light",
- //"textmate": "Textmate",
+ //"textmate": "Textmate (Mac Classic)",
"tomorrow": "Tomorrow",
"tomorrow_night": "Tomorrow-Night",
"tomorrow_night_blue": "Tomorrow-Night-Blue",
"tomorrow_night_bright": "Tomorrow-Night-Bright",
"tomorrow_night_eighties": "Tomorrow-Night-Eighties",
"twilight": "Twilight",
- "vibrant_ink": "Vibrant Ink"
+ "vibrant_ink": "Vibrant Ink",
+ "xcode": "Xcode_default"
};
function convertTheme(name) {
@@ -224,10 +243,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.");

0 comments on commit 4017abd

Please sign in to comment.