From 3a7a4499c3efc8f549f2b9b018b9ed7fc8eaf5b6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 6 Mar 2014 13:52:48 -0800 Subject: [PATCH 1/6] Support converting more TextMate theme styles --- src/text-mate-theme.coffee | 29 +++++++++++++++++++++-------- src/theme-converter.coffee | 6 +++++- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/text-mate-theme.coffee b/src/text-mate-theme.coffee index 835440110..f9211cbda 100644 --- a/src/text-mate-theme.coffee +++ b/src/text-mate-theme.coffee @@ -10,9 +10,24 @@ class TextMateTheme buildRulesets: -> {settings} = plist.parseStringSync(@contents) - @buildSyntaxVariables(settings[0]) - @buildGlobalSettingsRulesets(settings[0]) - @buildScopeSelectorRulesets(settings[1..]) + + for setting in settings + {scope, name} = setting.settings + continue if scope or name + + # Require all of these or invalid LESS will be generated if any required + # variable value is missing + {background, foreground, caret, selection, lineHighlight} = setting.settings + if background and foreground and caret and selection and lineHighlight + variableSettings = setting.settings + break + + unless variableSettings? + throw new Error('Could not find color settings in theme to convert') + + @buildSyntaxVariables(variableSettings) + @buildGlobalSettingsRulesets(variableSettings) + @buildScopeSelectorRulesets(settings) getStylesheet: -> lines = [ @@ -29,16 +44,14 @@ class TextMateTheme getSyntaxVariables: -> @syntaxVariables - buildSyntaxVariables: ({settings}) -> + buildSyntaxVariables: (settings) -> @syntaxVariables = SyntaxVariablesTemplate for key, value of settings replaceRegex = new RegExp("\\{\\{#{key}\\}\\}", 'g') @syntaxVariables = @syntaxVariables.replace(replaceRegex, @translateColor(value)) @syntaxVariables - buildGlobalSettingsRulesets: ({settings}) -> - {background, foreground, caret, selection, lineHighlight} = settings - + buildGlobalSettingsRulesets: (settings) -> @rulesets.push selector: '.editor' properties: @@ -101,7 +114,7 @@ class TextMateTheme @rulesets.push selector: '.editor.is-focused .line-number.cursor-line-no-selection, .editor.is-focused .line.cursor-line' properties: - 'background-color': @translateColor(lineHighlight) + 'background-color': @translateColor(settings.lineHighlight) buildScopeSelectorRulesets: (scopeSelectorSettings) -> for {name, scope, settings} in scopeSelectorSettings diff --git a/src/theme-converter.coffee b/src/theme-converter.coffee index 826ca2937..75e960c71 100644 --- a/src/theme-converter.coffee +++ b/src/theme-converter.coffee @@ -33,7 +33,11 @@ class ThemeConverter @readTheme (error, themeContents) => return callback(error) if error? - theme = new TextMateTheme(themeContents) + try + theme = new TextMateTheme(themeContents) + catch error + return callback(error) + fs.writeFileSync(path.join(@destinationPath, 'stylesheets', 'base.less'), theme.getStylesheet()) fs.writeFileSync(path.join(@destinationPath, 'stylesheets', 'syntax-variables.less'), theme.getSyntaxVariables()) callback() From bf474b202431be57eabd306d2abeb91da7bfa367 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 6 Mar 2014 13:57:02 -0800 Subject: [PATCH 2/6] Make invisibles required as well --- src/text-mate-theme.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/text-mate-theme.coffee b/src/text-mate-theme.coffee index f9211cbda..02cf29f3d 100644 --- a/src/text-mate-theme.coffee +++ b/src/text-mate-theme.coffee @@ -17,8 +17,8 @@ class TextMateTheme # Require all of these or invalid LESS will be generated if any required # variable value is missing - {background, foreground, caret, selection, lineHighlight} = setting.settings - if background and foreground and caret and selection and lineHighlight + {background, foreground, caret, selection, invisibles, lineHighlight} = setting.settings + if background and foreground and caret and selection and lineHighlight and invisibles variableSettings = setting.settings break From d4d0098f03cc4c627acd2a002a4162201d500a4e Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 6 Mar 2014 13:58:53 -0800 Subject: [PATCH 3/6] Default settings to empty array --- src/text-mate-theme.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/text-mate-theme.coffee b/src/text-mate-theme.coffee index 02cf29f3d..f5fa53d4b 100644 --- a/src/text-mate-theme.coffee +++ b/src/text-mate-theme.coffee @@ -9,7 +9,8 @@ class TextMateTheme @buildRulesets() buildRulesets: -> - {settings} = plist.parseStringSync(@contents) + {settings} = plist.parseStringSync(@contents) ? {} + settings ?= [] for setting in settings {scope, name} = setting.settings From 8d147872f0d2281f7a2b4fb7a5729775f249b4da Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 6 Mar 2014 14:07:09 -0800 Subject: [PATCH 4/6] Add longer error message when theme cannot be converted --- spec/init-spec.coffee | 13 ++++++++++++- src/text-mate-theme.coffee | 12 +++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/spec/init-spec.coffee b/spec/init-spec.coffee index 4ac4749c5..479d5d791 100644 --- a/spec/init-spec.coffee +++ b/spec/init-spec.coffee @@ -8,7 +8,7 @@ describe "apm init", -> [packagePath, themePath] = [] beforeEach -> - # silenceOutput() + silenceOutput() spyOnToken() currentDir = temp.mkdirSync('apm-init-') @@ -112,3 +112,14 @@ describe "apm init", -> expect(fs.existsSync(path.join(themePath, 'README.md'))).toBeTruthy() expect(fs.existsSync(path.join(themePath, 'package.json'))).toBeTruthy() expect(fs.existsSync(path.join(themePath, 'LICENSE.md'))).toBeFalsy() + + it "logs an error if it doesn't have all the required color settings", -> + callback = jasmine.createSpy('callback') + textMateThemePath = path.join(__dirname, 'fixtures', 'Bad.tmTheme') + apm.run(['init', '--theme', 'fake-theme', '--convert', textMateThemePath], callback) + + waitsFor 'waiting for init to complete', -> + callback.callCount is 1 + + runs -> + expect(callback.argsForCall[0][0].message.length).toBeGreaterThan 0 diff --git a/src/text-mate-theme.coffee b/src/text-mate-theme.coffee index f5fa53d4b..07fa2755e 100644 --- a/src/text-mate-theme.coffee +++ b/src/text-mate-theme.coffee @@ -24,7 +24,17 @@ class TextMateTheme break unless variableSettings? - throw new Error('Could not find color settings in theme to convert') + throw new Error """ + Could not find color settings in theme to convert. + + Theme must contain a settings array with all of the following keys: + * background + * caret + * foreground + * invisibles + * lineHighlight + * selection + """ @buildSyntaxVariables(variableSettings) @buildGlobalSettingsRulesets(variableSettings) From dd6fa3eedfa4c100afc1ef669e06dde76e1551d8 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 6 Mar 2014 14:07:30 -0800 Subject: [PATCH 5/6] Add invalid theme fixture --- spec/fixtures/Bad.tmTheme | 422 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 422 insertions(+) create mode 100644 spec/fixtures/Bad.tmTheme diff --git a/spec/fixtures/Bad.tmTheme b/spec/fixtures/Bad.tmTheme new file mode 100644 index 000000000..11e4f3c89 --- /dev/null +++ b/spec/fixtures/Bad.tmTheme @@ -0,0 +1,422 @@ + + + + + comment + Dawn + name + Dawn + settings + + + settings + + background + #F5F5F5 + caret + #000000 + foreground + #080808 + invisibles + #4B4B7E80 + selection + #7496CF4D + + + + name + Comment + scope + comment + settings + + fontStyle + italic + foreground + #5A525F + + + + name + Constant + scope + constant + settings + + fontStyle + bold + foreground + #811F24 + + + + name + Entity + scope + entity + settings + + fontStyle + + foreground + #BF4F24 + + + + name + Keyword + scope + keyword + settings + + fontStyle + + foreground + #794938 + + + + name + Storage + scope + storage + settings + + fontStyle + italic + foreground + #A71D5D + + + + name + String + scope + string | punctuation.definition.string + settings + + fontStyle + + foreground + #0B6125 + + + + name + Support + scope + support + settings + + fontStyle + + foreground + #691C97 + + + + name + Variable + scope + variable + settings + + fontStyle + + foreground + #234A97 + + + + name + Invalid – Deprecated + scope + invalid.deprecated + settings + + fontStyle + bold italic underline + foreground + #B52A1D + + + + name + Invalid – Illegal + scope + invalid.illegal + settings + + background + #B52A1D + fontStyle + italic underline + foreground + #F8F8F8 + + + + name + String embedded-source + scope + string source + settings + + background + #6F8BBA26 + fontStyle + + foreground + #080808 + + + + name + String constant + scope + string constant + settings + + fontStyle + bold + foreground + #696969 + + + + name + String variable + scope + string variable + settings + + fontStyle + + foreground + #234A97 + + + + name + String.regexp + scope + string.regexp + settings + + fontStyle + + foreground + #CF5628 + + + + name + String.regexp.«special» + scope + string.regexp.character-class, string.regexp constant.character.escaped, string.regexp source.ruby.embedded, string.regexp string.regexp.arbitrary-repitition + settings + + fontStyle + bold italic + foreground + #CF5628 + + + + name + String.regexp constant.character.escape + scope + string.regexp constant.character.escape + settings + + fontStyle + bold + foreground + #811F24 + + + + name + Embedded Source + scope + text source + settings + + background + #6F8BBA26 + + + + name + Support.function + scope + support.function + settings + + fontStyle + + foreground + #693A17 + + + + name + Support.constant + scope + support.constant + settings + + fontStyle + + foreground + #B4371F + + + + name + Support.variable + scope + support.variable + settings + + foreground + #234A97 + + + + name + Markup.list + scope + markup.list + settings + + foreground + #693A17 + + + + name + Markup.heading + scope + markup.heading | markup.heading entity.name + settings + + fontStyle + bold + foreground + #19356D + + + + name + Markup.quote + scope + markup.quote + settings + + background + #BBBBBB30 + fontStyle + italic + foreground + #0B6125 + + + + name + Markup.italic + scope + markup.italic + settings + + fontStyle + italic + foreground + #080808 + + + + name + Markup.bold + scope + markup.bold + settings + + fontStyle + bold + foreground + #080808 + + + + name + Markup.underline + scope + markup.underline + settings + + fontStyle + underline + foreground + #080808 + + + + name + Markup.link + scope + markup.link + settings + + fontStyle + italic underline + foreground + #234A97 + + + + name + Markup.raw + scope + markup.raw + settings + + background + #BBBBBB30 + fontStyle + + foreground + #234A97 + + + + name + Markup.deleted + scope + markup.deleted + settings + + foreground + #B52A1D + + + + name + Meta.seperator + scope + meta.separator + settings + + background + #DCDCDC + fontStyle + bold + foreground + #19356D + + + + uuid + E7E82498-F9EA-49A6-A0D8-12327EA46B01 + + From 933c6308ba999658e442156a6e0a702c4db2751a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 6 Mar 2014 14:18:55 -0800 Subject: [PATCH 6/6] Tweak error message --- src/text-mate-theme.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/text-mate-theme.coffee b/src/text-mate-theme.coffee index 07fa2755e..bdc99457b 100644 --- a/src/text-mate-theme.coffee +++ b/src/text-mate-theme.coffee @@ -25,9 +25,9 @@ class TextMateTheme unless variableSettings? throw new Error """ - Could not find color settings in theme to convert. + Could not find the required color settings in the theme. - Theme must contain a settings array with all of the following keys: + The theme being converted must contain a settings array with all of the following keys: * background * caret * foreground