rubymine2xcode-theme 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,59 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+
13
+ # Ignore all logfiles and tempfiles.
14
+ /log/*.log
15
+ /tmp
16
+
17
+ # mac noise:
18
+ .DS_Store
19
+
20
+ # rubymine:
21
+ .idea/
22
+
23
+ store/
24
+ .sass-cache/
25
+ stuff/
26
+
27
+
28
+
29
+ # xcode noise
30
+ *.mode1v3
31
+ *.pbxuser
32
+ *.perspective
33
+ *.perspectivev3
34
+ *.swp
35
+ *~.nib
36
+ build/
37
+ *.pbxuser
38
+ *.pyc
39
+ xcuserdata/
40
+
41
+
42
+ # bundler gem's .gitignore file:
43
+ *.gem
44
+ *.rbc
45
+ .bundle
46
+ .config
47
+ .yardoc
48
+ Gemfile.lock
49
+ InstalledFiles
50
+ _yardoc
51
+ coverage
52
+ doc/
53
+ lib/bundler/man
54
+ pkg
55
+ rdoc
56
+ spec/reports
57
+ test/tmp
58
+ test/version_tmp
59
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubymine2xcode-theme.gemspec
4
+ gemspec
5
+
6
+
7
+ gem 'plist'
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubymine2xcode-theme (0.0.1)
5
+ plist
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.1.3)
11
+ plist (3.1.0)
12
+ rspec (2.9.0)
13
+ rspec-core (~> 2.9.0)
14
+ rspec-expectations (~> 2.9.0)
15
+ rspec-mocks (~> 2.9.0)
16
+ rspec-core (2.9.0)
17
+ rspec-expectations (2.9.0)
18
+ diff-lcs (~> 1.1.3)
19
+ rspec-mocks (2.9.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ plist
26
+ rspec
27
+ rubymine2xcode-theme!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Matt Connolly
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Rubymine2xcode::Theme
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rubymine2xcode-theme'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rubymine2xcode-theme
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+
9
+ require 'rubymine2xcode-theme'
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # rubymine2xcode
4
+ #
5
+ # This program converts a rubymine colour theme into an xcode theme
6
+ #
7
+
8
+ puts "ruby is: #{RUBY_VERSION}"
9
+
10
+ require 'optparse'
11
+
12
+ # ensure our lib dir is in the load path
13
+ $:.unshift File.expand_path('../lib', File.dirname(__FILE__))
14
+
15
+ require 'rubymine2xcode-theme/version'
16
+ require 'rubymine2xcode-theme'
17
+ require 'fileutils'
18
+
19
+ include Rubymine2Xcode
20
+
21
+ OUTPUT_DIRECTORY = "~/Library/Developer/Xcode/UserData/FontAndColorThemes"
22
+ $overwrite = false
23
+
24
+
25
+ optparse = OptionParser.new do |opts|
26
+ opts.banner = <<END
27
+ Usage: rubymine2xcode <rubymine-theme.xml>
28
+ Convert the Ruby mine theme file <rubymine-theme.xml> into the Xcode theme file.
29
+ An Xcode theme file of the same base name will be created in ~/Library/... where
30
+ Xcode will look for it.
31
+
32
+ END
33
+
34
+ opts.on('-f', '--force', "force overwrite an existing output file") do
35
+ $overwrite = true
36
+ end
37
+
38
+ opts.on_tail("-h", "--help", "Show this message") do
39
+ puts opts
40
+ exit(0)
41
+ end
42
+
43
+ end
44
+
45
+
46
+ output_path = ''
47
+
48
+ begin
49
+ optparse.parse!
50
+
51
+ # check arguments
52
+ if ARGV.length != 1
53
+ raise "Expects 1 argument"
54
+ end
55
+
56
+ unless File.exist?(ARGV[0])
57
+ raise "Input file '#{ARGV[0]}' does not exist"
58
+ end
59
+
60
+
61
+ # read input file
62
+ puts "Loading rubymine theme..."
63
+ rubymine = RubymineTheme.load_file ARGV[0]
64
+
65
+
66
+ # checkout output
67
+ FileUtils.mkpath File.expand_path(OUTPUT_DIRECTORY)
68
+
69
+
70
+
71
+ # get output filename
72
+ ext = File.extname(ARGV[0])
73
+ output_name = File.basename(ARGV[0])
74
+ output_name.gsub! /#{Regexp.escape(ext)}$/, '.dvtcolortheme'
75
+ output_path = File.join(File.expand_path(OUTPUT_DIRECTORY), output_name)
76
+ puts "Generating xcode theme: #{output_path}"
77
+
78
+ if File.exist?(output_path)
79
+ if $overwrite
80
+ File.delete output_path
81
+ else
82
+ raise "Output file '#{output_path}' already exists. Run with -f to overwrite."
83
+ end
84
+ end
85
+
86
+
87
+ converter = Converter.new
88
+ converter.convert rubymine, output_path
89
+
90
+ rescue SystemExit
91
+ # let it go through, we've been told to exit
92
+ raise
93
+ rescue Exception => x
94
+ $stderr.puts optparse
95
+ $stderr.puts x
96
+ exit(1)
97
+ end
98
+
99
+
@@ -0,0 +1,158 @@
1
+ require "rubymine2xcode-theme/version"
2
+ require "rubymine2xcode-theme/rubymine"
3
+ require "rubymine2xcode-theme/xcode"
4
+ require 'plist'
5
+
6
+
7
+ module Rubymine2Xcode
8
+ # Your code goes here...
9
+
10
+ class Converter
11
+
12
+ include ColourConversion
13
+
14
+ COLOUR_CONVERSIONS = %w{
15
+
16
+ DVTConsoleDebuggerInputTextColor attributes/CONSOLE_USER_INPUT
17
+ DVTConsoleDebuggerOutputTextColor attributes/CONSOLE_NORMAL_OUTPUT
18
+ DVTConsoleDebuggerPromptTextColor attributes/CONSOLE_GRAY_OUTPUT
19
+ DVTConsoleExectuableInputTextColor attributes/CONSOLE_USER_INPUT
20
+ DVTConsoleExectuableOutputTextColor attributes/CONSOLE_NORMAL_OUTPUT
21
+
22
+ DVTConsoleTextBackgroundColor colours/CONSOLE_BACKGROUND_KEY
23
+ DVTConsoleTextInsertionPointColor colours/CARET_ROW_COLOR
24
+ DVTConsoleTextSelectionColor colours/SELECTION_BACKGROUND
25
+ DVTDebuggerInstructionPointerColor attributes/BAD_CHARACTER/BACKGROUND
26
+ DVTSourceTextBackground colours/CONSOLE_BACKGROUND_KEY
27
+ DVTSourceTextBlockDimBackgroundColor attributes/RUBY_HEREDOC_CONTENT/BACKGROUND
28
+ DVTSourceTextInsertionPointColor colours/CARET_COLOR
29
+ DVTSourceTextInvisiblesColor colours/WHITESPACES
30
+ DVTSourceTextSelectionColor colours/SELECTION_BACKGROUND
31
+
32
+ DVTSourceTextSyntaxColors/xcode.syntax.attribute attributes/RUBY_IVAR
33
+ DVTSourceTextSyntaxColors/xcode.syntax.character attributes/RUBY_SYMBOL
34
+ DVTSourceTextSyntaxColors/xcode.syntax.comment attributes/RUBY_COMMENT
35
+ DVTSourceTextSyntaxColors/xcode.syntax.comment.doc attributes/JAVA_DOC_COMMENT
36
+ DVTSourceTextSyntaxColors/xcode.syntax.comment.doc.keyword attributes/JAVA_DOC_COMMENT
37
+ DVTSourceTextSyntaxColors/xcode.syntax.identifier.class attributes/RUBY_CONSTANT
38
+ DVTSourceTextSyntaxColors/xcode.syntax.identifier.class.system attributes/RUBY_CONSTANT
39
+ DVTSourceTextSyntaxColors/xcode.syntax.identifier.constant attributes/RUBY_CONSTANT_DECLARATION
40
+ DVTSourceTextSyntaxColors/xcode.syntax.identifier.constant.system attributes/RUBY_CONSTANT_DECLARATION
41
+ DVTSourceTextSyntaxColors/xcode.syntax.identifier.function attributes/RUBY_METHOD_NAME
42
+ DVTSourceTextSyntaxColors/xcode.syntax.identifier.function.system attributes/RUBY_METHOD_NAME
43
+ DVTSourceTextSyntaxColors/xcode.syntax.identifier.macro attributes/RUBY_SPECIFIC_CALL
44
+ DVTSourceTextSyntaxColors/xcode.syntax.identifier.macro.system attributes/RUBY_SPECIFIC_CALL
45
+ DVTSourceTextSyntaxColors/xcode.syntax.identifier.type attributes/RUBY_REGEXP
46
+ DVTSourceTextSyntaxColors/xcode.syntax.identifier.type.system attributes/RUBY_REGEXP
47
+ DVTSourceTextSyntaxColors/xcode.syntax.identifier.variable attributes/RUBY_IVAR
48
+ DVTSourceTextSyntaxColors/xcode.syntax.identifier.variable.system attributes/RUBY_IVAR
49
+ DVTSourceTextSyntaxColors/xcode.syntax.keyword attributes/RUBY_KEYWORD
50
+ DVTSourceTextSyntaxColors/xcode.syntax.number attributes/RUBY_NUMBER
51
+ DVTSourceTextSyntaxColors/xcode.syntax.plain attributes/RUBY_IDENTIFIER
52
+ DVTSourceTextSyntaxColors/xcode.syntax.preprocessor attributes/RUBY_SPECIFIC_CALL
53
+ DVTSourceTextSyntaxColors/xcode.syntax.string attributes/RUBY_STRING
54
+ DVTSourceTextSyntaxColors/xcode.syntax.url attributes/HYPERLINK_ATTRIBUTES
55
+
56
+ }
57
+
58
+ FONT_CONVERSIONS = %w{
59
+ DVTConsoleDebuggerInputTextFont
60
+ DVTConsoleDebuggerOutputTextFont
61
+ DVTConsoleDebuggerPromptTextFont
62
+ DVTConsoleExectuableInputTextFont
63
+ DVTConsoleExectuableOutputTextFont
64
+
65
+ DVTSourceTextSyntaxFonts/xcode.syntax.attribute
66
+ DVTSourceTextSyntaxFonts/xcode.syntax.character
67
+ DVTSourceTextSyntaxFonts/xcode.syntax.comment
68
+ DVTSourceTextSyntaxFonts/xcode.syntax.comment.doc
69
+ DVTSourceTextSyntaxFonts/xcode.syntax.comment.doc.keyword
70
+ DVTSourceTextSyntaxFonts/xcode.syntax.identifier.class
71
+ DVTSourceTextSyntaxFonts/xcode.syntax.identifier.class.system
72
+ DVTSourceTextSyntaxFonts/xcode.syntax.identifier.constant
73
+ DVTSourceTextSyntaxFonts/xcode.syntax.identifier.constant.system
74
+ DVTSourceTextSyntaxFonts/xcode.syntax.identifier.function
75
+ DVTSourceTextSyntaxFonts/xcode.syntax.identifier.function.system
76
+ DVTSourceTextSyntaxFonts/xcode.syntax.identifier.macro
77
+ DVTSourceTextSyntaxFonts/xcode.syntax.identifier.macro.system
78
+ DVTSourceTextSyntaxFonts/xcode.syntax.identifier.type
79
+ DVTSourceTextSyntaxFonts/xcode.syntax.identifier.type.system
80
+ DVTSourceTextSyntaxFonts/xcode.syntax.identifier.variable
81
+ DVTSourceTextSyntaxFonts/xcode.syntax.identifier.variable.system
82
+ DVTSourceTextSyntaxFonts/xcode.syntax.keyword
83
+ DVTSourceTextSyntaxFonts/xcode.syntax.number
84
+ DVTSourceTextSyntaxFonts/xcode.syntax.plain
85
+ DVTSourceTextSyntaxFonts/xcode.syntax.preprocessor
86
+ DVTSourceTextSyntaxFonts/xcode.syntax.string
87
+ DVTSourceTextSyntaxFonts/xcode.syntax.url
88
+ }
89
+
90
+
91
+
92
+ def convert(rubymine_theme, output_filename)
93
+ output = {}
94
+
95
+ COLOUR_CONVERSIONS.each_slice(2) do |slice|
96
+
97
+ #prepare the destination
98
+ destination = slice[0]
99
+ destination_split = destination.split '/'
100
+ if destination_split.length == 1
101
+ destination_hash = output
102
+ else
103
+ output[destination_split[0]] ||= {}
104
+ destination_hash = output[destination_split[0]]
105
+ destination = destination_split[1]
106
+ end
107
+
108
+
109
+ #read the colour
110
+ method, name, property = slice[1].split '/'
111
+ property ||= 'FOREGROUND'
112
+ colour = case method
113
+ when 'colours'
114
+ rubymine_theme.colour_named name
115
+ when 'attributes'
116
+ rubymine_theme.attributes[name][property]
117
+ else
118
+ nil
119
+ end
120
+
121
+ puts "WARNING: #{slice[1]} was not found in rubymine theme!" unless colour
122
+
123
+ colour ||= "808080"
124
+
125
+ #convert to Xcode colour
126
+ colour = rubymine_colour_to_a(colour)
127
+ colour << 1
128
+
129
+ destination_hash[destination] = colour.join(' ')
130
+ end
131
+
132
+
133
+ # Define the fonts
134
+ font = "#{rubymine_theme.font_name} - #{rubymine_theme.font_size}"
135
+ FONT_CONVERSIONS.each do |item|
136
+
137
+ #prepare the destination
138
+ destination = item
139
+ destination_split = destination.split '/'
140
+ if destination_split.length == 1
141
+ destination_hash = output
142
+ else
143
+ output[destination_split[0]] ||= {}
144
+ destination_hash = output[destination_split[0]]
145
+ destination = destination_split[1]
146
+ end
147
+
148
+ destination_hash[destination] = font
149
+ end
150
+
151
+ # save output file
152
+ File.open(output_filename, "w") do |file|
153
+ file << output.to_plist
154
+ end
155
+
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,80 @@
1
+ require 'rexml/document'
2
+
3
+ module Rubymine2Xcode
4
+ # Your code goes here...
5
+
6
+
7
+ class RubymineTheme
8
+ include REXML
9
+
10
+ attr_accessor :colours
11
+ attr_accessor :attributes
12
+ attr_accessor :font_name, :font_size
13
+
14
+ def initialize()
15
+ @colours = []
16
+ @attributes = {}
17
+ end
18
+
19
+ def colour_named(name)
20
+ result = @colours.find { |colour| colour[:name] == name }
21
+ result[:value] unless result.nil?
22
+ end
23
+
24
+ def self.load_file(filename)
25
+ instance = self.new
26
+
27
+ xmlfile = File.new(filename)
28
+ xmldoc = Document.new(xmlfile)
29
+
30
+ # Now get the root element
31
+ root = xmldoc.root
32
+
33
+ # set colours
34
+ root.elements.each("colors/option") do |element|
35
+ name = element.attributes["name"]
36
+ value = element.attributes["value"]
37
+ instance.colours << { :name => name, :value => value }
38
+ end
39
+
40
+
41
+ # read attributes
42
+ root.elements.each("attributes/option") do |element|
43
+ name = element.attributes["name"]
44
+ attr = {}
45
+ element.elements.each("value/option") do |value_element|
46
+ value_name = value_element.attributes["name"]
47
+ value_value = value_element.attributes["value"]
48
+ attr[value_name] = value_value
49
+ end
50
+ instance.attributes[name] = attr
51
+ end
52
+
53
+
54
+ # read font name and size
55
+ instance.font_name = XPath.first(xmldoc, '/scheme/option[@name="EDITOR_FONT_NAME"]').attribute("value").value
56
+ instance.font_size = XPath.first(xmldoc, '/scheme/option[@name="EDITOR_FONT_SIZE"]').attribute("value").value.to_i
57
+
58
+ instance
59
+ end
60
+
61
+
62
+ end
63
+
64
+
65
+ module ColourConversion
66
+
67
+ def rubymine_colour_to_a string
68
+ # rubymine colours have leading zeros stripped
69
+ string = "0" * (6 - string.length) + string if string.length < 6
70
+ red = string[0..1]
71
+ green = string[2..3]
72
+ blue = string[4..5]
73
+ [red.to_i(16)/255.0, green.to_i(16)/255.0, blue.to_i(16)/255.0]
74
+ end
75
+
76
+ end
77
+
78
+
79
+ end
80
+