tm2gsv 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f7271f4f8fc08149a0fb0d0efca7793ce31db8de
4
+ data.tar.gz: 54b13539538b6c8291e3c8b3b64f389bfceefcc9
5
+ SHA512:
6
+ metadata.gz: c8f92a463b346abc71a11d577e155180ab392e97a3370e0d94038201913d73234229d7185638e9944b4f9bc351a73ec27cbab86506d58e07eabdb0374e0cb39d
7
+ data.tar.gz: 2a9d3d4a6621428b61ca96b3e4e99e4ac416928cbe754f334375162d00a13d554491eaad428b70bf92eaa492408007dafc230440a9e61ca4ba38cedc6a445f56
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/CHANGELOG.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'http://rubygems.org'
2
+ # Add dependencies required to use your gem here.
3
+ gem 'thor', '~> 0.19'
4
+ gem 'json', '~> 1.8'
5
+ gem 'plist', '~> 3.1'
6
+ gem 'ox', '~> 2.2'
7
+ gem 'color', '~> 1.8'
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem 'rdoc', '~> 3.12'
13
+ gem 'bundler', '~> 1.0'
14
+ gem 'jeweler', '~> 2.0'
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.8)
5
+ builder (3.2.2)
6
+ color (1.8)
7
+ descendants_tracker (0.0.4)
8
+ thread_safe (~> 0.3, >= 0.3.1)
9
+ faraday (0.9.2)
10
+ multipart-post (>= 1.2, < 3)
11
+ git (1.2.9.1)
12
+ github_api (0.12.4)
13
+ addressable (~> 2.3)
14
+ descendants_tracker (~> 0.0.4)
15
+ faraday (~> 0.8, < 0.10)
16
+ hashie (>= 3.4)
17
+ multi_json (>= 1.7.5, < 2.0)
18
+ nokogiri (~> 1.6.6)
19
+ oauth2
20
+ hashie (3.4.3)
21
+ highline (1.7.8)
22
+ jeweler (2.0.1)
23
+ builder
24
+ bundler (>= 1.0)
25
+ git (>= 1.2.5)
26
+ github_api
27
+ highline (>= 1.6.15)
28
+ nokogiri (>= 1.5.10)
29
+ rake
30
+ rdoc
31
+ json (1.8.3)
32
+ jwt (1.5.2)
33
+ mini_portile (0.6.2)
34
+ multi_json (1.11.2)
35
+ multi_xml (0.5.5)
36
+ multipart-post (2.0.0)
37
+ nokogiri (1.6.6.2)
38
+ mini_portile (~> 0.6.0)
39
+ oauth2 (1.0.0)
40
+ faraday (>= 0.8, < 0.10)
41
+ jwt (~> 1.0)
42
+ multi_json (~> 1.3)
43
+ multi_xml (~> 0.5)
44
+ rack (~> 1.2)
45
+ ox (2.2.2)
46
+ plist (3.1.0)
47
+ rack (1.6.4)
48
+ rake (10.4.2)
49
+ rdoc (3.12.2)
50
+ json (~> 1.4)
51
+ thor (0.19.1)
52
+ thread_safe (0.3.5)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ bundler (~> 1.0)
59
+ color (~> 1.8)
60
+ jeweler (~> 2.0)
61
+ json (~> 1.8)
62
+ ox (~> 2.2)
63
+ plist (~> 3.1)
64
+ rdoc (~> 3.12)
65
+ thor (~> 0.19)
66
+
67
+ BUNDLED WITH
68
+ 1.10.6
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Hardpixel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ ## Tm2Gsv
2
+
3
+ Tm2Gsv is a command line tool that converts Text Mate themes and language bundles (WIP) to GTK Source View themes and language definitions.
4
+
5
+ [![Code Climate](https://codeclimate.com/github/hardpixel/tm2gsv/badges/gpa.svg)](https://codeclimate.com/github/hardpixel/tm2gsv)
6
+
7
+ ## Commands
8
+
9
+ tm2gsv help [COMMAND] # Describe available commands or one specific command
10
+ tm2gsv theme SOURCE DESTINATION # Convert TextMate theme(s) to GTK Source View color scheme(s)
11
+ tm2gsv language SOURCE DESTINATION # Convert TextMate language(s) to GTK Source View language(s)
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+
14
+ require 'rake'
15
+ require 'jeweler'
16
+
17
+ Jeweler::Tasks.new do |gem|
18
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
19
+ gem.name = "tm2gsv"
20
+ gem.executables = ["tm2gsv"]
21
+ gem.homepage = "http://hardpixel.github.io/tm2gsv"
22
+ gem.license = "MIT"
23
+ gem.summary = %Q{A command-line tool for developing wordpress themes and plugins}
24
+ gem.description = %Q{Convert TextMate color scgemes to GTK Source View color schemes.}
25
+ gem.email = "info@hardpixel.eu"
26
+ gem.authors = ["Jonian Guveli", "Olibia Tsati"]
27
+ # dependencies defined in Gemfile
28
+ gem.files.include Dir.glob('**/*')
29
+ end
30
+
31
+ Jeweler::RubygemsDotOrgTasks.new
32
+
33
+ require 'rdoc/task'
34
+
35
+ Rake::RDocTask.new do |rdoc|
36
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
37
+
38
+ rdoc.rdoc_dir = 'rdoc'
39
+ rdoc.title = "tm2gsv #{version}"
40
+ rdoc.rdoc_files.include('README*')
41
+ rdoc.rdoc_files.include('LICENSE*')
42
+ rdoc.rdoc_files.include('CHANGELOG*')
43
+ rdoc.rdoc_files.include('lib/**/*.rb')
44
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/tm2gsv ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ require 'rubygems'
5
+
6
+ file_path = Pathname.new(__FILE__).realpath
7
+ libdir = File.join(File.dirname(File.dirname(file_path)), "lib")
8
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
9
+
10
+ require 'tm2gsv'
11
+
12
+ Tm2Gsv::CLI.start
@@ -0,0 +1,58 @@
1
+ {
2
+ "text": {
3
+ "foreground": "foreground",
4
+ "background": "background"
5
+ },
6
+ "cursor": {
7
+ "foreground": "caret"
8
+ },
9
+ "selection": {
10
+ "foreground": "selectionForeground",
11
+ "background": "selection"
12
+ },
13
+ "line-numbers": {
14
+ "foreground": [
15
+ "gutterForeground",
16
+ "def:comment.foreground"
17
+ ],
18
+ "background": [
19
+ "gutter",
20
+ "def:comment.background",
21
+ "background"
22
+ ]
23
+ },
24
+ "current-line": {
25
+ "background": "lineHighlight"
26
+ },
27
+ "current-line-number": {
28
+ "background": "lineHighlight"
29
+ },
30
+ "bracket-match": {
31
+ "foreground": [
32
+ "bracketsForeground"
33
+ ],
34
+ "fontStyle": "bracketsOptions"
35
+ },
36
+ "bracket-mismatch": {
37
+ "foreground": [
38
+ "bracketContentsForeground",
39
+ "bracketsForeground"
40
+ ]
41
+ },
42
+ "search-match": {
43
+ "foreground": "findHighlightForeground",
44
+ "background": "findHighlight"
45
+ },
46
+ "draw-spaces": {
47
+ "foreground": "invisibles"
48
+ },
49
+ "background-pattern": {
50
+ "background": "lineHighlight"
51
+ },
52
+ "right-margin": {
53
+ "background": [
54
+ "guide",
55
+ "background"
56
+ ]
57
+ }
58
+ }
@@ -0,0 +1,330 @@
1
+ {
2
+ "def:comment": [
3
+ "comment",
4
+ "comment.line",
5
+ "comment.block"
6
+ ],
7
+ "def:shebang": [
8
+ "comment",
9
+ "comment.line",
10
+ "comment.block"
11
+ ],
12
+ "def:doc-comment": [
13
+ "comment",
14
+ "comment.line",
15
+ "comment.block"
16
+ ],
17
+ "def:doc-comment-element": [
18
+ "comment",
19
+ "comment.line",
20
+ "comment.block"
21
+ ],
22
+ "def:constant": [
23
+ "constant"
24
+ ],
25
+ "def:character": [
26
+ "constant.character",
27
+ "string"
28
+ ],
29
+ "def:string": [
30
+ "string",
31
+ "string.literal",
32
+ "string.quoted.literal",
33
+ "string.unquoted.heredoc string",
34
+ "string - string source"
35
+ ],
36
+ "def:special-char": [
37
+ "constant.character.escape",
38
+ "constant.character.escaped",
39
+ "string constant",
40
+ "support.constant"
41
+ ],
42
+ "def:number": [
43
+ "constant.numeric",
44
+ "constant.numeric.ruby"
45
+ ],
46
+ "def:floating-point": [
47
+ "constant.numeric.floating-point",
48
+ "constant.numeric",
49
+ "constant.numeric.ruby"
50
+ ],
51
+ "def:decimal": [
52
+ "constant.numeric.floating-point",
53
+ "constant.numeric",
54
+ "constant.numeric.ruby"
55
+ ],
56
+ "def:base-n-integer": [
57
+ "constant.numeric.integer.int32",
58
+ "constant.numeric.integer.int64",
59
+ "constant.numeric",
60
+ "constant.numeric.ruby"
61
+ ],
62
+ "def:complex": [
63
+ "constant.numeric",
64
+ "constant.numeric.ruby"
65
+ ],
66
+ "def:special-constant": [
67
+ "constant.language"
68
+ ],
69
+ "def:boolean": [
70
+ "constant.language"
71
+ ],
72
+ "def:identifier": [
73
+ "variable",
74
+ "variable.language",
75
+ "variable.other"
76
+ ],
77
+ "def:function": [
78
+ "entity.name.function"
79
+ ],
80
+ "def:builtin": [
81
+ "constant.language",
82
+ "support"
83
+ ],
84
+ "def:statement": [
85
+ "keyword"
86
+ ],
87
+ "def:operator": [
88
+ "keyword.operator"
89
+ ],
90
+ "def:keyword": [
91
+ "keyword.control",
92
+ "keyword",
93
+ "storage"
94
+ ],
95
+ "def:type": [
96
+ "support.type"
97
+ ],
98
+ "def:preprocessor": [
99
+ "support.constant",
100
+ "keyword.control.import"
101
+ ],
102
+ "def:error": [
103
+ "invalid.illegal"
104
+ ],
105
+ "def:reserved": [
106
+ "keyword"
107
+ ],
108
+ "def:note": [
109
+ "comment"
110
+ ],
111
+ "diff:location": [
112
+ "meta.diff.header"
113
+ ],
114
+ "diff:added-line": [
115
+ "markup.inserted"
116
+ ],
117
+ "diff:removed-line": [
118
+ "markup.deleted"
119
+ ],
120
+ "diff:changed-line": [
121
+ "markup.changed"
122
+ ],
123
+ "css:keyword": [
124
+ "support.type.property-name.css"
125
+ ],
126
+ "css:at-rules": [
127
+ "meta.preprocessor.at-rule",
128
+ "keyword.control.at-rule"
129
+ ],
130
+ "css:color": [
131
+ "constant.other.rgb-value.css"
132
+ ],
133
+ "xml:entity": [
134
+ "declaration.xml-processing"
135
+ ],
136
+ "xml:doctype": [
137
+ "declaration.doctype",
138
+ "meta.tag.sgml.doctype"
139
+ ],
140
+ "xml:namespace": [
141
+ "entity.name.tag.namespace"
142
+ ],
143
+ "xml:tag": [
144
+ "markup.tag",
145
+ "declaration.tag",
146
+ "entity.name.tag",
147
+ "entity.name.function"
148
+ ],
149
+ "xml:element-name": [
150
+ "entity.name.tag",
151
+ "markup.tag"
152
+ ],
153
+ "xml:attribute-name": [
154
+ "entity.other.attribute-name"
155
+ ],
156
+ "html:dtd": [
157
+ "string.quoted.docinfo.doctype.DTD",
158
+ "declaration.doctype.DTD"
159
+ ],
160
+ "html:tag": [
161
+ "markup.tag",
162
+ "declaration.tag",
163
+ "entity.name.tag",
164
+ "entity.name.function"
165
+ ],
166
+ "js:function": [
167
+ "support.function.js"
168
+ ],
169
+ "c:preprocessor": [
170
+ "meta.preprocessor.c"
171
+ ],
172
+ "php:string": [
173
+ "string.quoted.single.php",
174
+ "string.quoted.double.php"
175
+ ],
176
+ "ruby:attribute-definition": [
177
+ "variable.other.constant",
178
+ "keyword"
179
+ ],
180
+ "ruby:builtin": [
181
+ "variable.other.constant"
182
+ ],
183
+ "ruby:instance-variable": [
184
+ "variable",
185
+ "variable.language",
186
+ "variable.other"
187
+ ],
188
+ "ruby:global-variable": [
189
+ "entity.name.function"
190
+ ],
191
+ "ruby:class-variable": [
192
+ "variable",
193
+ "variable.language",
194
+ "variable.other"
195
+ ],
196
+ "ruby:special-variable": [
197
+ "keyword"
198
+ ],
199
+ "ruby:predefined-variable": [
200
+ "constant.language"
201
+ ],
202
+ "ruby:constant": [
203
+ "variable.other.constant",
204
+ "variable.other",
205
+ "constant"
206
+ ],
207
+ "ruby:symbol": [
208
+ "constant.other.symbol"
209
+ ],
210
+ "ruby:regex": [
211
+ "string.regexp"
212
+ ],
213
+ "ruby:module-handler": [
214
+ "keyword"
215
+ ],
216
+ "rubyonrails:attribute-definition": [
217
+ "variable.other.constant",
218
+ "keyword"
219
+ ],
220
+ "rubyonrails:builtin": [
221
+ "support",
222
+ "variable.other.constant"
223
+ ],
224
+ "rubyonrails:instance-variable": [
225
+ "variable",
226
+ "variable.language",
227
+ "variable.other"
228
+ ],
229
+ "rubyonrails:global-variable": [
230
+ "entity.name.function"
231
+ ],
232
+ "rubyonrails:class-variable": [
233
+ "variable",
234
+ "variable.language",
235
+ "variable.other"
236
+ ],
237
+ "rubyonrails:special-variable": [
238
+ "keyword"
239
+ ],
240
+ "rubyonrails:predefined-variable": [
241
+ "constant.language"
242
+ ],
243
+ "rubyonrails:constant": [
244
+ "variable.other.constant",
245
+ "variable.other",
246
+ "constant"
247
+ ],
248
+ "rubyonrails:symbol": [
249
+ "constant.other.symbol"
250
+ ],
251
+ "rubyonrails:regex": [
252
+ "string.regexp"
253
+ ],
254
+ "rubyonrails:module-handler": [
255
+ "keyword"
256
+ ],
257
+ "rubyonrails:module-name": [
258
+ "entity.name.module",
259
+ "support.class.ruby",
260
+ "entity.name.type"
261
+ ],
262
+ "rubyonrails:class-name": [
263
+ "support.class.ruby",
264
+ "entity.name.type",
265
+ "entity"
266
+ ],
267
+ "rubyonrails:class-inherit": [
268
+ "entity.other.inherited-class",
269
+ "support.class.ruby",
270
+ "entity.name.type"
271
+ ],
272
+ "rubyonrails:block-parameter": [
273
+ "variable.parameter.function"
274
+ ],
275
+ "rubyonrails:simple-interpolation": [
276
+ "string source",
277
+ "string.interpolated",
278
+ "source string source",
279
+ "constant.character.escaped"
280
+ ],
281
+ "rubyonrails:complex-interpolation": [
282
+ "string source",
283
+ "string.interpolated",
284
+ "source string source",
285
+ "constant.character.escaped"
286
+ ],
287
+ "rubyonrails:rails": [
288
+ "source.ruby.rails",
289
+ "variable.other.constant"
290
+ ],
291
+ "python:module-handler": [
292
+ "keyword"
293
+ ],
294
+ "python:special-variable": [
295
+ "keyword"
296
+ ],
297
+ "python:builtin-constant": [
298
+ "keyword"
299
+ ],
300
+ "python:builtin-object": [
301
+ "constant"
302
+ ],
303
+ "python:builtin-function": [
304
+ "entity.name.function",
305
+ "constant"
306
+ ],
307
+ "perl:type": [
308
+ "constant"
309
+ ],
310
+ "perl:line-directive": [
311
+ "constant"
312
+ ],
313
+ "perl:builtin": [
314
+ "entity.name.function"
315
+ ],
316
+ "perl:variable": [
317
+ "variable",
318
+ "variable.language",
319
+ "variable.other"
320
+ ],
321
+ "perl:special-variable": [
322
+ "variable.other.constant",
323
+ "constant.language",
324
+ "keyword"
325
+ ],
326
+ "perl:include-statement": [
327
+ "keyword.control.import",
328
+ "keyword"
329
+ ]
330
+ }
data/lib/tm2gsv.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'thor'
2
+ require 'tm2gsv/cli'
3
+ require 'tm2gsv/extensions'
4
+
5
+ module Tm2Gsv
6
+ def self.root
7
+ ::File.expand_path(::File.join(::File.dirname(__FILE__), '..'))
8
+ end
9
+ end
10
+
11
+ trap 'SIGINT' do
12
+ puts
13
+ puts
14
+ puts ::Time.now.strftime('%T') + ' - INFO - Bye bye...'
15
+ exit 130
16
+ end
data/lib/tm2gsv/cli.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'tm2gsv/theme'
2
+ require 'tm2gsv/language'
3
+
4
+ module Tm2Gsv
5
+ class CLI < Thor
6
+
7
+ # Convert theme definitions
8
+ desc "theme SOURCE DESTINATION", "Convert TextMate theme(s) to GTK Source View color scheme(s)"
9
+ long_desc "Converts a single file or all files in a folder"
10
+ def theme(source, destination=nil)
11
+ converter = Tm2Gsv::Theme.new(self)
12
+ converter.convert(source, destination)
13
+ end
14
+
15
+ # Convert language definitions
16
+ desc "language SOURCE DESTINATION", "Convert TextMate language(s) to GTK Source View language(s)"
17
+ long_desc "Converts a single file or all files in a folder"
18
+ def language(source, destination=nil)
19
+ Tm2Gsv::Language.new(self, source, destination)
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,72 @@
1
+ class Object
2
+ def blank?
3
+ false
4
+ end
5
+
6
+ def try(*args)
7
+ send(*args) if respond_to?(args.first)
8
+ end
9
+ end
10
+
11
+ class Hash
12
+ def except(keys=[])
13
+ keys = [keys].flatten
14
+ self.reject { |k,v| keys.include?(k) }
15
+ end
16
+ end
17
+
18
+ class String
19
+ def blank?
20
+ self.strip == ""
21
+ end
22
+
23
+ def color?
24
+ if self.include? '#' and self.size > 6
25
+ return true
26
+ end
27
+
28
+ return false
29
+ end
30
+
31
+ def color_with_alpha?
32
+ if self.include? '#' and self.size > 7
33
+ return true
34
+ end
35
+
36
+ return false
37
+ end
38
+
39
+ def to_hex_color
40
+ self[0..6]
41
+ end
42
+
43
+ def to_hex_alpha
44
+ (100 * ((self[7,8]).to_i(16) / 255.0)).round
45
+ end
46
+
47
+ def dasherize
48
+ self.downcase.gsub(/[^0-9A-Za-z]/, ' ').squeeze(' ').gsub(' ', '-').strip
49
+ end
50
+ end
51
+
52
+ class NilClass
53
+ def blank?
54
+ true
55
+ end
56
+
57
+ def dasherize
58
+ self
59
+ end
60
+ end
61
+
62
+ class FalseClass
63
+ def to_i
64
+ 0
65
+ end
66
+ end
67
+
68
+ class TrueClass
69
+ def to_i
70
+ 1
71
+ end
72
+ end
@@ -0,0 +1,7 @@
1
+ module Tm2Gsv
2
+ class Language
3
+ def initialize(task, source, destination)
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,56 @@
1
+ require 'tm2gsv/theme/parser'
2
+ require 'tm2gsv/theme/writer'
3
+
4
+ module Tm2Gsv
5
+ class Theme
6
+
7
+ def initialize(task)
8
+ @task = task || ::Thor.new()
9
+ end
10
+
11
+ def convert(source, destination)
12
+ @themes = []
13
+ @source = source
14
+ @destination = destination || default_path
15
+ @parser = Tm2Gsv::ThemeParser.new(@task)
16
+ @writer = Tm2Gsv::ThemeWriter.new(@task)
17
+
18
+ parse_files
19
+ write_files
20
+ end
21
+
22
+ private
23
+
24
+ def default_path
25
+ File.join(ENV['HOME'], '.local', 'share', 'gtksourceview-3.0', 'styles')
26
+ end
27
+
28
+ def parse_files
29
+ unless File.exist? @source
30
+ @task.say "Error: No such file or directory!", :red
31
+ exit(1)
32
+ end
33
+
34
+ @task.say "Searching for theme file(s).", :cyan
35
+ if File.directory? @source
36
+ Dir[File.join(@source, '**', '*.tmTheme')].each do |file|
37
+ theme = @parser.parse(file) rescue next
38
+ @themes << theme unless theme[:id].nil?
39
+ end
40
+ else
41
+ theme = @parser.parse(@source) rescue return
42
+ @themes << theme unless theme[:id].nil?
43
+ end
44
+ @task.say "Total found: #{@themes.count}", :green
45
+ end
46
+
47
+ def write_files
48
+ @task.say "Converting theme file(s).", :cyan
49
+ @themes.each do |theme|
50
+ @writer.write(theme, @destination) rescue next
51
+ end
52
+ @task.say "Total converted: #{@themes.count}", :green
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,98 @@
1
+ require 'json'
2
+ require 'plist'
3
+
4
+ module Tm2Gsv
5
+ class ThemeParser
6
+
7
+ def initialize(task)
8
+ @task = task || ::Thor.new()
9
+ end
10
+
11
+ def parse(file)
12
+ @hash = ::Plist::parse_xml(file)
13
+ @settings = @hash['settings']
14
+ @theme = { version: '1.0' }
15
+
16
+ # Get theme meta
17
+ @theme[:name] = @hash['name']
18
+ @theme[:id] = @hash['name'].dasherize
19
+ @theme[:settings] = {}
20
+ @theme[:styles] = {}
21
+
22
+ parse_styles
23
+ parse_scopes
24
+ parse_settings
25
+
26
+ return @theme
27
+ end
28
+
29
+ private
30
+
31
+ def parse_styles
32
+ @settings.drop(1).each do |style|
33
+ settings = style['settings'] || {}
34
+
35
+ settings['fontStyle'].to_s.split.each { |f| settings[f] = true }
36
+ settings.delete('fontStyle')
37
+
38
+ scopes = style['scope'].to_s.split(%r{,\s*})
39
+ scopes.each do |scope|
40
+ @theme[:styles][scope] = settings if settings.any?
41
+ end
42
+ end
43
+ end
44
+
45
+ def parse_scopes
46
+ data = load_data('styles.json')
47
+ styles = @theme[:styles]
48
+
49
+ @theme[:styles] = {}
50
+ data.each do |key, value|
51
+ style = styles.select { |k, v| value.include?(k) }
52
+ @theme[:styles][key] = style.values[0] if style.any?
53
+ end
54
+ end
55
+
56
+ def parse_settings
57
+ data = load_data('settings.json')
58
+
59
+ data.each do |name, opts|
60
+ @theme[:settings][name] = parse_setting(opts)
61
+ end
62
+ end
63
+
64
+ def parse_setting(opts)
65
+ settings = @settings.first['settings']
66
+ styles = @theme[:styles]
67
+ setting = {}
68
+
69
+ opts.each do |key, value|
70
+ value = [value].flatten.reverse
71
+ if key == 'fontStyle'
72
+ style = settings.select { |k, v| value.include? k }.values[0]
73
+ style.to_s.split.each { |i| setting[i] = true }
74
+ else
75
+ value.each do |item|
76
+ if item.include? '.'
77
+ item = item.split('.')
78
+ style = styles.select { |k, v| k == item[0] }
79
+ style = style[item[0]][item[1]] rescue nil
80
+ else
81
+ style = settings[item] rescue nil
82
+ end
83
+ setting[key] = style unless style.nil?
84
+ end
85
+ end
86
+ end
87
+
88
+ return setting
89
+ end
90
+
91
+ def load_data(file)
92
+ path = File.join(Tm2Gsv.root, 'data', 'theme', file)
93
+ json = File.read File.expand_path(path)
94
+ return ::JSON.parse(json)
95
+ end
96
+
97
+ end
98
+ end
@@ -0,0 +1,86 @@
1
+ require 'ox'
2
+ require 'color'
3
+
4
+ module Tm2Gsv
5
+ class ThemeWriter
6
+
7
+ def initialize(task)
8
+ @task = task || ::Thor.new()
9
+ end
10
+
11
+ def write(theme, destination)
12
+ @theme = theme
13
+ @destination = destination
14
+ @file = File.join(@destination, "#{@theme[:id]}.xml")
15
+
16
+ create_doc
17
+ create_scheme
18
+
19
+ create_styles(@theme[:settings])
20
+ create_styles(@theme[:styles])
21
+
22
+ write_file
23
+
24
+ return @file
25
+ end
26
+
27
+ private
28
+
29
+ def create_doc
30
+ @doc = ::Ox::Document.new(version: '1.0', encoding: 'UTF-8')
31
+ end
32
+
33
+ def create_scheme
34
+ @scheme = ::Ox::Element.new('style-scheme')
35
+ @scheme[:id] = @theme[:id]
36
+ @scheme[:_name] = @theme[:name]
37
+ @scheme[:version] = @theme[:version]
38
+ @doc << @scheme
39
+
40
+ author = ::Ox::Element.new('author')
41
+ author << 'TM2GSV'
42
+ @scheme << author
43
+
44
+ desc = ::Ox::Element.new('description')
45
+ desc << 'A GTKSourceView color scheme converted with TM2GSV.'
46
+ @scheme << desc
47
+ end
48
+
49
+ def create_styles(styles)
50
+ styles.each do |key, value|
51
+ next if value.empty?
52
+
53
+ elem = ::Ox::Element.new('style')
54
+ elem[:name] = key
55
+ value.each do |k, v|
56
+ next if v.nil?
57
+ if v.to_s.color?
58
+ elem[k] = normalize_color(v)
59
+ else
60
+ elem[k] = v
61
+ end
62
+ end
63
+
64
+ @scheme << elem
65
+ end
66
+ end
67
+
68
+ def write_file
69
+ ::Ox.default_options = { with_xml: true }
70
+ ::Ox.to_file @file, @doc
71
+ end
72
+
73
+ def normalize_color(value)
74
+ bg = @theme[:settings]['text']['background']
75
+
76
+ if value.color_with_alpha?
77
+ bg = ::Color::RGB.from_html(bg.to_hex_color)
78
+ color = ::Color::RGB.from_html(value.to_hex_color)
79
+ return color.mix_with(bg, value.to_hex_alpha).html
80
+ else
81
+ return ::Color::RGB.from_html(value).html
82
+ end
83
+ end
84
+
85
+ end
86
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tm2gsv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonian Guveli
8
+ - Olibia Tsati
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-11-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.19'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.19'
28
+ - !ruby/object:Gem::Dependency
29
+ name: json
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.8'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.8'
42
+ - !ruby/object:Gem::Dependency
43
+ name: plist
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.1'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.1'
56
+ - !ruby/object:Gem::Dependency
57
+ name: ox
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.2'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.2'
70
+ - !ruby/object:Gem::Dependency
71
+ name: color
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.8'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.8'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rdoc
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.12'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.12'
98
+ - !ruby/object:Gem::Dependency
99
+ name: bundler
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '1.0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: jeweler
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '2.0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '2.0'
126
+ description: Convert TextMate color scgemes to GTK Source View color schemes.
127
+ email: info@hardpixel.eu
128
+ executables:
129
+ - tm2gsv
130
+ extensions: []
131
+ extra_rdoc_files:
132
+ - LICENSE.txt
133
+ - README.md
134
+ files:
135
+ - ".document"
136
+ - CHANGELOG.md
137
+ - Gemfile
138
+ - Gemfile.lock
139
+ - LICENSE.txt
140
+ - README.md
141
+ - Rakefile
142
+ - VERSION
143
+ - bin/tm2gsv
144
+ - data/theme/settings.json
145
+ - data/theme/styles.json
146
+ - lib/tm2gsv.rb
147
+ - lib/tm2gsv/cli.rb
148
+ - lib/tm2gsv/extensions.rb
149
+ - lib/tm2gsv/language.rb
150
+ - lib/tm2gsv/theme.rb
151
+ - lib/tm2gsv/theme/parser.rb
152
+ - lib/tm2gsv/theme/writer.rb
153
+ homepage: http://hardpixel.github.io/tm2gsv
154
+ licenses:
155
+ - MIT
156
+ metadata: {}
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 2.4.5.1
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: A command-line tool for developing wordpress themes and plugins
177
+ test_files: []
178
+ has_rdoc: