Class: SnippetsConverter::Base
- Inherits:
-
Object
- Object
- SnippetsConverter::Base
- Defined in:
- lib/snippets_converter.rb
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #run(*args) ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
13 |
# File 'lib/snippets_converter.rb', line 13 def initialize; end |
Instance Method Details
#run(*args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/snippets_converter.rb', line 15 def run(*args) @in_folder = Dir.pwd # File.dirname(__FILE__) + '/../in' raise Exception.new("You must have a '#{@in_folder}' folder") if !File.directory?(@in_folder) @out_folder = Dir.pwd + '/out' # File.dirname(__FILE__) + '/../out' FileUtils.mkdir_p(@out_folder) if !File.directory?(@out_folder) raise Exception.new("You must have a '#{@out_folder}' folder writable") if !File.directory?(@out_folder) || !File.writable?(@out_folder) @editor = args.first || 'Netbeans' # default editor is NetBeans @editor = 'Netbeans' if @editor == 'NetBeans' # Dirty fix for NetBeans editor name extend "SnippetsConverter::Editors::#{@editor.camelize}".constantize output = nil language = nil for file in Dir.glob("#{@in_folder}/**/*.tmSnippet") if ( new_output = convert(file) ) puts "Converting '#{File.basename(file)}' to #{@editor} snippet..." output = "#{output}#{new_output}" language = parse_tm_snippet(file)[:language] unless language else puts "(WARNING): Unable to convert the snippet '#{File.basename(file)}'." end end output = "#{editor_header(language)}#{output}#{editor_bottom}" File.open("#{@out_folder}/#{editor_target_file(language)}", "w") do |f| f.write(output) end puts "Result stored in '#{Pathname.new(@out_folder).realpath.to_s}/#{editor_target_file(language)}'" puts "**** Done ****" end |