ruboty-megen 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c05bcd2387328a9cf771d91ff2fd3ef1b409a4b6
4
- data.tar.gz: 1ad553a82ddd898f6eb5ac03cd2b6b1bf6d473db
3
+ metadata.gz: b0b8e907e8d2da94d412bb0417e9de0f34dd7ae7
4
+ data.tar.gz: 8a8b547c2ae29b332a641a037418c83af3b6e403
5
5
  SHA512:
6
- metadata.gz: 6e488f8c9f1c34df4d917b349d20b93b7923ea331ba13d765462d5676737e21858f3840d9f667820e1b28edd851de08d6a81ea7e8ee87131b4c403e7d52c576b
7
- data.tar.gz: 7043af95e4069867ad73eb5146397c8cd60111a87bab3e19d88f71d018455b3997170367bd873fb70304aed990670476a38d373795d860525513dc37a625b466
6
+ metadata.gz: 49140940eff3dbb0ba1b25b8db275d8a1b87e5d76f601c2652436aa2cf4e4dd9ea35801e52424e7f85a6123286ed9c18d9a8d9e3997c6e5a4ab2d065df4b963e
7
+ data.tar.gz: ecaa7a2294dfcacbdef7f643a7b42fe956b450796fe0366a83841e9e3cf597f1943c8003cd757583cf9307b14946be014f405ed8197755a76636a95ab776e841
data/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ ## v.1.0.1
2
+ 2014/11/12
3
+
4
+ ### New Feature
5
+ * Add Link from Commands to Usage
6
+
7
+ ## v.1.0.0
8
+ 2014/11/10
9
+
10
+ ### New Feature
11
+ nothing
12
+
13
+ ### Update Feature
14
+ * Fix `ruboty-megen version` error
15
+
16
+ ## v.0.0.1
17
+ 2014/11/10
18
+
19
+ * first release
@@ -1,226 +1,227 @@
1
- # encoding: utf-8
2
- require 'erb'
3
-
4
- module Ruboty
5
- module Gen
6
- # ReadmeGen Core
7
- class Readme
8
- # rubocop:disable LineLength
9
- README = 'README.md'
10
- RUBOTY_MEGEN_FILE = 'Rubotyme'
11
- RUBOTY_MEGEN_TEMPLATE = <<-EOS
12
- # encoding: utf-8
13
-
14
- # user_name(github user name)
15
- # user_name is required
16
- # user_name allow only String
17
- # user_name's default value => "user_name"
18
- user_name "user_name"
19
-
20
- # gem_class_name
21
- # gem_class_name is required
22
- # gem_class_name allow only String
23
- # gem_class_name's default value => "your_gem_class_name"
24
- # ex: SampleGem (Ruboty::SampleGem)
25
- gem_class_name "your_gem_class_name"
26
-
27
- # gem_name
28
- # gem_name is required
29
- # gem_name allow only String
30
- # gem_name's default value => "your_gem_name"
31
- # ex: sample_gem (not ruboty-sample_gem)
32
- gem_name "your_gem_name"
33
-
34
- # title
35
- # title is required
36
- # title allow only String
37
- # title's default value => "title"
38
- # ex: output N line messages.
39
- title "title"
40
-
41
- # you can set multiple ENV variables
42
- env do |e|
43
- # name
44
- # name allow only String
45
- # name's default value => ""
46
- e.name "environment variable name"
47
-
48
- # description
49
- # description allow only String
50
- # description's default value => ""
51
- e.description ""
52
- end
53
-
54
- # you can set multiple dependencies
55
- dependency do |d|
56
- # name
57
- # name allow only String
58
- # name's default value => ""
59
- d.name ""
60
-
61
- # description
62
- # description allow only String
63
- # description's default value => ""
64
- d.description ""
65
- end
66
-
67
- # you can set multiple commands
68
- command do |c|
69
- # name
70
- # name allow only String
71
- # name's default value => ""
72
- c.name ""
73
-
74
- # pattern
75
- # pattern allow only String
76
- # pattern's default value => ""
77
- c.pattern ""
78
-
79
- # description
80
- # description allow only String
81
- # description's default value => ""
82
- c.description ""
83
- end
84
- EOS
85
-
86
- RUBOTY_README_TEMPLATE = <<-EOS
87
- # Ruboty::<%=gem_class_name%>
88
-
89
- An Ruboty Handler + Actions to <%=title%>.
90
-
91
- [Ruboty](https://github.com/r7kamura/ruboty) is Chat bot framework. Ruby + Bot = Ruboty
92
-
93
- ## Installation
94
-
95
- Add this line to your application's Gemfile:
96
-
97
- ```ruby
98
- gem 'ruboty-<%=gem_name%>'
99
- ```
100
-
101
- And then execute:
102
-
103
- $ bundle
104
-
105
- Or install it yourself as:
106
-
107
- $ gem install ruboty-<%=gem_name%>
108
-
109
-
110
- ## Commands
111
-
112
- |Command|Pattern|Description|
113
- |:--|:--|:--|
114
- <%=command_table%>
115
-
116
- ## Usage
117
- <%=usages%>
118
-
119
- ## ENV
120
-
121
- |Name|Description|
122
- |:--|:--|
123
- <%=env_table%>
124
-
125
- ## Dependency
126
-
127
- |Name|Description|
128
- |:--|:--|
129
- <%=dependency_table%>
130
-
131
- ## Contributing
132
-
133
- 1. Fork it ( https://github.com/<%=user_name%>/ruboty-<%=gem_name%>/fork )
134
- 2. Create your feature branch (`git checkout -b my-new-feature`)
135
- 3. Commit your changes (`git commit -am 'Add some feature'`)
136
- 4. Push to the branch (`git push origin my-new-feature`)
137
- 5. Create a new Pull Request
138
- EOS
139
- # rubocop:enable LineLength
140
-
141
- # generate Rubotymegenfile to current directory.
142
- def self.init
143
- File.open(RUBOTY_MEGEN_FILE, 'w') do |f|
144
- f.puts RUBOTY_MEGEN_TEMPLATE
145
- end
146
- end
147
-
148
- # generate ruboty README.md template.
149
- def self.generate
150
- src = read_dsl
151
- dsl = Ruboty::Dsl.new
152
- dsl.instance_eval src
153
- src = apply(dsl.ruboty_megen)
154
- File.open(README, 'w:utf-8') { |file|file.puts src }
155
- end
156
-
157
- def self.read_dsl
158
- File.open(RUBOTY_MEGEN_FILE) { |f|f.read }
159
- end
160
- private_class_method :read_dsl
161
-
162
- # rubocop:disable UselessAssignment
163
- def self.apply(config)
164
- gem_class_name = config.gem_class_name
165
- gem_name = config.gem_name
166
- title = config.title
167
- command_table = command_table(config.commands)
168
- usages = usages(config.commands)
169
- env_table = env_table(config.env)
170
- dependency_table = dependency_table(config.dependencies)
171
- user_name = config.user_name
172
-
173
- erb = ERB.new(RUBOTY_README_TEMPLATE)
174
- erb.result(binding)
175
- end
176
- private_class_method :apply
177
- # rubocop:enable UselessAssignment
178
-
179
- def self.command_table(commands)
180
- command_table = commands.each_with_object([]) do |e, memo|
181
- list = ['', e.read_name, e.read_pattern, e.read_description, '']
182
- list = normalize_markdown_table(list)
183
- memo << list.join('|')
184
- end
185
- command_table.join("\n")
186
- end
187
- private_class_method :command_table
188
-
189
- def self.usages(commands)
190
- usages = commands.each_with_object([]) do |e, memo|
191
- name = e.read_name
192
- description = e.read_description
193
- row = ["### #{name}", "* #{description}", '', '~~~', '', '~~~']
194
- memo << row.join("\n")
195
- end
196
- usages.join("\n\n")
197
- end
198
- private_class_method :usages
199
-
200
- def self.env_table(env)
201
- env_table = env.each_with_object([]) do |e, memo|
202
- list = ['', e.read_name, e.read_description, '']
203
- list = normalize_markdown_table(list)
204
- memo << list.join('|')
205
- end
206
- env_table.join("\n")
207
- end
208
- private_class_method :env_table
209
-
210
- def self.dependency_table(dependencies)
211
- dependency_table = dependencies.each_with_object([]) do |e, memo|
212
- list = ['', e.read_name, e.read_description, '']
213
- list = normalize_markdown_table(list)
214
- memo << list.join('|')
215
- end
216
- dependency_table.join("\n")
217
- end
218
- private_class_method :dependency_table
219
-
220
- def self.normalize_markdown_table(texts)
221
- texts.map { |e| e.gsub('|', '&#124;') }
222
- end
223
- private_class_method :normalize_markdown_table
224
- end
225
- end
226
- end
1
+ # encoding: utf-8
2
+ require 'erb'
3
+
4
+ module Ruboty
5
+ module Gen
6
+ # ReadmeGen Core
7
+ class Readme
8
+ # rubocop:disable LineLength
9
+ README = 'README.md'
10
+ RUBOTY_MEGEN_FILE = 'Rubotyme'
11
+ RUBOTY_MEGEN_TEMPLATE = <<-EOS
12
+ # encoding: utf-8
13
+
14
+ # user_name(github user name)
15
+ # user_name is required
16
+ # user_name allow only String
17
+ # user_name's default value => "user_name"
18
+ user_name "user_name"
19
+
20
+ # gem_class_name
21
+ # gem_class_name is required
22
+ # gem_class_name allow only String
23
+ # gem_class_name's default value => "your_gem_class_name"
24
+ # ex: SampleGem (Ruboty::SampleGem)
25
+ gem_class_name "your_gem_class_name"
26
+
27
+ # gem_name
28
+ # gem_name is required
29
+ # gem_name allow only String
30
+ # gem_name's default value => "your_gem_name"
31
+ # ex: sample_gem (not ruboty-sample_gem)
32
+ gem_name "your_gem_name"
33
+
34
+ # title
35
+ # title is required
36
+ # title allow only String
37
+ # title's default value => "title"
38
+ # ex: output N line messages.
39
+ title "title"
40
+
41
+ # you can set multiple ENV variables
42
+ env do |e|
43
+ # name
44
+ # name allow only String
45
+ # name's default value => ""
46
+ e.name "environment variable name"
47
+
48
+ # description
49
+ # description allow only String
50
+ # description's default value => ""
51
+ e.description ""
52
+ end
53
+
54
+ # you can set multiple dependencies
55
+ dependency do |d|
56
+ # name
57
+ # name allow only String
58
+ # name's default value => ""
59
+ d.name ""
60
+
61
+ # description
62
+ # description allow only String
63
+ # description's default value => ""
64
+ d.description ""
65
+ end
66
+
67
+ # you can set multiple commands
68
+ command do |c|
69
+ # name
70
+ # name allow only String
71
+ # name's default value => ""
72
+ c.name ""
73
+
74
+ # pattern
75
+ # pattern allow only String
76
+ # pattern's default value => ""
77
+ c.pattern ""
78
+
79
+ # description
80
+ # description allow only String
81
+ # description's default value => ""
82
+ c.description ""
83
+ end
84
+ EOS
85
+
86
+ RUBOTY_README_TEMPLATE = <<-EOS
87
+ # Ruboty::<%=gem_class_name%>
88
+
89
+ An Ruboty Handler + Actions to <%=title%>.
90
+
91
+ [Ruboty](https://github.com/r7kamura/ruboty) is Chat bot framework. Ruby + Bot = Ruboty
92
+
93
+ ## Installation
94
+
95
+ Add this line to your application's Gemfile:
96
+
97
+ ```ruby
98
+ gem 'ruboty-<%=gem_name%>'
99
+ ```
100
+
101
+ And then execute:
102
+
103
+ $ bundle
104
+
105
+ Or install it yourself as:
106
+
107
+ $ gem install ruboty-<%=gem_name%>
108
+
109
+
110
+ ## Commands
111
+
112
+ |Command|Pattern|Description|
113
+ |:--|:--|:--|
114
+ <%=command_table%>
115
+
116
+ ## Usage
117
+ <%=usages%>
118
+
119
+ ## ENV
120
+
121
+ |Name|Description|
122
+ |:--|:--|
123
+ <%=env_table%>
124
+
125
+ ## Dependency
126
+
127
+ |Name|Description|
128
+ |:--|:--|
129
+ <%=dependency_table%>
130
+
131
+ ## Contributing
132
+
133
+ 1. Fork it ( https://github.com/<%=user_name%>/ruboty-<%=gem_name%>/fork )
134
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
135
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
136
+ 4. Push to the branch (`git push origin my-new-feature`)
137
+ 5. Create a new Pull Request
138
+ EOS
139
+ # rubocop:enable LineLength
140
+
141
+ # generate Rubotymegenfile to current directory.
142
+ def self.init
143
+ File.open(RUBOTY_MEGEN_FILE, 'w') do |f|
144
+ f.puts RUBOTY_MEGEN_TEMPLATE
145
+ end
146
+ end
147
+
148
+ # generate ruboty README.md template.
149
+ def self.generate
150
+ src = read_dsl
151
+ dsl = Ruboty::Dsl.new
152
+ dsl.instance_eval src
153
+ src = apply(dsl.ruboty_megen)
154
+ File.open(README, 'w:utf-8') { |file|file.puts src }
155
+ end
156
+
157
+ def self.read_dsl
158
+ File.open(RUBOTY_MEGEN_FILE) { |f|f.read }
159
+ end
160
+ private_class_method :read_dsl
161
+
162
+ # rubocop:disable UselessAssignment
163
+ def self.apply(config)
164
+ gem_class_name = config.gem_class_name
165
+ gem_name = config.gem_name
166
+ title = config.title
167
+ command_table = command_table(config.commands)
168
+ usages = usages(config.commands)
169
+ env_table = env_table(config.env)
170
+ dependency_table = dependency_table(config.dependencies)
171
+ user_name = config.user_name
172
+
173
+ erb = ERB.new(RUBOTY_README_TEMPLATE)
174
+ erb.result(binding)
175
+ end
176
+ private_class_method :apply
177
+ # rubocop:enable UselessAssignment
178
+
179
+ def self.command_table(commands)
180
+ command_table = commands.each_with_object([]) do |e, memo|
181
+ command_link = "[#{e.read_name}](##{e.read_name})"
182
+ list = ['', command_link, e.read_pattern, e.read_description, '']
183
+ list = normalize_markdown_table(list)
184
+ memo << list.join('|')
185
+ end
186
+ command_table.join("\n")
187
+ end
188
+ private_class_method :command_table
189
+
190
+ def self.usages(commands)
191
+ usages = commands.each_with_object([]) do |e, memo|
192
+ name = e.read_name
193
+ description = e.read_description
194
+ row = ["### #{name}", "* #{description}", '', '~~~', '', '~~~']
195
+ memo << row.join("\n")
196
+ end
197
+ usages.join("\n\n")
198
+ end
199
+ private_class_method :usages
200
+
201
+ def self.env_table(env)
202
+ env_table = env.each_with_object([]) do |e, memo|
203
+ list = ['', e.read_name, e.read_description, '']
204
+ list = normalize_markdown_table(list)
205
+ memo << list.join('|')
206
+ end
207
+ env_table.join("\n")
208
+ end
209
+ private_class_method :env_table
210
+
211
+ def self.dependency_table(dependencies)
212
+ dependency_table = dependencies.each_with_object([]) do |e, memo|
213
+ list = ['', e.read_name, e.read_description, '']
214
+ list = normalize_markdown_table(list)
215
+ memo << list.join('|')
216
+ end
217
+ dependency_table.join("\n")
218
+ end
219
+ private_class_method :dependency_table
220
+
221
+ def self.normalize_markdown_table(texts)
222
+ texts.map { |e| e.gsub('|', '&#124;') }
223
+ end
224
+ private_class_method :normalize_markdown_table
225
+ end
226
+ end
227
+ end
@@ -1,7 +1,7 @@
1
- # RubotyMegen
2
- module Ruboty
3
- # Gen
4
- module Gen
5
- VERSION = '1.0.0'
6
- end
7
- end
1
+ # RubotyMegen
2
+ module Ruboty
3
+ # Gen
4
+ module Gen
5
+ VERSION = '1.0.1'
6
+ end
7
+ end
data/sample/README.md CHANGED
@@ -1,66 +1,66 @@
1
- # Ruboty::Ume
2
-
3
- An Ruboty Handler + Actions to An Ruboty Handler + Actions to output N line messages..
4
-
5
- [Ruboty](https://github.com/r7kamura/ruboty) is Chat bot framework. Ruby + Bot = Ruboty
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'ruboty-ume'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install ruboty-ume
22
-
23
-
24
- ## Commands
25
-
26
- |Command|Pattern|Description|
27
- |:--|:--|:--|
28
- |ume|/ume (?<count>.*?)z/|output empty message N lines (<count> times)|
29
- |umec|/umec (?<text>.+?) (?<count>.*?)z/|output <text> message N lines (<count> times)|
30
-
31
- ## Usage
32
- ### ume
33
- * output empty message N lines (<count> times)
34
-
35
- ~~~
36
-
37
- ~~~
38
-
39
- ### umec
40
- * output <text> message N lines (<count> times)
41
-
42
- ~~~
43
-
44
- ~~~
45
-
46
- ## ENV
47
-
48
- |Name|Description|
49
- |:--|:--|
50
- |ENV1|ENV1 desc|
51
- |ENV2|ENV2 desc|
52
-
53
- ## Dependency
54
-
55
- |Name|Description|
56
- |:--|:--|
57
- |dependency1|dependency1 description|
58
- |dependency2|dependency2 description|
59
-
60
- ## Contributing
61
-
62
- 1. Fork it ( https://github.com/tbpgr/ruboty-ume/fork )
63
- 2. Create your feature branch (`git checkout -b my-new-feature`)
64
- 3. Commit your changes (`git commit -am 'Add some feature'`)
65
- 4. Push to the branch (`git push origin my-new-feature`)
66
- 5. Create a new Pull Request
1
+ # Ruboty::Ume
2
+
3
+ An Ruboty Handler + Actions to An Ruboty Handler + Actions to output N line messages..
4
+
5
+ [Ruboty](https://github.com/r7kamura/ruboty) is Chat bot framework. Ruby + Bot = Ruboty
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruboty-ume'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ruboty-ume
22
+
23
+
24
+ ## Commands
25
+
26
+ |Command|Pattern|Description|
27
+ |:--|:--|:--|
28
+ |[ume](#ume)|/ume (?<count>.*?)z/|output empty message N lines (<count> times)|
29
+ |[umec](#umec)|/umec (?<text>.+?) (?<count>.*?)z/|output <text> message N lines (<count> times)|
30
+
31
+ ## Usage
32
+ ### ume
33
+ * output empty message N lines (<count> times)
34
+
35
+ ~~~
36
+
37
+ ~~~
38
+
39
+ ### umec
40
+ * output <text> message N lines (<count> times)
41
+
42
+ ~~~
43
+
44
+ ~~~
45
+
46
+ ## ENV
47
+
48
+ |Name|Description|
49
+ |:--|:--|
50
+ |ENV1|ENV1 desc|
51
+ |ENV2|ENV2 desc|
52
+
53
+ ## Dependency
54
+
55
+ |Name|Description|
56
+ |:--|:--|
57
+ |dependency1|dependency1 description|
58
+ |dependency2|dependency2 description|
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it ( https://github.com/tbpgr/ruboty-ume/fork )
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 5. Create a new Pull Request
@@ -1,162 +1,162 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require 'ruboty/gen'
4
-
5
- # rubocop:disable LineLength, UnusedMethodArgument
6
- describe Ruboty::Gen::Readme do
7
- context :generate do
8
- let(:tmp) { 'tmp' }
9
- let(:ruboty_megen_template) do
10
- template = <<-EOS
11
- # encoding: utf-8
12
-
13
- user_name 'tbpgr'
14
- gem_class_name 'SampleGem'
15
- gem_name 'sample_gem'
16
- title 'output sample messages'
17
-
18
- env do |e|
19
- e.name 'ENV1'
20
- e.description 'ENV1 description'
21
- end
22
-
23
- env do |e|
24
- e.name 'ENV2'
25
- e.description 'ENV2 description'
26
- end
27
-
28
- dependency do |d|
29
- d.name 'dependency1 name'
30
- d.description 'dependency1 description'
31
- end
32
-
33
- dependency do |d|
34
- d.name 'dependency2 name'
35
- d.description 'dependency2 description'
36
- end
37
-
38
- command do |c|
39
- c.name 'command1'
40
- c.pattern '/command1 | hoge/'
41
- c.description 'command1 description'
42
- end
43
-
44
- command do |c|
45
- c.name 'command2'
46
- c.pattern '/command2 | hoge/'
47
- c.description 'command2 description'
48
- end
49
- EOS
50
- template
51
- end
52
-
53
- cases = [
54
- {
55
- case_no: 1,
56
- case_title: 'valid case',
57
- expected: <<-EOS
58
- # Ruboty::SampleGem
59
-
60
- An Ruboty Handler + Actions to output sample messages.
61
-
62
- [Ruboty](https://github.com/r7kamura/ruboty) is Chat bot framework. Ruby + Bot = Ruboty
63
-
64
- ## Installation
65
-
66
- Add this line to your application's Gemfile:
67
-
68
- ```ruby
69
- gem 'ruboty-sample_gem'
70
- ```
71
-
72
- And then execute:
73
-
74
- $ bundle
75
-
76
- Or install it yourself as:
77
-
78
- $ gem install ruboty-sample_gem
79
-
80
-
81
- ## Commands
82
-
83
- |Command|Pattern|Description|
84
- |:--|:--|:--|
85
- |command1|/command1 &#124; hoge/|command1 description|
86
- |command2|/command2 &#124; hoge/|command2 description|
87
-
88
- ## Usage
89
- ### command1
90
- * command1 description
91
-
92
- ~~~
93
-
94
- ~~~
95
-
96
- ### command2
97
- * command2 description
98
-
99
- ~~~
100
-
101
- ~~~
102
-
103
- ## ENV
104
-
105
- |Name|Description|
106
- |:--|:--|
107
- |ENV1|ENV1 description|
108
- |ENV2|ENV2 description|
109
-
110
- ## Dependency
111
-
112
- |Name|Description|
113
- |:--|:--|
114
- |dependency1 name|dependency1 description|
115
- |dependency2 name|dependency2 description|
116
-
117
- ## Contributing
118
-
119
- 1. Fork it ( https://github.com/tbpgr/ruboty-sample_gem/fork )
120
- 2. Create your feature branch (`git checkout -b my-new-feature`)
121
- 3. Commit your changes (`git commit -am 'Add some feature'`)
122
- 4. Push to the branch (`git push origin my-new-feature`)
123
- 5. Create a new Pull Request
124
- EOS
125
- }
126
- ]
127
-
128
- cases.each do |c|
129
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
130
- begin
131
- case_before c
132
-
133
- # -- given --
134
- # nothing
135
-
136
- # -- when --
137
- Ruboty::Gen::Readme.generate
138
- actual = File.open(Ruboty::Gen::Readme::README, 'r:utf-8') { |e|e.read }
139
-
140
- # -- then --
141
- expect(actual).to eq(c[:expected])
142
- ensure
143
- case_after c
144
- end
145
- end
146
-
147
- def case_before(_c)
148
- FileUtils.mkdir_p(tmp) unless Dir.exist? tmp
149
- Dir.chdir(tmp)
150
- File.open(Ruboty::Gen::Readme::RUBOTY_MEGEN_FILE, 'w:utf-8') do |file|
151
- file.puts ruboty_megen_template
152
- end
153
- end
154
-
155
- def case_after(_c)
156
- Dir.chdir('../')
157
- FileUtils.rm_rf(tmp) if Dir.exist? tmp
158
- end
159
- end
160
- end
161
- end
162
- # rubocop:enable LineLength, UnusedMethodArgument
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'ruboty/gen'
4
+
5
+ # rubocop:disable LineLength, UnusedMethodArgument
6
+ describe Ruboty::Gen::Readme do
7
+ context :generate do
8
+ let(:tmp) { 'tmp' }
9
+ let(:ruboty_megen_template) do
10
+ template = <<-EOS
11
+ # encoding: utf-8
12
+
13
+ user_name 'tbpgr'
14
+ gem_class_name 'SampleGem'
15
+ gem_name 'sample_gem'
16
+ title 'output sample messages'
17
+
18
+ env do |e|
19
+ e.name 'ENV1'
20
+ e.description 'ENV1 description'
21
+ end
22
+
23
+ env do |e|
24
+ e.name 'ENV2'
25
+ e.description 'ENV2 description'
26
+ end
27
+
28
+ dependency do |d|
29
+ d.name 'dependency1 name'
30
+ d.description 'dependency1 description'
31
+ end
32
+
33
+ dependency do |d|
34
+ d.name 'dependency2 name'
35
+ d.description 'dependency2 description'
36
+ end
37
+
38
+ command do |c|
39
+ c.name 'command1'
40
+ c.pattern '/command1 | hoge/'
41
+ c.description 'command1 description'
42
+ end
43
+
44
+ command do |c|
45
+ c.name 'command2'
46
+ c.pattern '/command2 | hoge/'
47
+ c.description 'command2 description'
48
+ end
49
+ EOS
50
+ template
51
+ end
52
+
53
+ cases = [
54
+ {
55
+ case_no: 1,
56
+ case_title: 'valid case',
57
+ expected: <<-EOS
58
+ # Ruboty::SampleGem
59
+
60
+ An Ruboty Handler + Actions to output sample messages.
61
+
62
+ [Ruboty](https://github.com/r7kamura/ruboty) is Chat bot framework. Ruby + Bot = Ruboty
63
+
64
+ ## Installation
65
+
66
+ Add this line to your application's Gemfile:
67
+
68
+ ```ruby
69
+ gem 'ruboty-sample_gem'
70
+ ```
71
+
72
+ And then execute:
73
+
74
+ $ bundle
75
+
76
+ Or install it yourself as:
77
+
78
+ $ gem install ruboty-sample_gem
79
+
80
+
81
+ ## Commands
82
+
83
+ |Command|Pattern|Description|
84
+ |:--|:--|:--|
85
+ |[command1](#command1)|/command1 &#124; hoge/|command1 description|
86
+ |[command2](#command2)|/command2 &#124; hoge/|command2 description|
87
+
88
+ ## Usage
89
+ ### command1
90
+ * command1 description
91
+
92
+ ~~~
93
+
94
+ ~~~
95
+
96
+ ### command2
97
+ * command2 description
98
+
99
+ ~~~
100
+
101
+ ~~~
102
+
103
+ ## ENV
104
+
105
+ |Name|Description|
106
+ |:--|:--|
107
+ |ENV1|ENV1 description|
108
+ |ENV2|ENV2 description|
109
+
110
+ ## Dependency
111
+
112
+ |Name|Description|
113
+ |:--|:--|
114
+ |dependency1 name|dependency1 description|
115
+ |dependency2 name|dependency2 description|
116
+
117
+ ## Contributing
118
+
119
+ 1. Fork it ( https://github.com/tbpgr/ruboty-sample_gem/fork )
120
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
121
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
122
+ 4. Push to the branch (`git push origin my-new-feature`)
123
+ 5. Create a new Pull Request
124
+ EOS
125
+ }
126
+ ]
127
+
128
+ cases.each do |c|
129
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
130
+ begin
131
+ case_before c
132
+
133
+ # -- given --
134
+ # nothing
135
+
136
+ # -- when --
137
+ Ruboty::Gen::Readme.generate
138
+ actual = File.open(Ruboty::Gen::Readme::README, 'r:utf-8') { |e|e.read }
139
+
140
+ # -- then --
141
+ expect(actual).to eq(c[:expected])
142
+ ensure
143
+ case_after c
144
+ end
145
+ end
146
+
147
+ def case_before(_c)
148
+ FileUtils.mkdir_p(tmp) unless Dir.exist? tmp
149
+ Dir.chdir(tmp)
150
+ File.open(Ruboty::Gen::Readme::RUBOTY_MEGEN_FILE, 'w:utf-8') do |file|
151
+ file.puts ruboty_megen_template
152
+ end
153
+ end
154
+
155
+ def case_after(_c)
156
+ Dir.chdir('../')
157
+ FileUtils.rm_rf(tmp) if Dir.exist? tmp
158
+ end
159
+ end
160
+ end
161
+ end
162
+ # rubocop:enable LineLength, UnusedMethodArgument
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-megen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tbpgr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-10 00:00:00.000000000 Z
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -92,6 +92,7 @@ files:
92
92
  - .rspec
93
93
  - .rubocop.yml
94
94
  - .travis.yml
95
+ - CHANGELOG.md
95
96
  - Gemfile
96
97
  - LICENSE.txt
97
98
  - README.md