sublime_sunippetter 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
  gem "rspec", "~> 2.14.1"
6
6
  gem "thor", "~> 0.18.1"
7
+ gem "simplecov", "~> 0.8.2"
data/README.md CHANGED
@@ -53,6 +53,8 @@ add :hige
53
53
  add :hoge1, :args1, :args2, "block@d"
54
54
  # if two args method and brace-block
55
55
  add :hoge2, :args1, :args2, "block@b"
56
+ # requires
57
+ add_requires 'hoge', 'hige'
56
58
  ~~~
57
59
 
58
60
  Third, you have to do is execute command 'suni'.
@@ -115,6 +117,32 @@ hoge2 ${1:args1}, ${2:args2} { |${9:args}|${0:block} }
115
117
  </snippet>
116
118
  ~~~
117
119
 
120
+ And
121
+
122
+ ~~~xml
123
+ <snippet>
124
+ <content><![CDATA[
125
+ require 'hoge'
126
+ ]]></content>
127
+ <tabTrigger>require hoge</tabTrigger>
128
+ <scope>source.java</scope>
129
+ <description>require hoge</description>
130
+ </snippet>
131
+ ~~~
132
+
133
+ And
134
+
135
+ ~~~xml
136
+ <snippet>
137
+ <content><![CDATA[
138
+ require 'hige'
139
+ ]]></content>
140
+ <tabTrigger>require hige</tabTrigger>
141
+ <scope>source.ruby</scope>
142
+ <description>require hige</description>
143
+ </snippet>
144
+ ~~~
145
+
118
146
  in 'C:/Users/user_name/AppData/Roaming/Sublime Text 2/Packages/User' directory.
119
147
 
120
148
  ## Use Generated Sunippet
@@ -122,6 +150,7 @@ in 'C:/Users/user_name/AppData/Roaming/Sublime Text 2/Packages/User' directory.
122
150
  <img src="./doc_image/sublime_sunippetter.gif" />
123
151
 
124
152
  ## History
153
+ * version 0.0.5 : enable require 'filename' generate.
125
154
  * version 0.0.4 : enable do-block, brace-block generate.
126
155
  * version 0.0.3 : question can use. for ex 'blank?'.
127
156
  * version 0.0.1 : first release.
@@ -27,6 +27,9 @@ module SublimeSunippetter
27
27
  # add :hoge1, :args1, :args2, "block@d"
28
28
  # if two args method and brace-block
29
29
  # add :hoge2, :args1, :args2, "block@b"
30
+
31
+ # require snippet
32
+ # add_requires 'file1', 'file2'
30
33
  EOS
31
34
 
32
35
  # sublime sunippet template
@@ -41,6 +44,18 @@ module SublimeSunippetter
41
44
  </snippet>
42
45
  EOS
43
46
 
47
+ # sublime sunippet require template
48
+ REQUIRE_SUNIPPET_TEMPLATE = <<-EOS
49
+ <snippet>
50
+ <content><![CDATA[
51
+ require '<%= require_file %>'
52
+ ]]></content>
53
+ <tabTrigger>require <%= require_file %></tabTrigger>
54
+ <scope><%= scope%></scope>
55
+ <description>require <%= require_file %></description>
56
+ </snippet>
57
+ EOS
58
+
44
59
  # generate Sunippetdefine to current directory.
45
60
  def init
46
61
  File.open("./#{DEFINE_FILE}", 'w') { |f|f.puts DEFINE_FILE_TEMPLATE }
@@ -62,6 +77,11 @@ module SublimeSunippetter
62
77
  filename = "#{dsl._output_path}/#{m.method_name.to_s.tr('?', '')}.sublime-snippet"
63
78
  File.open(filename, 'w:UTF-8') { |f|f.puts snippet }
64
79
  end
80
+
81
+ dsl.requires.each do |r|
82
+ require_snippet = get_require_snippet(r, dsl._scope)
83
+ File.open("require_#{r}.sublime-snippet", 'w:UTF-8') { |f|f.puts require_snippet }
84
+ end
65
85
  end
66
86
 
67
87
  private
@@ -79,7 +99,7 @@ module SublimeSunippetter
79
99
  def get_args_names(method)
80
100
  args = method.args
81
101
  args_names = ' '
82
- args.each_with_index {|a, i|args_names << "${#{i + 1}:#{a}}, "}
102
+ args.each_with_index { |a, i|args_names << "${#{i + 1}:#{a}}, " }
83
103
  args_names.chop!.chop! unless args.empty?
84
104
  end
85
105
 
@@ -96,6 +116,10 @@ end
96
116
  return '' unless method.has_brace_block
97
117
  ' { |${9:args}|${0:block} }'
98
118
  end
119
+
120
+ def get_require_snippet(require_file, scope)
121
+ ERB.new(REQUIRE_SUNIPPET_TEMPLATE).result(binding)
122
+ end
99
123
  end
100
124
 
101
125
  class SunippetterError < StandardError; end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # SublimeSunippetter
3
3
  module SublimeSunippetter
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.5'
5
5
  end
@@ -4,13 +4,14 @@ require 'target_method'
4
4
  module SublimeSunippetter
5
5
  # Dsl. this is dsl for Sunippetdefine.
6
6
  class Dsl
7
- attr_accessor :target_methods, :_scope, :_output_path
7
+ attr_accessor :target_methods, :_scope, :_output_path, :requires
8
8
 
9
9
  # init default values
10
10
  def initialize
11
11
  @target_methods = []
12
12
  @_scope = 'source.ruby'
13
13
  @_output_path = './'
14
+ @requires = []
14
15
  end
15
16
 
16
17
  # add sunippet information
@@ -27,6 +28,10 @@ module SublimeSunippetter
27
28
  end
28
29
  end
29
30
 
31
+ def add_requires(*filenames)
32
+ @requires = filenames
33
+ end
34
+
30
35
  # set sunippet scope
31
36
  def scope(_scope)
32
37
  return if _scope.nil?
@@ -67,6 +67,28 @@ describe SublimeSunippetter::Dsl do
67
67
  end
68
68
  end
69
69
 
70
+ cases_add_requires = [
71
+ {
72
+ case_no: 1,
73
+ require_files: ['hoge', 'hige'],
74
+ expecteds: ['hoge', 'hige']
75
+ },
76
+ ]
77
+
78
+ cases_add_requires.each do |c|
79
+ it "#add_requires case_no=#{c[:case_no]} add require_files=#{c[:require_files]}" do
80
+ # given
81
+ dsl = SublimeSunippetter::Dsl.new
82
+
83
+ # when
84
+ dsl.add_requires c[:require_files][0], c[:require_files][1]
85
+ actual = dsl.requires
86
+
87
+ # then
88
+ expect(actual).to eq(c[:expecteds])
89
+ end
90
+ end
91
+
70
92
  cases_scope = [
71
93
  {
72
94
  case_no: 1,
@@ -32,13 +32,22 @@ add :hige?
32
32
  add :hoge1, "block@b"
33
33
  add :hoge2, "block@d"
34
34
  add :hoge3, :args1, :args2, "block@b"
35
+ add_requires 'hoge', 'hige'
35
36
  EOS
36
37
 
37
38
  cases_generate_sunippets = [
38
39
  {
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'],
40
+ case_no: 1,
41
+ sunippetdefine: GENERATE_SUNIPPETS_CASE,
42
+ output_file_names: [
43
+ 'hoge.sublime-snippet',
44
+ 'hige.sublime-snippet',
45
+ 'hoge1.sublime-snippet',
46
+ 'hoge2.sublime-snippet',
47
+ 'hoge3.sublime-snippet',
48
+ 'require_hoge.sublime-snippet',
49
+ 'require_hige.sublime-snippet',
50
+ ],
42
51
  }
43
52
  ]
44
53
 
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec", "~> 2.14.1"
26
+ spec.add_development_dependency "simplecov", "~> 0.8.2"
26
27
  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
4
+ version: 0.0.5
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-22 00:00:00.000000000 Z
12
+ date: 2014-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &21219336 !ruby/object:Gem::Requirement
16
+ requirement: &21316788 !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: *21219336
24
+ version_requirements: *21316788
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &21218892 !ruby/object:Gem::Requirement
27
+ requirement: &21314676 !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: *21218892
35
+ version_requirements: *21314676
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &21218652 !ruby/object:Gem::Requirement
38
+ requirement: &21338628 !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: *21218652
46
+ version_requirements: *21338628
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &21218328 !ruby/object:Gem::Requirement
49
+ requirement: &21337452 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,18 @@ dependencies:
54
54
  version: 2.14.1
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *21218328
57
+ version_requirements: *21337452
58
+ - !ruby/object:Gem::Dependency
59
+ name: simplecov
60
+ requirement: &21336876 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 0.8.2
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *21336876
58
69
  description: SublimeSunippetter is generate Sublime Text2 simple sunippet from Sunippetfile
59
70
  DSL.
60
71
  email: