sublime_sunippetter 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +51 -20
- data/bin/suni +29 -29
- data/lib/sublime_sunippetter/version.rb +5 -3
- data/lib/sublime_sunippetter.rb +102 -130
- data/lib/sublime_sunippetter_dsl.rb +60 -0
- data/lib/target_method.rb +15 -0
- data/spec/spec_helper.rb +8 -17
- data/spec/sublime_sunippetter_dsl_spec.rb +21 -20
- data/spec/sublime_sunippetter_spec.rb +71 -68
- metadata +12 -10
data/README.md
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
SublimeSunippetter is generate Sublime Text2 simple sunippet from Sunippetfile DSL.
|
4
4
|
|
5
|
-
2013/11/20 ver 0.01 is still simple. Only single line space separating sunippet is supported.
|
6
|
-
|
7
5
|
## Purpose
|
8
6
|
|
9
7
|
SublimeSunippetter can use following situations.
|
@@ -36,7 +34,7 @@ First, you create Sunippetfile manually or following command.
|
|
36
34
|
|
37
35
|
suni init
|
38
36
|
|
39
|
-
Second, you have to edit Sunippetfile.
|
37
|
+
Second, you have to edit Sunippetfile manually.
|
40
38
|
|
41
39
|
~~~ruby
|
42
40
|
# encoding: utf-8
|
@@ -51,9 +49,13 @@ scope "source.ruby"
|
|
51
49
|
add :hoge, :args1, :args2
|
52
50
|
# if no args method
|
53
51
|
add :hige
|
52
|
+
# if two args method and do-block
|
53
|
+
add :hoge1, :args1, :args2, "block@d"
|
54
|
+
# if two args method and brace-block
|
55
|
+
add :hoge2, :args1, :args2, "block@b"
|
54
56
|
~~~
|
55
57
|
|
56
|
-
Third, you have to do is execute command suni.
|
58
|
+
Third, you have to do is execute command 'suni'.
|
57
59
|
|
58
60
|
suni
|
59
61
|
|
@@ -62,27 +64,55 @@ Result => generate hoge.sublime-snippet, hige.sublime-snippet
|
|
62
64
|
This Sample Sunppet Contens are ...
|
63
65
|
|
64
66
|
~~~xml
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
<snippet>
|
68
|
+
<content><![CDATA[
|
69
|
+
hoge ${1:args1}, ${2:args2}
|
70
|
+
]]></content>
|
71
|
+
<tabTrigger>hoge</tabTrigger>
|
72
|
+
<scope>source.ruby</scope>
|
73
|
+
<description>hoge method</description>
|
74
|
+
</snippet>
|
75
|
+
~~~
|
76
|
+
|
77
|
+
And
|
78
|
+
|
79
|
+
~~~xml
|
80
|
+
<snippet>
|
81
|
+
<content><![CDATA[
|
82
|
+
hige
|
83
|
+
]]></content>
|
84
|
+
<tabTrigger>hige</tabTrigger>
|
85
|
+
<scope>source.ruby</scope>
|
86
|
+
<description>hige method</description>
|
87
|
+
</snippet>
|
88
|
+
~~~
|
89
|
+
|
90
|
+
And
|
91
|
+
|
92
|
+
~~~xml
|
93
|
+
<snippet>
|
94
|
+
<content><![CDATA[
|
95
|
+
hoge1 ${1:args1}, ${2:args2} do |${9:args}|
|
96
|
+
${0:block}
|
97
|
+
end
|
98
|
+
]]></content>
|
99
|
+
<tabTrigger>hoge1</tabTrigger>
|
100
|
+
<scope>source.ruby</scope>
|
101
|
+
<description>hoge1 method</description>
|
102
|
+
</snippet>
|
73
103
|
~~~
|
74
104
|
|
75
105
|
And
|
76
106
|
|
77
107
|
~~~xml
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
108
|
+
<snippet>
|
109
|
+
<content><![CDATA[
|
110
|
+
hoge2 ${1:args1}, ${2:args2} { |${9:args}|${0:block} }
|
111
|
+
]]></content>
|
112
|
+
<tabTrigger>hoge2</tabTrigger>
|
113
|
+
<scope>source.ruby</scope>
|
114
|
+
<description>hoge2 method</description>
|
115
|
+
</snippet>
|
86
116
|
~~~
|
87
117
|
|
88
118
|
in 'C:/Users/user_name/AppData/Roaming/Sublime Text 2/Packages/User' directory.
|
@@ -92,6 +122,7 @@ in 'C:/Users/user_name/AppData/Roaming/Sublime Text 2/Packages/User' directory.
|
|
92
122
|
<img src="./doc_image/sublime_sunippetter.gif" />
|
93
123
|
|
94
124
|
## History
|
125
|
+
* version 0.0.4 : enable do-block, brace-block generate.
|
95
126
|
* version 0.0.3 : question can use. for ex 'blank?'.
|
96
127
|
* version 0.0.1 : first release.
|
97
128
|
|
data/bin/suni
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'sublime_sunippetter'
|
4
|
-
require
|
5
|
-
|
6
|
-
module SublimeSunippetter
|
7
|
-
|
8
|
-
class CLI < Thor
|
9
|
-
class_option :help, :
|
10
|
-
class_option :version, :
|
11
|
-
default_task :execute
|
12
|
-
|
13
|
-
desc
|
14
|
-
def execute
|
15
|
-
SublimeSunippetter::Core.new.generate_sunippets
|
16
|
-
end
|
17
|
-
|
18
|
-
desc
|
19
|
-
def init
|
20
|
-
SublimeSunippetter::Core.new.init
|
21
|
-
end
|
22
|
-
|
23
|
-
desc
|
24
|
-
def version
|
25
|
-
p SublimeSunippetter::VERSION
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
SublimeSunippetter::CLI.start
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'sublime_sunippetter'
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
module SublimeSunippetter
|
7
|
+
# = SublimeSunippetter CLI
|
8
|
+
class CLI < Thor
|
9
|
+
class_option :help, type: :boolean, aliases: '-h', desc: 'help message.'
|
10
|
+
class_option :version, type: :boolean, desc: 'version'
|
11
|
+
default_task :execute
|
12
|
+
|
13
|
+
desc 'execute', 'generate Sublime Text2 snippet'
|
14
|
+
def execute
|
15
|
+
SublimeSunippetter::Core.new.generate_sunippets
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'init', 'generate Sunippetdefine'
|
19
|
+
def init
|
20
|
+
SublimeSunippetter::Core.new.init
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'version', 'version'
|
24
|
+
def version
|
25
|
+
p SublimeSunippetter::VERSION
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
SublimeSunippetter::CLI.start
|
data/lib/sublime_sunippetter.rb
CHANGED
@@ -1,130 +1,102 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
#
|
13
|
-
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
#
|
21
|
-
|
22
|
-
# if
|
23
|
-
# add :
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
def add(method_name, *args)
|
104
|
-
return if method_name.nil?
|
105
|
-
return if method_name.empty?
|
106
|
-
return if args.each.include?(nil)
|
107
|
-
return if args.each.include?("")
|
108
|
-
@target_methods << TargetMethod.new do |t|
|
109
|
-
t.method_name = method_name
|
110
|
-
t.args = args
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
#== set sunippet scope
|
115
|
-
def scope(_scope)
|
116
|
-
return if _scope.nil?
|
117
|
-
return if _scope.empty?
|
118
|
-
@_scope = _scope
|
119
|
-
end
|
120
|
-
|
121
|
-
#== set sunippet output path
|
122
|
-
def output_path(_output_path)
|
123
|
-
return if _output_path.nil?
|
124
|
-
return if _output_path.empty?
|
125
|
-
@_output_path = _output_path
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
class SunippetterError < StandardError;end
|
130
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'sublime_sunippetter/version'
|
3
|
+
require 'erb'
|
4
|
+
require 'sublime_sunippetter_dsl'
|
5
|
+
|
6
|
+
module SublimeSunippetter
|
7
|
+
# SublimeSunippetter Core
|
8
|
+
class Core
|
9
|
+
# Sunippetdefine file name.
|
10
|
+
DEFINE_FILE = 'Sunippetdefine'
|
11
|
+
|
12
|
+
# Sunippetdefine file template
|
13
|
+
DEFINE_FILE_TEMPLATE = <<-EOS
|
14
|
+
# encoding: utf-8
|
15
|
+
|
16
|
+
# set output path. default=current directory
|
17
|
+
# output_path 'C:/Users/user_name/AppData/Roaming/Sublime Text 2/Packages/User'
|
18
|
+
|
19
|
+
# set sunippet scope. default=source.ruby
|
20
|
+
# scope "source.ruby"
|
21
|
+
|
22
|
+
# if two args method
|
23
|
+
# add :hoge, :args1, :args2
|
24
|
+
# if no args method
|
25
|
+
# add :hige
|
26
|
+
# if two args method and do-block
|
27
|
+
# add :hoge1, :args1, :args2, "block@d"
|
28
|
+
# if two args method and brace-block
|
29
|
+
# add :hoge2, :args1, :args2, "block@b"
|
30
|
+
EOS
|
31
|
+
|
32
|
+
# sublime sunippet template
|
33
|
+
SUNIPPET_TEMPLATE = <<-EOS
|
34
|
+
<snippet>
|
35
|
+
<content><![CDATA[
|
36
|
+
<%= method_name %><%= args_names %><%= do_block %><%= brace_block %>
|
37
|
+
]]></content>
|
38
|
+
<tabTrigger><%= method_name %></tabTrigger>
|
39
|
+
<scope><%= scope%></scope>
|
40
|
+
<description><%= method_name %> method</description>
|
41
|
+
</snippet>
|
42
|
+
EOS
|
43
|
+
|
44
|
+
# generate Sunippetdefine to current directory.
|
45
|
+
def init
|
46
|
+
File.open("./#{DEFINE_FILE}", 'w') { |f|f.puts DEFINE_FILE_TEMPLATE }
|
47
|
+
end
|
48
|
+
|
49
|
+
# generate sublime text2 sunippets from Sunippetdefine
|
50
|
+
def generate_sunippets
|
51
|
+
sunippet_define = read_sunippetdefine
|
52
|
+
dsl = Dsl.new
|
53
|
+
dsl.instance_eval sunippet_define
|
54
|
+
dsl.target_methods.each do |m|
|
55
|
+
snippet = get_snippet(
|
56
|
+
m.method_name ,
|
57
|
+
get_args_names(m) ,
|
58
|
+
get_do_block(m).chop,
|
59
|
+
get_brace_block(m),
|
60
|
+
dsl._scope
|
61
|
+
)
|
62
|
+
filename = "#{dsl._output_path}/#{m.method_name.to_s.tr('?', '')}.sublime-snippet"
|
63
|
+
File.open(filename, 'w:UTF-8') { |f|f.puts snippet }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def read_sunippetdefine
|
69
|
+
unless File.exists? "./#{DEFINE_FILE}"
|
70
|
+
fail SunippetterError, "you must create #{DEFINE_FILE}. manual or 'suni init' command"
|
71
|
+
end
|
72
|
+
File.read("./#{DEFINE_FILE}")
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_snippet(method_name, args_names, do_block, brace_block, scope)
|
76
|
+
ERB.new(SUNIPPET_TEMPLATE).result(binding)
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_args_names(method)
|
80
|
+
args = method.args
|
81
|
+
args_names = ' '
|
82
|
+
args.each_with_index {|a, i|args_names << "${#{i + 1}:#{a}}, "}
|
83
|
+
args_names.chop!.chop! unless args.empty?
|
84
|
+
end
|
85
|
+
|
86
|
+
def get_do_block(method)
|
87
|
+
return '' unless method.has_do_block
|
88
|
+
<<-EOS
|
89
|
+
do |${9:args}|
|
90
|
+
${0:block}
|
91
|
+
end
|
92
|
+
EOS
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_brace_block(method)
|
96
|
+
return '' unless method.has_brace_block
|
97
|
+
' { |${9:args}|${0:block} }'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class SunippetterError < StandardError; end
|
102
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'target_method'
|
3
|
+
|
4
|
+
module SublimeSunippetter
|
5
|
+
# Dsl. this is dsl for Sunippetdefine.
|
6
|
+
class Dsl
|
7
|
+
attr_accessor :target_methods, :_scope, :_output_path
|
8
|
+
|
9
|
+
# init default values
|
10
|
+
def initialize
|
11
|
+
@target_methods = []
|
12
|
+
@_scope = 'source.ruby'
|
13
|
+
@_output_path = './'
|
14
|
+
end
|
15
|
+
|
16
|
+
# add sunippet information
|
17
|
+
def add(method_name, *args)
|
18
|
+
return if has_error?(method_name, *args)
|
19
|
+
has_do_block = args.include?('block@d')
|
20
|
+
has_brace_block = args.include?('block@b')
|
21
|
+
args = delete_block_args args
|
22
|
+
@target_methods << TargetMethod.new do |t|
|
23
|
+
t.method_name = method_name
|
24
|
+
t.args = args
|
25
|
+
t.has_do_block = has_do_block
|
26
|
+
t.has_brace_block = has_brace_block
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# set sunippet scope
|
31
|
+
def scope(_scope)
|
32
|
+
return if _scope.nil?
|
33
|
+
return if _scope.empty?
|
34
|
+
@_scope = _scope
|
35
|
+
end
|
36
|
+
|
37
|
+
# set sunippet output path
|
38
|
+
def output_path(_output_path)
|
39
|
+
return if _output_path.nil?
|
40
|
+
return if _output_path.empty?
|
41
|
+
@_output_path = _output_path
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def has_error?(method_name, *args)
|
47
|
+
return true if method_name.nil?
|
48
|
+
return true if method_name.empty?
|
49
|
+
return true if args.each.include?(nil)
|
50
|
+
return true if args.each.include?('')
|
51
|
+
false
|
52
|
+
end
|
53
|
+
|
54
|
+
def delete_block_args(args)
|
55
|
+
args - ['block@b', 'block@d']
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class SunippetterError < StandardError; end
|
60
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SublimeSunippetter
|
4
|
+
# TargetMethod. this is method information container
|
5
|
+
class TargetMethod
|
6
|
+
attr_accessor :method_name, :args, :has_do_block, :has_brace_block
|
7
|
+
|
8
|
+
# generate sublime text2 sunippets from Sunippetdefine
|
9
|
+
def initialize(&block)
|
10
|
+
instance_eval do
|
11
|
+
block.call(self)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,17 +1,8 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
config.run_all_when_everything_filtered = true
|
10
|
-
config.filter_run :focus
|
11
|
-
|
12
|
-
# Run specs in random order to surface order dependencies. If you find an
|
13
|
-
# order dependency and want to debug it, you can fix the order by providing
|
14
|
-
# the seed, which is printed after each run.
|
15
|
-
# --seed 1234
|
16
|
-
config.order = 'random'
|
17
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
6
|
+
config.run_all_when_everything_filtered = true
|
7
|
+
config.filter_run :focus
|
8
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require_relative
|
3
|
-
require
|
2
|
+
require_relative '../lib/sublime_sunippetter'
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'target_method'
|
4
5
|
|
5
6
|
describe SublimeSunippetter::Dsl do
|
6
7
|
cases_add = [
|
@@ -15,30 +16,30 @@ describe SublimeSunippetter::Dsl do
|
|
15
16
|
},
|
16
17
|
{
|
17
18
|
case_no: 2,
|
18
|
-
method_names:nil,
|
19
|
+
method_names: nil,
|
19
20
|
params: [:hoge, :hige, :hage],
|
20
21
|
expecteds: nil,
|
21
22
|
invalid?: true
|
22
23
|
},
|
23
24
|
{
|
24
25
|
case_no: 3,
|
25
|
-
method_names:
|
26
|
+
method_names: '',
|
26
27
|
params: [:hoge, :hige, :hage],
|
27
|
-
expecteds:
|
28
|
+
expecteds: '',
|
28
29
|
invalid?: true
|
29
30
|
},
|
30
31
|
{
|
31
32
|
case_no: 4,
|
32
33
|
method_names: :hoge,
|
33
34
|
params: [:hoge, nil, :hage],
|
34
|
-
expecteds:
|
35
|
+
expecteds: '',
|
35
36
|
invalid?: true
|
36
37
|
},
|
37
38
|
{
|
38
39
|
case_no: 5,
|
39
40
|
method_names: :hoge,
|
40
|
-
params: [:hoge,
|
41
|
-
expecteds:
|
41
|
+
params: [:hoge, '', :hage],
|
42
|
+
expecteds: '',
|
42
43
|
invalid?: true
|
43
44
|
},
|
44
45
|
]
|
@@ -69,18 +70,18 @@ describe SublimeSunippetter::Dsl do
|
|
69
70
|
cases_scope = [
|
70
71
|
{
|
71
72
|
case_no: 1,
|
72
|
-
scope:
|
73
|
-
expected:
|
73
|
+
scope: 'source.java',
|
74
|
+
expected: 'source.java'
|
74
75
|
},
|
75
76
|
{
|
76
77
|
case_no: 2,
|
77
|
-
scope:nil,
|
78
|
-
expected:
|
78
|
+
scope: nil,
|
79
|
+
expected: 'source.ruby'
|
79
80
|
},
|
80
81
|
{
|
81
82
|
case_no: 3,
|
82
|
-
scope:
|
83
|
-
expected:
|
83
|
+
scope: '',
|
84
|
+
expected: 'source.ruby'
|
84
85
|
},
|
85
86
|
]
|
86
87
|
|
@@ -100,18 +101,18 @@ describe SublimeSunippetter::Dsl do
|
|
100
101
|
cases_output_path = [
|
101
102
|
{
|
102
103
|
case_no: 1,
|
103
|
-
output_path:
|
104
|
-
expected:
|
104
|
+
output_path: 'C:\\',
|
105
|
+
expected: 'C:\\'
|
105
106
|
},
|
106
107
|
{
|
107
108
|
case_no: 2,
|
108
|
-
output_path:nil,
|
109
|
-
expected:
|
109
|
+
output_path: nil,
|
110
|
+
expected: './'
|
110
111
|
},
|
111
112
|
{
|
112
113
|
case_no: 3,
|
113
|
-
output_path:
|
114
|
-
expected:
|
114
|
+
output_path: '',
|
115
|
+
expected: './'
|
115
116
|
},
|
116
117
|
]
|
117
118
|
|
@@ -1,68 +1,71 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative
|
3
|
-
require
|
4
|
-
|
5
|
-
describe SublimeSunippetter::Core do
|
6
|
-
cases_init = [
|
7
|
-
{
|
8
|
-
case_no: 1,
|
9
|
-
expected: SublimeSunippetter::Core::DEFINE_FILE_TEMPLATE
|
10
|
-
},
|
11
|
-
]
|
12
|
-
|
13
|
-
cases_init.each do |c|
|
14
|
-
it "#init case_no=#{c[:case_no]} generate #{SublimeSunippetter::Core::DEFINE_FILE}" do
|
15
|
-
# given
|
16
|
-
sunippet = SublimeSunippetter::Core.new
|
17
|
-
|
18
|
-
# when
|
19
|
-
sunippet.init
|
20
|
-
|
21
|
-
# then
|
22
|
-
actual = File.
|
23
|
-
expect(actual).to eq(c[:expected])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
GENERATE_SUNIPPETS_CASE
|
28
|
-
output_path "#{File.absolute_path('.')}"
|
29
|
-
scope "source.java"
|
30
|
-
add :hoge, :args1, :args2
|
31
|
-
add :hige?
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
sunippet.
|
55
|
-
|
56
|
-
#
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative '../lib/sublime_sunippetter'
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SublimeSunippetter::Core do
|
6
|
+
cases_init = [
|
7
|
+
{
|
8
|
+
case_no: 1,
|
9
|
+
expected: SublimeSunippetter::Core::DEFINE_FILE_TEMPLATE
|
10
|
+
},
|
11
|
+
]
|
12
|
+
|
13
|
+
cases_init.each do |c|
|
14
|
+
it "#init case_no=#{c[:case_no]} generate #{SublimeSunippetter::Core::DEFINE_FILE}" do
|
15
|
+
# given
|
16
|
+
sunippet = SublimeSunippetter::Core.new
|
17
|
+
|
18
|
+
# when
|
19
|
+
sunippet.init
|
20
|
+
|
21
|
+
# then
|
22
|
+
actual = File.read("#{SublimeSunippetter::Core::DEFINE_FILE}")
|
23
|
+
expect(actual).to eq(c[:expected])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
GENERATE_SUNIPPETS_CASE = <<-EOS
|
28
|
+
output_path "#{File.absolute_path('.')}"
|
29
|
+
scope "source.java"
|
30
|
+
add :hoge, :args1, :args2
|
31
|
+
add :hige?
|
32
|
+
add :hoge1, "block@b"
|
33
|
+
add :hoge2, "block@d"
|
34
|
+
add :hoge3, :args1, :args2, "block@b"
|
35
|
+
EOS
|
36
|
+
|
37
|
+
cases_generate_sunippets = [
|
38
|
+
{
|
39
|
+
case_no: 1,
|
40
|
+
sunippetdefine: GENERATE_SUNIPPETS_CASE,
|
41
|
+
output_file_names: ['hoge.sublime-snippet', 'hige.sublime-snippet', 'hoge1.sublime-snippet', 'hoge2.sublime-snippet', 'hoge3.sublime-snippet'],
|
42
|
+
}
|
43
|
+
]
|
44
|
+
|
45
|
+
context do
|
46
|
+
before do
|
47
|
+
File.open("./#{SublimeSunippetter::Core::DEFINE_FILE}", 'w') { |f|f.puts GENERATE_SUNIPPETS_CASE }
|
48
|
+
end
|
49
|
+
|
50
|
+
cases_generate_sunippets.each do |c|
|
51
|
+
|
52
|
+
it "#generate_sunippets case_no=#{c[:case_no]}" do
|
53
|
+
# given
|
54
|
+
sunippet = SublimeSunippetter::Core.new
|
55
|
+
|
56
|
+
# when
|
57
|
+
sunippet.generate_sunippets
|
58
|
+
|
59
|
+
# then
|
60
|
+
c[:output_file_names].each do |f|
|
61
|
+
FileTest.exist?("./#{f}").should be_true
|
62
|
+
File.delete("./#{f}")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
after(:each) do
|
69
|
+
File.delete("#{SublimeSunippetter::Core::DEFINE_FILE}") if File.exists?("#{SublimeSunippetter::Core::DEFINE_FILE}")
|
70
|
+
end
|
71
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sublime_sunippetter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement: &
|
16
|
+
requirement: &21219336 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.18.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *21219336
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &21218892 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.3'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *21218892
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &21218652 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *21218652
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &21218328 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 2.14.1
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *21218328
|
58
58
|
description: SublimeSunippetter is generate Sublime Text2 simple sunippet from Sunippetfile
|
59
59
|
DSL.
|
60
60
|
email:
|
@@ -74,6 +74,8 @@ files:
|
|
74
74
|
- doc_image/sublime_sunippetter.gif
|
75
75
|
- lib/sublime_sunippetter.rb
|
76
76
|
- lib/sublime_sunippetter/version.rb
|
77
|
+
- lib/sublime_sunippetter_dsl.rb
|
78
|
+
- lib/target_method.rb
|
77
79
|
- spec/spec_helper.rb
|
78
80
|
- spec/sublime_sunippetter_dsl_spec.rb
|
79
81
|
- spec/sublime_sunippetter_spec.rb
|