snippets_converter 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +21 -9
- data/VERSION +1 -1
- data/lib/snippets_converter/editors/netbeans.rb +1 -1
- data/lib/snippets_converter.rb +62 -32
- data/snippets_converter.gemspec +8 -9
- data/test/test_snippets_converter.rb +3 -0
- metadata +13 -6
data/README.rdoc
CHANGED
@@ -1,30 +1,42 @@
|
|
1
1
|
= Snippets Converter
|
2
2
|
|
3
|
-
Convert TextMate Snippets into Gedit, NetBeans and Ruble (Aptana RadRails 3) snippets.
|
3
|
+
Convert TextMate Snippets into Gedit, NetBeans and Ruble (Aptana Studio/RadRails 3) snippets.
|
4
4
|
|
5
5
|
== Install the gem
|
6
6
|
sudo gem snippets_converter
|
7
7
|
|
8
|
-
== How to use (for Ubuntu)
|
9
|
-
* Open a terminal and go in your TextMate Bundle directory. Then run
|
8
|
+
== How to use (for Ubuntu and Ruby snippets)
|
9
|
+
* Open a terminal and go in your TextMate Bundle directory. Then run
|
10
|
+
|
10
11
|
snippets_converter netbeans|gedit|ruble
|
11
|
-
|
12
|
+
|
13
|
+
This will convert all your Snippets in a XML file into the "out" folder of your current directory.
|
12
14
|
|
13
15
|
=== Gedit
|
14
|
-
Put the
|
16
|
+
* Put the <language>.xml file into
|
15
17
|
|
16
18
|
/home/username/.gnome2/gedit/snippets
|
17
19
|
|
20
|
+
==== If you used GMate (http://github.com/gmate/gmate)
|
21
|
+
|
22
|
+
* Open your <language>.xml file and check if the "language" attribute of "snippets" tag is correct
|
23
|
+
|
24
|
+
<snippets language="rubyonrails">
|
25
|
+
|
18
26
|
=== NetBeans
|
19
|
-
Put the org-netbeans-modules-editor-settings-CustomCodeTemplates.xml file into
|
27
|
+
* Put the org-netbeans-modules-editor-settings-CustomCodeTemplates.xml file into
|
20
28
|
|
21
|
-
/home/username/.netbeans/6.
|
29
|
+
/home/username/.netbeans/6.9/config/Editors/text/x-ruby/CodeTemplates
|
22
30
|
|
23
|
-
=== Ruble
|
24
|
-
Put the
|
31
|
+
=== Ruble (Aptana Studio/RadRails 3)
|
32
|
+
* Put the <language>_snippets.rb file into
|
25
33
|
|
26
34
|
/home/username/Documents/Aptana Rubles/my_ruble.ruble/snippets
|
27
35
|
|
36
|
+
* Open your <language>_snippets.rb file and check if the value of "scope" is correct
|
37
|
+
|
38
|
+
with_defaults :scope => "source.ruby" do |bundle|
|
39
|
+
|
28
40
|
More info at https://radrails.tenderapp.com/faqs/radrails-3/ruble-programming-guide
|
29
41
|
|
30
42
|
== Note on Patches/Pull Requests
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
@@ -5,8 +5,8 @@ module SnippetsConverter
|
|
5
5
|
def editor_conversion(trigger, description, code)
|
6
6
|
code.gsub!(/\$0/, '${cursor}')
|
7
7
|
code.gsub!(/\$\{([0-9]{1,5}):((?>[^{}]+)|(\1))+\}/m, '${\1 default="\2"}')
|
8
|
+
code.gsub!(/(\$\{([0-9]{1,5}) default\=\".+\"\}.+)\$(\2)/m, '\1${\3}')
|
8
9
|
code.gsub!(/\$([0-9]{1,5})/, '${tabStop\1 default=""}')
|
9
|
-
|
10
10
|
return <<-CODE
|
11
11
|
<codetemplate abbreviation='#{trigger}' xml:space='preserve'>
|
12
12
|
<description><![CDATA[#{description}]]></description>
|
data/lib/snippets_converter.rb
CHANGED
@@ -84,25 +84,42 @@ module SnippetsConverter
|
|
84
84
|
|
85
85
|
# Nested tab stops and place holders remover, e.g '${1: ${3:cool} $2 }' become ' ${3:cool} $2 '
|
86
86
|
def transform_snippet(code)
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
87
|
+
# Transform TextMate snippets syntax into snippets converter internal codes, e.g. '$' become ':dollar:'
|
88
|
+
|
89
|
+
# Nested tab stops, e.g '${1: $2 }'
|
90
|
+
nested_tab_stop = /((\$\{[0-9]{1,5}:[^${}]*)\$([0-9]{1,5})([^${}]*\}))+/m
|
91
|
+
code.gsub!(nested_tab_stop, '\2:nested_tab_stop\3:\4')
|
92
|
+
|
93
|
+
code.gsub!(/\$([0-9]{1,5})/, ':tab_stop\1:') # Tab Stop, e.g '$0'
|
94
|
+
|
95
|
+
# Unescape "$", "`" and "}" if there are in plain text or in the value of a variable
|
96
|
+
# More info at http://manual.macromates.com/en/snippets#plain_text and http://manual.macromates.com/en/snippets#variables
|
97
|
+
code.gsub!(/\\`/, ':escape_backtick:')
|
98
|
+
code.gsub!(/\\\$/, ':escape_dollar:')
|
99
|
+
|
100
|
+
i = 0
|
101
|
+
loop do
|
102
|
+
i += 1
|
103
|
+
break if !code.gsub!(/\{([^{}]*|[^{}]*\{[^{}]*\}[^{}]*)\\\}/, ':escape_bracket:\1:escape_close_bracket:') || i > 20
|
104
|
+
end
|
105
|
+
|
106
|
+
code.gsub!(/\$([^{][^0-9]+[^:])/, ':dollar:\1') # Dollar, e.g. '$titi'
|
107
|
+
|
108
|
+
# Place holders, e.g. '${1: cool }'
|
109
|
+
place_holders = /\$\{((?>[^${}]+)|(\1))+\}/m
|
110
|
+
place_holders_matches = code.scan(place_holders)
|
111
|
+
place_holders_matches.flatten.each do |place_holder|
|
112
|
+
if place_holder
|
113
|
+
idx = place_holder.gsub(/([0-9]{1,5}):.+/,'\1')
|
114
|
+
code.gsub!(/\$\{#{place_holder}\}/m, ":place_holders#{idx}:")
|
115
|
+
end
|
102
116
|
end
|
103
|
-
|
117
|
+
|
104
118
|
|
105
|
-
#
|
119
|
+
#TODO Check if the regular expression in variables are correctly converted/supported
|
120
|
+
# More info at http://manual.macromates.com/en/regular_expressions.html
|
121
|
+
|
122
|
+
# Removed Nested place holders, e.g. '${1: ${3:cool} }' become ' ${3:cool} '
|
106
123
|
nested_place_holders = /(\$\{[0-9]{1,5}:(([^${}]*(\$\{[0-9]{1,5}:|\{)[^${}]+\}[^${}]*)|[^${}]+)\})/m
|
107
124
|
i = 0
|
108
125
|
loop do
|
@@ -110,24 +127,37 @@ module SnippetsConverter
|
|
110
127
|
break if !code.gsub!(nested_place_holders, '\2') || i > 20
|
111
128
|
end
|
112
129
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
130
|
+
# Transform snippets converter internal codes into characters, e.g. ':dollar:' become '$'
|
131
|
+
|
132
|
+
place_holders_matches.flatten.each do |place_holder|
|
133
|
+
if place_holder
|
134
|
+
idx = place_holder.gsub(/([0-9]{1,5}):.+/,'\1')
|
135
|
+
code.gsub!(/:place_holders#{idx}:/m, "\$\{#{place_holder}\}")
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# Nested tab stops
|
140
|
+
code.gsub!(/:nested_tab_stop([0-9]{1,5}):/, '$\1')
|
141
|
+
nested_tab_stop = /(\$\{[0-9]{1,5}:([^${}]*\$[0-9]{1,5}[^${}]*)\})+/m
|
142
|
+
i = 0
|
143
|
+
loop do
|
144
|
+
i += 1
|
145
|
+
break if !code.gsub!(nested_tab_stop, '\2') || i > 20
|
117
146
|
end
|
118
|
-
end
|
119
147
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
i
|
126
|
-
|
127
|
-
|
148
|
+
code.gsub!(/:tab_stop([0-9]{1,5}):/, '$\1')
|
149
|
+
|
150
|
+
code.gsub!(/:escape_backtick:/, '`')
|
151
|
+
code.gsub!(/:escape_dollar:/, '$')
|
152
|
+
|
153
|
+
i = 0
|
154
|
+
loop do
|
155
|
+
i += 1
|
156
|
+
break if !code.gsub!(/:escape_bracket:(.*):escape_close_bracket:/, '{\1}') || i > 20
|
157
|
+
end
|
128
158
|
|
129
|
-
|
130
|
-
|
159
|
+
code.gsub!(/:dollar:/, '$')
|
160
|
+
|
131
161
|
end
|
132
162
|
|
133
163
|
# Dummy methods, the current Editor module must override them
|
data/snippets_converter.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{snippets_converter}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nowhere Man"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-06-17}
|
13
13
|
s.default_executable = %q{snippets_converter}
|
14
14
|
s.description = %q{Quick and dirty code to transform TextMate Snippets into Gedit, NetBeans and Ruble (Aptana Studio) snippets}
|
15
15
|
s.email = %q{nowhereman@open_office}
|
@@ -41,19 +41,19 @@ Gem::Specification.new do |s|
|
|
41
41
|
s.homepage = %q{http://github.com/nowhereman/snippets_converter}
|
42
42
|
s.rdoc_options = ["--charset=UTF-8"]
|
43
43
|
s.require_paths = ["lib"]
|
44
|
-
s.rubygems_version = %q{1.3.
|
44
|
+
s.rubygems_version = %q{1.3.7}
|
45
45
|
s.summary = %q{Convert TextMate Snippets Gedit, NetBeans and Ruble (Aptana Studio) Snippets.}
|
46
46
|
s.test_files = [
|
47
|
-
"test/
|
47
|
+
"test/test_parse_tm_snippet.rb",
|
48
48
|
"test/test_snippets_converter.rb",
|
49
|
-
"test/
|
49
|
+
"test/test_helper.rb"
|
50
50
|
]
|
51
51
|
|
52
52
|
if s.respond_to? :specification_version then
|
53
53
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
54
54
|
s.specification_version = 3
|
55
55
|
|
56
|
-
if Gem::Version.new(Gem::
|
56
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
57
57
|
s.add_runtime_dependency(%q<activesupport>, ["< 3.0.0"])
|
58
58
|
else
|
59
59
|
s.add_dependency(%q<activesupport>, ["< 3.0.0"])
|
@@ -62,4 +62,3 @@ Gem::Specification.new do |s|
|
|
62
62
|
s.add_dependency(%q<activesupport>, ["< 3.0.0"])
|
63
63
|
end
|
64
64
|
end
|
65
|
-
|
@@ -14,6 +14,9 @@ class TestSnippetsConverter < Test::Unit::TestCase
|
|
14
14
|
@snippets << [ "${1: [ ${2: cool} ${3: guy { ${4:tralala} } } ] }", " [ ${2: cool} guy { ${4:tralala} } ] "]
|
15
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
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
|
+
@snippets << [ "${1: ${2: {:global => \\$COOL\\} } ${3: && \\`cd /\\`} }", " ${2: {:global => $COOL} } ${3: && `cd /`} "]
|
18
|
+
@snippets << [ "${1: cool} ${2: {:global => ${3:\\`cd /\\`} \\} }", "${1: cool} {:global => ${3:`cd /`} } "]
|
19
|
+
@snippets << [ "${1: ${2: {:global => { :hash1 => \\`cd /\\` \\} \\} } }", " ${2: {:global => { :hash1 => `cd /` } } } "]
|
17
20
|
|
18
21
|
snippet = 'context "${1:description}" do
|
19
22
|
${2:setup do
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snippets_converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Nowhere Man
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-06-17 00:00:00 +02:00
|
18
19
|
default_executable: snippets_converter
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: activesupport
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - <
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
27
30
|
segments:
|
28
31
|
- 3
|
29
32
|
- 0
|
@@ -69,27 +72,31 @@ rdoc_options:
|
|
69
72
|
require_paths:
|
70
73
|
- lib
|
71
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
72
76
|
requirements:
|
73
77
|
- - ">="
|
74
78
|
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
75
80
|
segments:
|
76
81
|
- 0
|
77
82
|
version: "0"
|
78
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
79
85
|
requirements:
|
80
86
|
- - ">="
|
81
87
|
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
82
89
|
segments:
|
83
90
|
- 0
|
84
91
|
version: "0"
|
85
92
|
requirements: []
|
86
93
|
|
87
94
|
rubyforge_project:
|
88
|
-
rubygems_version: 1.3.
|
95
|
+
rubygems_version: 1.3.7
|
89
96
|
signing_key:
|
90
97
|
specification_version: 3
|
91
98
|
summary: Convert TextMate Snippets Gedit, NetBeans and Ruble (Aptana Studio) Snippets.
|
92
99
|
test_files:
|
93
|
-
- test/test_helper.rb
|
94
|
-
- test/test_snippets_converter.rb
|
95
100
|
- test/test_parse_tm_snippet.rb
|
101
|
+
- test/test_snippets_converter.rb
|
102
|
+
- test/test_helper.rb
|