snippets_converter 0.1.1
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.
- data/.document +5 -0
- data/.gitignore +9 -0
- data/LICENSE +19 -0
- data/README.rdoc +45 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/bin/snippets_converter +25 -0
- data/in/DummyFile +0 -0
- data/lib/snippets_converter/editors/gedit.rb +34 -0
- data/lib/snippets_converter/editors/netbeans.rb +36 -0
- data/lib/snippets_converter/editors/ruble.rb +37 -0
- data/lib/snippets_converter.rb +130 -0
- data/out/DummyFile +0 -0
- data/snippets_converter.gemspec +59 -0
- data/test/test_helper.rb +9 -0
- data/test/test_snippets_converter.rb +94 -0
- metadata +79 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2009 Nicolas Alpi
|
2
|
+
Copyright (c) 2010 Nowhere Man
|
3
|
+
|
4
|
+
TmSnippetsConverter is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
|
5
|
+
as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
|
6
|
+
|
7
|
+
TmSnippetsConverter is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
8
|
+
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
9
|
+
|
10
|
+
You should have received a copy of the GNU General Public License along with TmSnippetsConverter; if not, write to the
|
11
|
+
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
14
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
15
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
17
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
18
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
19
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
= Snippets Converter
|
2
|
+
|
3
|
+
Convert TextMate Snippets into into Gedit, NetBeans and Ruble (Aptana Studio) snippets.
|
4
|
+
|
5
|
+
== How to use (for Ubuntu)
|
6
|
+
|
7
|
+
Copy your TextMate Snippets directory into the in folder of snippets_converter, run
|
8
|
+
ruby snippets_converter netbeans|gedit|ruble
|
9
|
+
This will convert all you need and create a XML file.
|
10
|
+
|
11
|
+
== Gedit
|
12
|
+
Put the gedit_snippet.xml file into
|
13
|
+
|
14
|
+
/home/username/.gnome2/gedit/snippets
|
15
|
+
|
16
|
+
|
17
|
+
== NetBeans
|
18
|
+
Put the org-netbeans-modules-editor-settings-CustomCodeTemplates.xml file into
|
19
|
+
|
20
|
+
/home/username/.netbeans/6.8/config/Editors/text/x-ruby/CodeTemplates
|
21
|
+
|
22
|
+
== Ruble
|
23
|
+
TODO
|
24
|
+
|
25
|
+
== Dependencies
|
26
|
+
|
27
|
+
you'll need ActiveSupport and Nokogiri gems in order to use this gem, so :
|
28
|
+
sudo gem install active_support nokogiri
|
29
|
+
|
30
|
+
== Note on Patches/Pull Requests
|
31
|
+
|
32
|
+
* Fork the project.
|
33
|
+
* Make your feature addition or bug fix.
|
34
|
+
* Add tests for it. This is important so I don't break it in a
|
35
|
+
future version unintentionally.
|
36
|
+
* Commit, do not mess with rakefile, version, or history.
|
37
|
+
(if you want to have your own version, that is fine but
|
38
|
+
bump version in a commit by itself I can ignore when I pull)
|
39
|
+
* Send me a pull request. Bonus points for topic branches.
|
40
|
+
|
41
|
+
== Copyright
|
42
|
+
|
43
|
+
Copyright (c) 2009 Nicolas Alpi
|
44
|
+
|
45
|
+
Copyright (c) 2010 Nowhere Man. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "snippets_converter"
|
9
|
+
gem.summary = "Convert TextMate Snippets Gedit, NetBeans and Ruble (Aptana Studio) Snippets."
|
10
|
+
gem.description = "Quick and dirty code to transform TextMate Snippets into Gedit, NetBeans and Ruble (Aptana Studio) snippets"
|
11
|
+
gem.email = "nowhereman@open_office"
|
12
|
+
gem.homepage = "http://github.com/nowhereman/snippets_converter"
|
13
|
+
gem.authors = ["Nowhere Man"]
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/*_test.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/*_test.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
if File.exist?('VERSION')
|
48
|
+
version = File.read('VERSION')
|
49
|
+
else
|
50
|
+
version = "0.1.0"
|
51
|
+
end
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "snippets_converter #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# TmSnippetsConverter
|
4
|
+
# Quick and dirty code to transform TextMate Snippets into Gedit, NetBeans and Ruble (Aptana Studio) snippets
|
5
|
+
# Based on tmsnippets2gedit (http://github.com/spyou/tmsnippets2gedit)
|
6
|
+
#
|
7
|
+
# Copyright (c) 2009 Nicolas Alpi
|
8
|
+
# Copyright (c) 2010 Nowhere Man
|
9
|
+
#
|
10
|
+
# Last update 29 April 2010
|
11
|
+
#
|
12
|
+
# TmSnippetsConverter is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
|
13
|
+
# as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
|
14
|
+
#
|
15
|
+
# TmSnippetsConverter is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
16
|
+
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License along with TmSnippetsConverter; if not, write to the
|
19
|
+
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
20
|
+
|
21
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
22
|
+
require 'snippets_converter'
|
23
|
+
|
24
|
+
snippet_converter = SnippetsConverter.new
|
25
|
+
snippet_converter.run(*ARGV)
|
data/in/DummyFile
ADDED
File without changes
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class SnippetsConverter
|
2
|
+
module Editors
|
3
|
+
module Gedit
|
4
|
+
|
5
|
+
def editor_conversion(trigger, description, code)
|
6
|
+
# Need to remove dot in 'trigger' because Gedit doesn't seem to like it on the tag
|
7
|
+
return <<-CODE
|
8
|
+
<snippet id="#{trigger.gsub(/\./,'')}">
|
9
|
+
<tag>#{trigger.gsub(/\./,'')}</tag>
|
10
|
+
<description><![CDATA[#{description}]]></description>
|
11
|
+
<text><![CDATA[#{code}]]></text>
|
12
|
+
</snippet>
|
13
|
+
CODE
|
14
|
+
end
|
15
|
+
|
16
|
+
def editor_header(language='[LANGUAGE]')
|
17
|
+
# TODO use ARGV or get 'scope' attribute of TextMate to get the desire language
|
18
|
+
return <<-CODE
|
19
|
+
<?xml version='1.0' encoding='utf-8'?>
|
20
|
+
<snippets language=\"#{language}\">
|
21
|
+
CODE
|
22
|
+
end
|
23
|
+
|
24
|
+
def editor_bottom
|
25
|
+
"</snippets>"
|
26
|
+
end
|
27
|
+
|
28
|
+
def editor_target_file
|
29
|
+
"gedit_snippets.xml"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class SnippetsConverter
|
2
|
+
module Editors
|
3
|
+
module Netbeans
|
4
|
+
|
5
|
+
def editor_conversion(trigger, description, code)
|
6
|
+
code.gsub!(/\$0/, '${cursor}')
|
7
|
+
code.gsub!(/\$\{([0-9]{1,5}):((?>[^{}]+)|(\1))+\}/m, '${\1 default="\2"}')
|
8
|
+
code.gsub!(/\$([0-9]{1,5})/, '${tabStop\1 default=""}')
|
9
|
+
|
10
|
+
return <<-CODE
|
11
|
+
<codetemplate abbreviation='#{trigger}' xml:space='preserve'>
|
12
|
+
<description><![CDATA[#{description}]]></description>
|
13
|
+
<code><![CDATA[#{code}]]></code>
|
14
|
+
</codetemplate>
|
15
|
+
CODE
|
16
|
+
end
|
17
|
+
|
18
|
+
def editor_header
|
19
|
+
return <<-CODE
|
20
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
21
|
+
<!DOCTYPE codetemplates PUBLIC "-//NetBeans//DTD Editor Code Templates settings 1.0//EN" "http://www.netbeans.org/dtds/EditorCodeTemplates-1_0.dtd">
|
22
|
+
<codetemplates>
|
23
|
+
CODE
|
24
|
+
end
|
25
|
+
|
26
|
+
def editor_bottom
|
27
|
+
"</codetemplates>"
|
28
|
+
end
|
29
|
+
|
30
|
+
def editor_target_file
|
31
|
+
"org-netbeans-modules-editor-settings-CustomCodeTemplates.xml"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class SnippetsConverter
|
2
|
+
module Editors
|
3
|
+
module Ruble
|
4
|
+
|
5
|
+
def editor_conversion(trigger, description, code)
|
6
|
+
# Need to escape double quote for description and code because Ruble doesn't seem to like it
|
7
|
+
return <<-CODE
|
8
|
+
snippet "#{description.gsub(/\"/,'\"')}" do |snippet|
|
9
|
+
snippet.trigger = "#{trigger}"
|
10
|
+
snippet.expansion = "#{code.gsub(/\"/,'\"')}"
|
11
|
+
end
|
12
|
+
|
13
|
+
CODE
|
14
|
+
end
|
15
|
+
|
16
|
+
def editor_header(language='[LANGUAGE]')
|
17
|
+
# TODO use ARGV or get 'scope' attribute of TextMate to get the desire language
|
18
|
+
return <<-CODE
|
19
|
+
require 'ruble'
|
20
|
+
|
21
|
+
with_defaults :scope => "#{language}" do |bundle|
|
22
|
+
|
23
|
+
CODE
|
24
|
+
end
|
25
|
+
|
26
|
+
def editor_bottom
|
27
|
+
|
28
|
+
"end"
|
29
|
+
end
|
30
|
+
|
31
|
+
def editor_target_file
|
32
|
+
"ruble_snippets.rb"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
class SnippetsConverter
|
2
|
+
require 'rubygems'
|
3
|
+
require 'active_support'
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
Dir[File.dirname(__FILE__) + '/snippets_converter/editors/*.rb'].each do |file|
|
7
|
+
require file
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
end
|
12
|
+
|
13
|
+
def convert(file)
|
14
|
+
xml = File.read(file)
|
15
|
+
doc = Nokogiri::XML(xml)
|
16
|
+
i = 0
|
17
|
+
j = 0
|
18
|
+
|
19
|
+
arrKey = Array.new
|
20
|
+
arrString = Array.new
|
21
|
+
# Transform the key and string node into arrays
|
22
|
+
doc.xpath('//key','//string').each do |key|
|
23
|
+
if key.name == "key"
|
24
|
+
arrKey[i] = key.text
|
25
|
+
i+=1
|
26
|
+
else
|
27
|
+
arrString[j] = key.text
|
28
|
+
j+=1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
code = arrString[arrKey.index('content')]
|
33
|
+
transform_snippet(code)
|
34
|
+
return editor_conversion(arrString[arrKey.index('tabTrigger')], arrString[arrKey.index('name')], code)
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
# Nested tab stops and place holders remover, e.g '${1: ${3:cool} $2 }' become ' ${3:cool} $2 '
|
39
|
+
def transform_snippet(code)
|
40
|
+
|
41
|
+
# Nested tab stops, e.g '${1: $2 }'
|
42
|
+
nested_tab_stop = /((\$\{[0-9]{1,5}:[^${}]*)\$([0-9]{1,5})([^${}]*\}))+/m
|
43
|
+
code.gsub!(nested_tab_stop, '\2:nested_tab_stop\3:\4')
|
44
|
+
|
45
|
+
code.gsub!(/\$([0-9]{1,5})/, ':tab_stop\1:') # Tab Stop, e.g '$0'
|
46
|
+
code.gsub!(/\$([^{][^0-9]+[^:])/, ':dollar:\1') # Dollar, e.g. '$titi'
|
47
|
+
|
48
|
+
# Place holders, e.g. '${1: cool }'
|
49
|
+
place_holders = /\$\{((?>[^${}]+)|(\1))+\}/m
|
50
|
+
place_holders_matches = code.scan(place_holders)
|
51
|
+
place_holders_matches.flatten.each do |place_holder|
|
52
|
+
if place_holder
|
53
|
+
idx = place_holder.gsub(/([0-9]{1,5}):.+/,'\1')
|
54
|
+
code.gsub!(/\$\{#{place_holder}\}/m, ":place_holders#{idx}:")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Nested place holders, e.g. '${1: ${3:cool} }'
|
59
|
+
nested_place_holders = /(\$\{[0-9]{1,5}:(([^${}]*(\$\{[0-9]{1,5}:|\{)[^${}]+\}[^${}]*)|[^${}]+)\})/m
|
60
|
+
i = 0
|
61
|
+
loop do
|
62
|
+
i += 1
|
63
|
+
break if !code.gsub!(nested_place_holders, '\2') || i > 20
|
64
|
+
end
|
65
|
+
|
66
|
+
place_holders_matches.flatten.each do |place_holder|
|
67
|
+
if place_holder
|
68
|
+
idx = place_holder.gsub(/([0-9]{1,5}):.+/,'\1')
|
69
|
+
code.gsub!(/:place_holders#{idx}:/m, "\$\{#{place_holder}\}")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Nested tab stops
|
74
|
+
code.gsub!(/:nested_tab_stop([0-9]{1,5}):/, '$\1')
|
75
|
+
nested_tab_stop = /(\$\{[0-9]{1,5}:([^${}]*\$[0-9]{1,5}[^${}]*)\})+/m
|
76
|
+
i = 0
|
77
|
+
loop do
|
78
|
+
i += 1
|
79
|
+
break if !code.gsub!(nested_tab_stop, '\2') || i > 20
|
80
|
+
end
|
81
|
+
|
82
|
+
code.gsub!(/:tab_stop([0-9]{1,5}):/, '$\1')
|
83
|
+
code.gsub!(/:dollar:/, '$')
|
84
|
+
end
|
85
|
+
|
86
|
+
# Dummy methods, the current Editor module must override them
|
87
|
+
def editor_conversion(trigger, description, code)
|
88
|
+
raise Exception.new("The current Editor module must implement this method")
|
89
|
+
end
|
90
|
+
|
91
|
+
def editor_header
|
92
|
+
raise Exception.new("The current Editor module must implement this method")
|
93
|
+
end
|
94
|
+
|
95
|
+
def editor_bottom
|
96
|
+
raise Exception.new("The current Editor module must implement this method")
|
97
|
+
end
|
98
|
+
|
99
|
+
def editor_target_file
|
100
|
+
raise Exception.new("The current Editor module must implement this method")
|
101
|
+
end
|
102
|
+
|
103
|
+
def run(*args)
|
104
|
+
@in_folder = Dir.pwd # File.dirname(__FILE__) + '/../in'
|
105
|
+
@out_folder = Dir.pwd + '/out' # File.dirname(__FILE__) + '/../out'
|
106
|
+
|
107
|
+
@editor = args.first || 'Netbeans' # default editor is NetBeans
|
108
|
+
@editor = 'Netbeans' if @editor == 'NetBeans' # Dirty fix for NetBeans editor name
|
109
|
+
extend "SnippetsConverter::Editors::#{@editor.camelize}".constantize
|
110
|
+
|
111
|
+
raise Exception.new("You must have a '#{@in_folder}' folder writable") if !File.directory?(@in_folder) || !File.writable?(@in_folder)
|
112
|
+
raise Exception.new("You must have a '#{@out_folder}' folder writable") if !File.directory?(@out_folder) || !File.writable?(@out_folder)
|
113
|
+
|
114
|
+
output = editor_header
|
115
|
+
for file in Dir.glob("#{@in_folder}/**/*.tmSnippet")
|
116
|
+
puts "Converting #{file} to #{@editor} snippet..."
|
117
|
+
output = "#{output}#{convert(file)}"
|
118
|
+
end
|
119
|
+
output = "#{output}#{editor_bottom}"
|
120
|
+
|
121
|
+
File.open("#{@out_folder}/#{editor_target_file}", "w") do |f|
|
122
|
+
f.write(output)
|
123
|
+
end
|
124
|
+
|
125
|
+
puts "Result stored in '#{Pathname.new(@out_folder).realpath.to_s}/#{editor_target_file}'"
|
126
|
+
puts "**** Done ****"
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
data/out/DummyFile
ADDED
File without changes
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{snippets_converter}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nowhere Man"]
|
12
|
+
s.date = %q{2010-04-30}
|
13
|
+
s.default_executable = %q{snippets_converter}
|
14
|
+
s.description = %q{Quick and dirty code to transform TextMate Snippets into Gedit, NetBeans and Ruble (Aptana Studio) snippets}
|
15
|
+
s.email = %q{nowhereman@open_office}
|
16
|
+
s.executables = ["snippets_converter"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/snippets_converter",
|
29
|
+
"in/DummyFile",
|
30
|
+
"lib/snippets_converter.rb",
|
31
|
+
"lib/snippets_converter/editors/gedit.rb",
|
32
|
+
"lib/snippets_converter/editors/netbeans.rb",
|
33
|
+
"lib/snippets_converter/editors/ruble.rb",
|
34
|
+
"out/DummyFile",
|
35
|
+
"snippets_converter.gemspec",
|
36
|
+
"test/test_helper.rb",
|
37
|
+
"test/test_snippets_converter.rb"
|
38
|
+
]
|
39
|
+
s.homepage = %q{http://github.com/nowhereman/snippets_converter}
|
40
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.3.6}
|
43
|
+
s.summary = %q{Convert TextMate Snippets Gedit, NetBeans and Ruble (Aptana Studio) Snippets.}
|
44
|
+
s.test_files = [
|
45
|
+
"test/test_helper.rb",
|
46
|
+
"test/test_snippets_converter.rb"
|
47
|
+
]
|
48
|
+
|
49
|
+
if s.respond_to? :specification_version then
|
50
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
51
|
+
s.specification_version = 3
|
52
|
+
|
53
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
54
|
+
else
|
55
|
+
end
|
56
|
+
else
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestSnippetsConverter < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@snippets = []
|
7
|
+
@snippets << [ "${1: ${2: cool} }", " ${2: cool} "]
|
8
|
+
@snippets << [ "${1: cool $2 }", " cool $2 "]
|
9
|
+
@snippets << [ "${1: ${2: $cool} }", " ${2: $cool} "]
|
10
|
+
@snippets << [ "${1: [ ${2: cool} ] }", " [ ${2: cool} ] "]
|
11
|
+
@snippets << [ "${1: ${2: cool} ${3: guy} }", " ${2: cool} ${3: guy} "]
|
12
|
+
@snippets << [ "${1: [ ${2: cool} ${3: guy} ] }", " [ ${2: cool} ${3: guy} ] "]
|
13
|
+
@snippets << [ "${1: [ ${2: cool} ${3: guy ${4:tralala}} ] }", " [ ${2: cool} guy ${4:tralala} ] "]
|
14
|
+
@snippets << [ "${1: [ ${2: cool} ${3: guy { ${4:tralala} } } ] }", " [ ${2: cool} guy { ${4:tralala} } ] "]
|
15
|
+
@snippets << [ 'should_have_db_column :${1:name}${2:, :${3:type} => ${4:"${5:string}"}${6:, :${7:default} => ${8:nil}}}', 'should_have_db_column :${1:name}, :${3:type} => "${5:string}", :${7:default} => ${8:nil}']
|
16
|
+
@snippets << [ "should_have_db_indices :${1:object_id}${2:, [:${3:commentable_type}, :${4:commentable_id}]}$0", "should_have_db_indices :${1:object_id}, [:${3:commentable_type}, :${4:commentable_id}]$0" ]
|
17
|
+
|
18
|
+
snippet = 'context "${1:description}" do
|
19
|
+
${2:setup do
|
20
|
+
${3: cool}
|
21
|
+
end
|
22
|
+
|
23
|
+
}should "${4:description}" do
|
24
|
+
${5: guy}
|
25
|
+
end
|
26
|
+
end'
|
27
|
+
|
28
|
+
expected_snippet = 'context "${1:description}" do
|
29
|
+
setup do
|
30
|
+
${3: cool}
|
31
|
+
end
|
32
|
+
|
33
|
+
should "${4:description}" do
|
34
|
+
${5: guy}
|
35
|
+
end
|
36
|
+
end'
|
37
|
+
|
38
|
+
@snippets << [ snippet, expected_snippet ]
|
39
|
+
@snippets << [ "[ ${3::${4:key} => ${5:value}${6:, :${7:key} => ${8:value} } } ]", "[ :${4:key} => ${5:value}, :${7:key} => ${8:value} ]" ]
|
40
|
+
@snippets << [ " { ${3::${4:key} => ${5:value}${6:, :${7:key} => ${8:value}}} } ", " { :${4:key} => ${5:value}, :${7:key} => ${8:value} } " ]
|
41
|
+
|
42
|
+
snippet = 'context "on POST to :${1:create}" do
|
43
|
+
setup do
|
44
|
+
post :$1, :${2:user} => { ${3::${4:key} => ${5:value}${6:, :${7:key} => ${8:value} } } }
|
45
|
+
end
|
46
|
+
|
47
|
+
${9:should "${10:description}" do
|
48
|
+
$0
|
49
|
+
end}
|
50
|
+
end'
|
51
|
+
|
52
|
+
expected_snippet = 'context "on POST to :${1:create}" do
|
53
|
+
setup do
|
54
|
+
post :$1, :${2:user} => { :${4:key} => ${5:value}, :${7:key} => ${8:value} }
|
55
|
+
end
|
56
|
+
|
57
|
+
should "${10:description}" do
|
58
|
+
$0
|
59
|
+
end
|
60
|
+
end'
|
61
|
+
@snippets << [ snippet, expected_snippet ]
|
62
|
+
|
63
|
+
snippet = 'context "${1:description}" do
|
64
|
+
${2:setup do
|
65
|
+
$3
|
66
|
+
end
|
67
|
+
|
68
|
+
}should "${4:description}" do
|
69
|
+
$0
|
70
|
+
end
|
71
|
+
end'
|
72
|
+
|
73
|
+
expected_snippet = 'context "${1:description}" do
|
74
|
+
setup do
|
75
|
+
$3
|
76
|
+
end
|
77
|
+
|
78
|
+
should "${4:description}" do
|
79
|
+
$0
|
80
|
+
end
|
81
|
+
end'
|
82
|
+
@snippets << [ snippet, expected_snippet ]
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
def test_snippets_conversion
|
87
|
+
@snippets.each do |snippet, expected_snippet|
|
88
|
+
SnippetsConverter.new.transform_snippet(snippet)
|
89
|
+
assert_equal expected_snippet, snippet
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: snippets_converter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Nowhere Man
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-30 00:00:00 +02:00
|
18
|
+
default_executable: snippets_converter
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Quick and dirty code to transform TextMate Snippets into Gedit, NetBeans and Ruble (Aptana Studio) snippets
|
22
|
+
email: nowhereman@open_office
|
23
|
+
executables:
|
24
|
+
- snippets_converter
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
files:
|
31
|
+
- .document
|
32
|
+
- .gitignore
|
33
|
+
- LICENSE
|
34
|
+
- README.rdoc
|
35
|
+
- Rakefile
|
36
|
+
- VERSION
|
37
|
+
- bin/snippets_converter
|
38
|
+
- in/DummyFile
|
39
|
+
- lib/snippets_converter.rb
|
40
|
+
- lib/snippets_converter/editors/gedit.rb
|
41
|
+
- lib/snippets_converter/editors/netbeans.rb
|
42
|
+
- lib/snippets_converter/editors/ruble.rb
|
43
|
+
- out/DummyFile
|
44
|
+
- snippets_converter.gemspec
|
45
|
+
- test/test_helper.rb
|
46
|
+
- test/test_snippets_converter.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://github.com/nowhereman/snippets_converter
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --charset=UTF-8
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.3.6
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Convert TextMate Snippets Gedit, NetBeans and Ruble (Aptana Studio) Snippets.
|
77
|
+
test_files:
|
78
|
+
- test/test_helper.rb
|
79
|
+
- test/test_snippets_converter.rb
|