From 4017abd825293656505b56c3ba966c81edc76112 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Tue, 11 Sep 2012 17:05:36 -0700 Subject: [PATCH] Make updates to theme parser logic and tool --- tool/Theme.tmpl.css | 32 +++++++++++++- tool/package.json | 4 +- tool/tmtheme.js | 102 ++++++++++++++++++++++++++++++++++++-------- 3 files changed, 117 insertions(+), 21 deletions(-) diff --git a/tool/Theme.tmpl.css b/tool/Theme.tmpl.css index 8b52ef83..6bb17908 100644 --- a/tool/Theme.tmpl.css +++ b/tool/Theme.tmpl.css @@ -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; } diff --git a/tool/package.json b/tool/package.json index c576aff2..a96e830d 100644 --- a/tool/package.json +++ b/tool/package.json @@ -2,6 +2,8 @@ "name": "ace-tools", "version": "0.1.0", "dependencies": { - "plist": "" + "plist": "", + "css-parse": "", + "css-stringify": "" } } diff --git a/tool/tmtheme.js b/tool/tmtheme.js index fca5453b..81104f0e 100755 --- a/tool/tmtheme.js +++ b/tool/tmtheme.js @@ -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 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 .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); \ No newline at end of file +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."); \ No newline at end of file