coloration 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,34 @@
1
1
  module Coloration
2
+
2
3
  module Converters
4
+
3
5
  class Textmate2JEditConverter < AbstractConverter
4
- @in_theme_type = "Textmate"
5
- @in_theme_ext = "tmTheme"
6
- @out_theme_type = "JEdit"
7
- @out_theme_ext = "jedit-scheme"
6
+
8
7
  include Readers::TextMateThemeReader
9
8
  include Writers::JEditThemeWriter
10
- end
11
- end
12
- end
9
+
10
+ # @return [String]
11
+ def in_theme_type
12
+ 'Textmate'
13
+ end
14
+
15
+ # @return [String]
16
+ def in_theme_ext
17
+ 'tmTheme'
18
+ end
19
+
20
+ # @return [String]
21
+ def out_theme_type
22
+ 'JEdit'
23
+ end
24
+
25
+ # @return [String]
26
+ def out_theme_ext
27
+ 'jedit-scheme'
28
+ end
29
+
30
+ end # Textmate2JEditConverter
31
+
32
+ end # Converters
33
+
34
+ end # Coloration
@@ -1,12 +1,34 @@
1
1
  module Coloration
2
+
2
3
  module Converters
4
+
3
5
  class Textmate2KatePartConverter < AbstractConverter
4
- @in_theme_type = "Textmate"
5
- @in_theme_ext = "tmTheme"
6
- @out_theme_type = "KatePart"
7
- @out_theme_ext = "txt"
6
+
8
7
  include Readers::TextMateThemeReader
9
8
  include Writers::KatePartThemeWriter
10
- end
11
- end
12
- end
9
+
10
+ # @return [String]
11
+ def in_theme_type
12
+ 'Textmate'
13
+ end
14
+
15
+ # @return [String]
16
+ def in_theme_ext
17
+ 'tmTheme'
18
+ end
19
+
20
+ # @return [String]
21
+ def out_theme_type
22
+ 'KatePart'
23
+ end
24
+
25
+ # @return [String]
26
+ def out_theme_ext
27
+ 'txt'
28
+ end
29
+
30
+ end # Textmate2KatePartConverter
31
+
32
+ end # Converters
33
+
34
+ end # Coloration
@@ -1,12 +1,34 @@
1
1
  module Coloration
2
+
2
3
  module Converters
4
+
3
5
  class Textmate2VimConverter < AbstractConverter
4
- @in_theme_type = "Textmate"
5
- @in_theme_ext = "tmTheme"
6
- @out_theme_type = "Vim"
7
- @out_theme_ext = "vim"
6
+
8
7
  include Readers::TextMateThemeReader
9
8
  include Writers::VimThemeWriter
10
- end
11
- end
12
- end
9
+
10
+ # @return [String]
11
+ def in_theme_type
12
+ 'Textmate'
13
+ end
14
+
15
+ # @return [String]
16
+ def in_theme_ext
17
+ 'tmTheme'
18
+ end
19
+
20
+ # @return [String]
21
+ def out_theme_type
22
+ 'Vim'
23
+ end
24
+
25
+ # @return [String]
26
+ def out_theme_ext
27
+ 'vim'
28
+ end
29
+
30
+ end # Textmate2VimConverter
31
+
32
+ end # Converters
33
+
34
+ end # Colorationnd
@@ -1,9 +1,11 @@
1
1
  require 'plist'
2
- require 'textpow'
3
2
 
4
3
  module Coloration
4
+
5
5
  module Readers
6
+
6
7
  module TextMateThemeReader
8
+
7
9
  class InvalidThemeError < RuntimeError; end
8
10
 
9
11
  def parse_input
@@ -49,31 +51,9 @@ module Coloration
49
51
  end
50
52
  self.items = ItemsLookup.new(items)
51
53
  end
52
- end
53
54
 
54
- class ItemsLookup
55
- def initialize(items)
56
- @items = items
57
- @score_manager = Textpow::ScoreManager.new
58
- end
55
+ end # TextMateThemeReader
59
56
 
60
- def [](keys)
61
- keys.split(",").each do |key|
62
- best_selector = nil
63
- best_score = 0
64
- @items.keys.each do |selector|
65
- score = @score_manager.score(selector, key)
66
- if score > best_score
67
- best_score, best_selector = score, selector
68
- end
69
- end
70
- if best_selector
71
- return @items[best_selector]
72
- end
73
- end
74
- nil
75
- end
76
- end
77
- end
57
+ end # Readers
78
58
 
79
- end
59
+ end # Coloration
@@ -1,6 +1,7 @@
1
1
  module Coloration
2
2
 
3
3
  class Style
4
+
4
5
  attr_accessor :foreground, :background, :bold, :italic, :underline, :strike, :inverse, :comment
5
6
 
6
7
  def initialize(obj=nil, bg=nil)
@@ -32,6 +33,7 @@ module Coloration
32
33
  def blank?
33
34
  foreground.nil? && background.nil?
34
35
  end
35
- end
36
36
 
37
- end
37
+ end # Style
38
+
39
+ end # Coloration
@@ -0,0 +1,42 @@
1
+ require 'textpow'
2
+
3
+ module Coloration
4
+
5
+ module Readers
6
+
7
+ class ItemsLookup
8
+
9
+ def initialize(items)
10
+ @items = items
11
+ end
12
+
13
+ def [](keys)
14
+ keys.split(",").each do |key|
15
+ best_selector = nil
16
+ best_score = 0
17
+
18
+ @items.keys.each do |selector|
19
+ score = score_manager.score(selector, key)
20
+ if score > best_score
21
+ best_score, best_selector = score, selector
22
+ end
23
+ end
24
+
25
+ return @items[best_selector] if best_selector
26
+ end
27
+
28
+ nil
29
+ end
30
+
31
+ private
32
+
33
+ # @return [Textpow::ScoreManager]
34
+ def score_manager
35
+ @score_manager ||= Textpow::ScoreManager.new
36
+ end
37
+
38
+ end # ItemsLookup
39
+
40
+ end # Readers
41
+
42
+ end # Coloration
@@ -1,3 +1,3 @@
1
1
  module Coloration
2
- VERSION = "0.3.3".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
@@ -0,0 +1,27 @@
1
+ module Coloration
2
+
3
+ module Writers
4
+
5
+ module AbstractWriter
6
+
7
+ # @param line [String]
8
+ # @return [Array<String>]
9
+ def add_line(line = '')
10
+ (@lines ||= []) << line
11
+ end
12
+
13
+ # @param name [String]
14
+ # @param style [String]
15
+ # @raise RuntimeError
16
+ # @return [String]
17
+ def format_item(name, style)
18
+ raise RuntimeError, "Style for #{name} is missing!" unless style
19
+
20
+ "#{name}=#{format_style(style)}"
21
+ end
22
+
23
+ end # AbstractWriter
24
+
25
+ end # Writers
26
+
27
+ end # Coloration
@@ -1,9 +1,13 @@
1
1
  module Coloration
2
+
2
3
  module Writers
4
+
3
5
  module JEditThemeWriter
4
6
 
7
+ include Coloration::Writers::AbstractWriter
8
+
5
9
  def build_result
6
- add_line(format_comment(comment_text))
10
+ add_line(format_comment(comment_message))
7
11
  add_line
8
12
 
9
13
  ui_mapping = {
@@ -32,10 +36,10 @@ module Coloration
32
36
  "view.style.operator" => @items["keyword.operator"], # = < + -
33
37
  "view.style.function" => @items["entity.name.function"], # def foo
34
38
  "view.style.literal3" => @items["string.regexp"], # /jola/
35
- # "view.style.invalid" => @items["invalid"], # errors etc
36
- #"view.style.literal4" => :constant # MyClass, USER_SPACE
39
+ # "view.style.invalid" => @items["invalid"], # errors etc
40
+ # "view.style.literal4" => :constant # MyClass, USER_SPACE
37
41
  "view.style.markup" => @items["meta.tag"] || @items["entity.name.tag"] # <div>
38
- #TODO: gutter etc
42
+ # TODO: gutter etc
39
43
  }
40
44
 
41
45
  default_style = Style.new
@@ -49,10 +53,6 @@ module Coloration
49
53
 
50
54
  protected
51
55
 
52
- def add_line(line="")
53
- (@lines ||= []) << line
54
- end
55
-
56
56
  def escape(value)
57
57
  value.gsub(':', '\:').gsub('#', '\#').strip
58
58
  end
@@ -67,11 +67,6 @@ module Coloration
67
67
  "#{name}=#{escape(value)}"
68
68
  end
69
69
 
70
- def format_item(name, style)
71
- raise RuntimeError.new("Style for #{name} is missing!") if style.nil?
72
- "#{name}=#{format_style(style)}"
73
- end
74
-
75
70
  def format_style(style)
76
71
  s = ""
77
72
  s << " color:#{style.foreground.html}" if style.foreground
@@ -89,6 +84,8 @@ module Coloration
89
84
  "\# #{text}"
90
85
  end
91
86
 
92
- end
93
- end
94
- end
87
+ end # JEditThemeWriter
88
+
89
+ end # Writers
90
+
91
+ end # Coloration
@@ -1,9 +1,13 @@
1
1
  module Coloration
2
+
2
3
  module Writers
4
+
3
5
  module KatePartThemeWriter
4
6
 
7
+ include Coloration::Writers::AbstractWriter
8
+
5
9
  def build_result
6
- add_comment comment_text
10
+ add_comment comment_message
7
11
  add_comment "-" * 20 + " Put following in katesyntaxhighlightingrc " + "-" * 20
8
12
  add_line
9
13
 
@@ -90,21 +94,21 @@ module Coloration
90
94
  "Color Background" => @ui["background"],
91
95
  "Color Highlighted Bracket" => @ui["background"],
92
96
  "Color Highlighted Line" => @ui["lineHighlight"],
93
- # "Color Icon Bar" => @ui[:background],
94
- # "Color Line Number" => :,
95
- # "Color MarkType1" => :,
96
- # "Color MarkType2" => :,
97
- # "Color MarkType3" => :,
98
- # "Color MarkType4" => :,
99
- # "Color MarkType5" => :,
100
- # "Color MarkType6" => :,
101
- # "Color MarkType7" => :,
97
+ # "Color Icon Bar" => @ui[:background],
98
+ # "Color Line Number" => :,
99
+ # "Color MarkType1" => :,
100
+ # "Color MarkType2" => :,
101
+ # "Color MarkType3" => :,
102
+ # "Color MarkType4" => :,
103
+ # "Color MarkType5" => :,
104
+ # "Color MarkType6" => :,
105
+ # "Color MarkType7" => :,
102
106
  "Color Selection" => @ui["selection"],
103
107
  "Color Tab Marker" => @ui["invisibles"],
104
- # "Color Template Background" => :,
105
- # "Color Template Editable Placeholder" => :,
106
- # "Color Template Focused Editable Placeholder" => :,
107
- # "Color Template Not Editable Placeholder" => :,
108
+ # "Color Template Background" => :,
109
+ # "Color Template Editable Placeholder" => :,
110
+ # "Color Template Focused Editable Placeholder" => :,
111
+ # "Color Template Not Editable Placeholder" => :,
108
112
  "Color Word Wrap Marker" => @ui["invisibles"]
109
113
  }
110
114
  ui_mapping.keys.each do |key|
@@ -120,10 +124,6 @@ module Coloration
120
124
  add_line(format_comment(c))
121
125
  end
122
126
 
123
- def add_line(line="")
124
- (@lines ||= []) << line
125
- end
126
-
127
127
  def format_style(style)
128
128
  style ||= @default_style
129
129
  # normal,selected,bold,italic,strike,underline,bg,bg_selected,---
@@ -140,11 +140,6 @@ module Coloration
140
140
  s.join(",")
141
141
  end
142
142
 
143
- def format_item(name, style)
144
- raise RuntimeError.new("Style for #{name} is missing!") if style.nil?
145
- "#{name}=#{format_style(style)}"
146
- end
147
-
148
143
  def format_comment(text)
149
144
  "# #{text}"
150
145
  end
@@ -153,6 +148,8 @@ module Coloration
153
148
  "#{(col.r*255).to_i},#{(col.g*255).to_i},#{(col.b*255).to_i}"
154
149
  end
155
150
 
156
- end
157
- end
158
- end
151
+ end # KatePartThemeWriter
152
+
153
+ end # Writers
154
+
155
+ end # Coloration
@@ -1,6 +1,11 @@
1
1
  module Coloration
2
+
2
3
  module Writers
4
+
3
5
  module VimThemeWriter
6
+
7
+ include Coloration::Writers::AbstractWriter
8
+
4
9
  XTERM_COLORS = [ 0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF ]
5
10
  XTERM_GREYS = [ 0x08, 0x12, 0x1C, 0x26, 0x30, 0x3A,
6
11
  0x44, 0x4E, 0x58, 0x62, 0x6C, 0x76,
@@ -9,7 +14,7 @@ module Coloration
9
14
 
10
15
  def build_result
11
16
  add_line "\" Vim color file"
12
- add_line "\" #{comment_text}"
17
+ add_line "\" #{comment_message}"
13
18
  add_line
14
19
 
15
20
  add_line "set background=dark"
@@ -66,111 +71,111 @@ module Coloration
66
71
 
67
72
  items_mapping = {
68
73
  # general colors for all languages
69
- "Normal" => Style.new(:fg => @ui["foreground"], :bg => @ui["background"]),
70
- "Boolean" => "constant.language",
71
- "Character" => "constant.character",
72
- "Comment" => "comment",
74
+ "Normal" => Style.new(:fg => @ui["foreground"], :bg => @ui["background"]),
75
+ "Boolean" => "constant.language",
76
+ "Character" => "constant.character",
77
+ "Comment" => "comment",
73
78
  "Conditional" => "keyword.control",
74
- "Constant" => "constant",
75
- #"Debug" => [],
76
- "Define" => "keyword",
77
- #"Delimiter" => "meta.separator",
78
- "DiffAdd" => Style.new(:bg => green.mix_with(@ui['background'], 80), :fg => @ui['foreground'], :bold => true),
79
- "DiffDelete" => Style.new(:fg => red.mix_with(@ui['background'], 80)),
80
- "DiffChange" => Style.new(:bg => blue.mix_with(@ui['background'], 50), :fg => @ui['foreground']),
81
- "DiffText" => Style.new(:bg => blue.mix_with(@ui['background'], 100), :fg => @ui['foreground'], :bold => true),
82
- "ErrorMsg" => "invalid",
83
- "WarningMsg" => "invalid",
84
- #"Exception" => [],
85
- "Float" => "constant.numeric",
86
- "Function" => "entity.name.function",
87
- "Identifier" => "storage.type",
88
- #"Include" => [],
89
- "Keyword" => "keyword",
90
- "Label" => "string.other",
91
- #"Macro" => [],
92
- "NonText" => Style.new(:fg => @ui["invisibles"], :bg => @ui["background"].mix_with(@ui["foreground"], 95)),
93
- "Number" => "constant.numeric",
94
- "Operator" => "keyword.operator",
95
- #"PreCondit" => [],
96
- "PreProc" => "keyword.other",
97
- #"Repeat" => [],
98
- "Special" => Style.new(:fg => @ui["foreground"]),
99
- #"SpecialChar" => [],
100
- #"SpecialComment" => [],
101
- "SpecialKey" => Style.new(:fg => @ui["invisibles"], :bg => bg_line_color),
102
- "Statement" => "keyword.control",
79
+ "Constant" => "constant",
80
+ # "Debug" => [],
81
+ "Define" => "keyword",
82
+ # "Delimiter" => "meta.separator",
83
+ "DiffAdd" => Style.new(:bg => green.mix_with(@ui['background'], 80), :fg => @ui['foreground'], :bold => true),
84
+ "DiffDelete" => Style.new(:fg => red.mix_with(@ui['background'], 80)),
85
+ "DiffChange" => Style.new(:bg => blue.mix_with(@ui['background'], 50), :fg => @ui['foreground']),
86
+ "DiffText" => Style.new(:bg => blue.mix_with(@ui['background'], 100), :fg => @ui['foreground'], :bold => true),
87
+ "ErrorMsg" => "invalid",
88
+ "WarningMsg" => "invalid",
89
+ # "Exception" => [],
90
+ "Float" => "constant.numeric",
91
+ "Function" => "entity.name.function",
92
+ "Identifier" => "storage.type",
93
+ # "Include" => [],
94
+ "Keyword" => "keyword",
95
+ "Label" => "string.other",
96
+ # "Macro" => [],
97
+ "NonText" => Style.new(:fg => @ui["invisibles"], :bg => @ui["background"].mix_with(@ui["foreground"], 95)),
98
+ "Number" => "constant.numeric",
99
+ "Operator" => "keyword.operator",
100
+ # "PreCondit" => [],
101
+ "PreProc" => "keyword.other",
102
+ # "Repeat" => [],
103
+ "Special" => Style.new(:fg => @ui["foreground"]),
104
+ # "SpecialChar" => [],
105
+ # "SpecialComment" => [],
106
+ "SpecialKey" => Style.new(:fg => @ui["invisibles"], :bg => bg_line_color),
107
+ "Statement" => "keyword.control",
103
108
  "StorageClass" => "storage.type",
104
- "String" => "string,string.quoted",
105
- #"Structure" => [],
106
- "Tag" => "entity.name.tag",
107
- "Title" => Style.new(:fg => @ui["foreground"], :bold => true),
108
- "Todo" => (@items["comment"] || default_style).clone.tap { |c| c.inverse = true; c.bold = true },
109
- "Type" => "entity.name.type",
110
- #"Typedef" => [],
111
- "Underlined" => Style.new(:underline => true),
109
+ "String" => "string,string.quoted",
110
+ # "Structure" => [],
111
+ "Tag" => "entity.name.tag",
112
+ "Title" => Style.new(:fg => @ui["foreground"], :bold => true),
113
+ "Todo" => (@items["comment"] || default_style).clone.tap { |c| c.inverse = true; c.bold = true },
114
+ "Type" => "entity.name.type",
115
+ # "Typedef" => [],
116
+ "Underlined" => Style.new(:underline => true),
112
117
 
113
118
  # ruby
114
- "rubyClass" => "keyword.controll.class.ruby",
115
- "rubyFunction" => "entity.name.function.ruby",
119
+ "rubyClass" => "keyword.controll.class.ruby",
120
+ "rubyFunction" => "entity.name.function.ruby",
116
121
  "rubyInterpolationDelimiter" => "",
117
- "rubySymbol" => "constant.other.symbol.ruby",
118
- "rubyConstant" => "support.class",
119
- "rubyStringDelimiter" => "string,string.quoted",
120
- "rubyBlockParameter" => "variable.parameter",
121
- "rubyInstanceVariable" => "variable.language",
122
- "rubyInclude" => "keyword.other.special-method.ruby",
123
- "rubyGlobalVariable" => "variable.other",
124
- "rubyRegexp" => "string.regexp",
125
- "rubyRegexpDelimiter" => "string.regexp",
126
- "rubyEscape" => "constant.character.escape",
127
- "rubyControl" => "keyword.control",
128
- "rubyClassVariable" => "variable",
129
- "rubyOperator" => "keyword.operator",
130
- "rubyException" => "keyword.other.special-method.ruby",
131
- "rubyPseudoVariable" => "variable.language.ruby",
122
+ "rubySymbol" => "constant.other.symbol.ruby",
123
+ "rubyConstant" => "support.class",
124
+ "rubyStringDelimiter" => "string,string.quoted",
125
+ "rubyBlockParameter" => "variable.parameter",
126
+ "rubyInstanceVariable" => "variable.language",
127
+ "rubyInclude" => "keyword.other.special-method.ruby",
128
+ "rubyGlobalVariable" => "variable.other",
129
+ "rubyRegexp" => "string.regexp",
130
+ "rubyRegexpDelimiter" => "string.regexp",
131
+ "rubyEscape" => "constant.character.escape",
132
+ "rubyControl" => "keyword.control",
133
+ "rubyClassVariable" => "variable",
134
+ "rubyOperator" => "keyword.operator",
135
+ "rubyException" => "keyword.other.special-method.ruby",
136
+ "rubyPseudoVariable" => "variable.language.ruby",
132
137
 
133
138
  # rails
134
- "rubyRailsUserClass" => "support.class.ruby",
139
+ "rubyRailsUserClass" => "support.class.ruby",
135
140
  "rubyRailsARAssociationMethod" => "support.function.activerecord.rails",
136
- "rubyRailsARMethod" => "support.function.activerecord.rails",
137
- "rubyRailsRenderMethod" => "support.function",
138
- "rubyRailsMethod" => "support.function",
141
+ "rubyRailsARMethod" => "support.function.activerecord.rails",
142
+ "rubyRailsRenderMethod" => "support.function",
143
+ "rubyRailsMethod" => "support.function",
139
144
 
140
145
  # eruby
141
- "erubyDelimiter" => "punctuation.section.embedded.ruby",
142
- "erubyComment" => "comment",
146
+ "erubyDelimiter" => "punctuation.section.embedded.ruby",
147
+ "erubyComment" => "comment",
143
148
  "erubyRailsMethod" => "support.function",
144
- #"erubyExpression" => "text.html.ruby source",
145
- #"erubyDelimiter" => "",
149
+ # "erubyExpression" => "text.html.ruby source",
150
+ # "erubyDelimiter" => "",
146
151
 
147
152
  # html
148
- "htmlTag" => "meta.tag entity",
149
- "htmlEndTag" => "meta.tag entity",
150
- "htmlTagName" => "meta.tag entity",
151
- "htmlArg" => "meta.tag entity",
153
+ "htmlTag" => "meta.tag entity",
154
+ "htmlEndTag" => "meta.tag entity",
155
+ "htmlTagName" => "meta.tag entity",
156
+ "htmlArg" => "meta.tag entity",
152
157
  "htmlSpecialChar" => "constant.character.entity.html",
153
158
 
154
159
  # javascript
155
- "javaScriptFunction" => "storage.type.function.js",
160
+ "javaScriptFunction" => "storage.type.function.js",
156
161
  "javaScriptRailsFunction" => "support.function",
157
- "javaScriptBraces" => "meta.brace.curly.js",
162
+ "javaScriptBraces" => "meta.brace.curly.js",
158
163
 
159
164
  # yaml
160
- "yamlKey" => "entity.name.tag.yaml",
161
- "yamlAnchor" => "variable.other.yaml",
162
- "yamlAlias" => "variable.other.yaml",
165
+ "yamlKey" => "entity.name.tag.yaml",
166
+ "yamlAnchor" => "variable.other.yaml",
167
+ "yamlAlias" => "variable.other.yaml",
163
168
  "yamlDocumentHeader" => "string.unquoted.yaml",
164
169
 
165
170
  # css
166
- "cssURL" => "variable.parameter.misc.css",
167
- "cssFunctionName" => "support.function.misc.css",
168
- "cssColor" => "constant.other.color.rgb-value.css",
171
+ "cssURL" => "variable.parameter.misc.css",
172
+ "cssFunctionName" => "support.function.misc.css",
173
+ "cssColor" => "constant.other.color.rgb-value.css",
169
174
  "cssPseudoClassId" => "entity.other.attribute-name.pseudo-class.css",
170
- "cssClassName" => "entity.other.attribute-name.class.css",
171
- "cssValueLength" => "constant.numeric.css",
172
- "cssCommonAttr" => "support.constant.property-value.css",
173
- "cssBraces" => "punctuation.section.property-list.css",
175
+ "cssClassName" => "entity.other.attribute-name.class.css",
176
+ "cssValueLength" => "constant.numeric.css",
177
+ "cssCommonAttr" => "support.constant.property-value.css",
178
+ "cssBraces" => "punctuation.section.property-list.css",
174
179
  }
175
180
 
176
181
  items_mapping.keys.each do |key|
@@ -182,12 +187,9 @@ module Coloration
182
187
 
183
188
  protected
184
189
 
185
- def add_line(line="")
186
- (@lines ||= []) << line
187
- end
188
-
189
190
  def format_item(name, style_or_item_name)
190
- raise RuntimeError.new("Style for #{name} is missing!") if style_or_item_name.nil?
191
+ raise RuntimeError, "Style for #{name} is missing!" if style_or_item_name.nil?
192
+
191
193
  if style_or_item_name == :inverse
192
194
  "hi #{name} gui=inverse"
193
195
  else
@@ -277,6 +279,9 @@ module Coloration
277
279
 
278
280
  colors.last
279
281
  end
280
- end
281
- end
282
- end
282
+
283
+ end # VimThemeWriter
284
+
285
+ end # Writers
286
+
287
+ end # Coloration