grape-doc 0.0.1.alpha → 0.1.0

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.
@@ -0,0 +1,20 @@
1
+ require_relative 'test_helper'
2
+ describe 'Dummy test for rack-test-poc' do
3
+
4
+ include Rack::Test::Methods
5
+
6
+ def app
7
+ TestAPI1
8
+ end
9
+
10
+ specify 'test the get call' do
11
+
12
+ get '/hello',test: 'hy'
13
+ last_response.status.must_be :==, 200
14
+
15
+ get '/hello.json'
16
+ last_response.status.must_be :==, 200
17
+
18
+ end
19
+
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-29 00:00:00.000000000 Z
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rack-test
56
+ name: loader
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,21 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rack-test-poc
70
+ name: RedCloth
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rack-test-poc
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 1.0.2
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 1.0.2
83
111
  description: " Documentation generator for Grape module compatible with Redmine and
84
112
  Github formats "
85
113
  email:
@@ -96,8 +124,22 @@ files:
96
124
  - grape-doc.gemspec
97
125
  - lib/grape-doc.rb
98
126
  - lib/grape/doc.rb
99
- - lib/grape/doc/logic.rb
100
- - lib/grape/doc/mpatch.rb
127
+ - lib/grape/doc/doc_class.rb
128
+ - lib/grape/doc/doc_class/header.rb
129
+ - lib/grape/doc/doc_class/link.rb
130
+ - lib/grape/doc/doc_class/list.rb
131
+ - lib/grape/doc/doc_class/parser.rb
132
+ - lib/grape/doc/doc_class/raw.rb
133
+ - lib/grape/doc/doc_class/sidebar.rb
134
+ - lib/grape/doc/doc_class/table.rb
135
+ - lib/grape/doc/generator.rb
136
+ - lib/grape/doc/helper.rb
137
+ - lib/grape/doc/prototype.rb
138
+ - test/sample.html
139
+ - test/test_doc_gen.rb
140
+ - test/test_helper.rb
141
+ - test/test_object_space_collector.rb
142
+ - test/test_sample_api.rb
101
143
  homepage: https://github.com/adamluzsi/grape-doc
102
144
  licenses: []
103
145
  metadata: {}
@@ -112,14 +154,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
154
  version: '0'
113
155
  required_rubygems_version: !ruby/object:Gem::Requirement
114
156
  requirements:
115
- - - ">"
157
+ - - ">="
116
158
  - !ruby/object:Gem::Version
117
- version: 1.3.1
159
+ version: '0'
118
160
  requirements: []
119
161
  rubyforge_project:
120
162
  rubygems_version: 2.2.2
121
163
  signing_key:
122
164
  specification_version: 4
123
165
  summary: Documentation generator for Grape module
124
- test_files: []
166
+ test_files:
167
+ - test/sample.html
168
+ - test/test_doc_gen.rb
169
+ - test/test_helper.rb
170
+ - test/test_object_space_collector.rb
171
+ - test/test_sample_api.rb
125
172
  has_rdoc:
@@ -1,495 +0,0 @@
1
- module GrapeDoc
2
- module Extend
3
- module Doc
4
-
5
- # helpers for doc generation
6
- def wiki_body(route,wrapper_begin,wrapper_end,wrapper_close)
7
-
8
- require 'grape/doc/mpatch'
9
-
10
- description_key= :body
11
- tmp_array= Array.new()
12
- params= nil
13
- evalue= nil
14
- content_type= nil
15
-
16
- #if route.route_path == "/booking/request(.:format)"
17
- # debugger
18
- #end
19
-
20
- case true
21
-
22
- when route.route_description.class <= ::String
23
- params= route.route_params
24
-
25
- when route.route_description.class <= ::Hash
26
-
27
- if !route.route_description[:content_type].nil?
28
- content_type= route.route_description[:content_type]
29
- end
30
-
31
- if description_key.nil?
32
- params= route.route_params
33
- evalue= "value[:type]"
34
- else
35
- params= route.route_description[description_key]
36
- evalue= "value"
37
- end
38
-
39
- when route.route_description.class <= ::NilClass
40
- params= route.route_params
41
- params ||= "no return"
42
- content_type= "TXT"
43
-
44
- else
45
- params= route.route_params
46
- content_type= "TXT"
47
-
48
- end
49
-
50
- case true
51
-
52
- when params.class <= ::Hash
53
-
54
- if params == route.route_params
55
- tmp_hash= Hash.new
56
- params.each do |key,value|
57
- tmp_hash[key]= value[:type].to_s
58
- end
59
- params= tmp_hash
60
- end
61
-
62
- params = params.convert_all_value_to_grape_dsl_format
63
-
64
- when params.class <= ::Class
65
- begin
66
- if params.to_s.include? '::'
67
- if params.to_s.downcase.include? 'boolean'
68
- params= params.to_s.split('::').last
69
- end
70
- end
71
-
72
- content_type= "TXT"
73
- end
74
-
75
- when params.class <= ::String
76
- content_type= "TXT"
77
-
78
- else
79
- begin
80
- params= "no params spec"
81
- content_type= "TXT"
82
- end
83
-
84
- end
85
-
86
- content_type ||= 'TXT'
87
- content_type = content_type.keys if content_type.class <= ::Hash
88
-
89
- [*content_type].each do |one_content_type|
90
-
91
- case one_content_type.to_s.downcase
92
-
93
- when 'json'
94
- begin
95
-
96
- tmp_array.push [wrapper_begin,one_content_type.to_s,wrapper_end].join
97
-
98
- require 'json'
99
-
100
- formatted_string= params.to_json
101
-
102
- {
103
- '{' => "{\n",
104
- '}' => "\n}",
105
- ',' => ",\n"
106
- }.each do |from,to|
107
- formatted_string.gsub!(from,to)
108
- end
109
-
110
- formatted_string.gsub!(/^"/," \"")
111
- tmp_array.push formatted_string
112
- tmp_array.push wrapper_close
113
-
114
- end
115
-
116
- when "txt"
117
- tmp_array.push(params.inspect)
118
-
119
- end
120
-
121
- end
122
-
123
- return tmp_array
124
-
125
- end
126
-
127
- # this method help create from grape params and description a ppt like redmine wiki doc
128
- # Usage:
129
- #
130
- ##> example variable for description (hash obj)
131
- #description= Hash.new
132
- #
133
- ##> optional -> :description
134
- #description[:desc]= String.new
135
- #
136
- ##> response body like if JSON than a ruby Hash obj with the Structure and the values are the types
137
- #description[:body]= Hash.new
138
- #
139
- ##> response body code type -> like json usually same as content_type (format :xy)
140
- #description[:content_type]= String.new #> "JSON"
141
- #
142
- #desc description
143
- #params do
144
- # optional :blabla, :type => String, :desc => "bla bla desc"
145
- # requires :xy, type: String, desc: "XY desc"
146
- #end
147
- #get "xy" do
148
- #
149
- #end
150
- #
151
- ##>---------------------------------------------------------------------------------------------------
152
- #> OR the classic
153
- #desc "My awsome String Description"
154
- #params do
155
- # optional :blabla, :type => String, :desc => "bla bla desc"
156
- # requires :xy, type: String, desc: "XY desc"
157
- #end
158
- #delete "xy" do
159
- #
160
- #end
161
- #
162
- ##>---------------------------------------------------------------------
163
- ## For the method use
164
- #
165
- ## for a targeted specified class
166
- #Grape.create_redmine_wiki_doc target_class: REST::API,
167
- # path: File.expand_path(File.join(File.dirname(__FILE__),"test_file.txt"))
168
- #
169
- ## for all grape subclass (directs and indirects)
170
- #Grape.create_redmine_wiki_doc path: File.expand_path(File.join(File.dirname(__FILE__),"test_file.txt"))
171
- #
172
- def create_wiki_doc(*args)
173
-
174
- # default set in args
175
- begin
176
-
177
- args= Hash[*args]
178
- args.dup.each do |key,value|
179
- if key.class != Symbol
180
- args[key.to_s.to_sym]= value
181
- args.delete key
182
- end
183
- end
184
-
185
- if args[:path].nil?
186
- raise ArgumentError,"You must set a file path with a file name in order to create documentation for grape!"
187
- end
188
-
189
- args[:desc_files] ||= Array.new
190
-
191
- [:desc,:desc_file,:extra_desc_file].each do |one_key|
192
-
193
- args[:desc_files] += args[(one_key.to_s+"s").to_sym] if args[(one_key.to_s+"s").to_sym].class == Array
194
- args[:desc_files].push(args[one_key]) if args[one_key].class == String
195
-
196
- end
197
-
198
- args[:type] ||= args[:doc_type]
199
- args[:type] ||= 'wiki'
200
-
201
- #args[:path],
202
- #args[:extra_desc_file]
203
- #args[:target_class]
204
- #args[:type]
205
-
206
- end
207
-
208
-
209
- # defaults
210
- begin
211
-
212
- uni_tab= ""
213
- case args[:type].to_s.downcase
214
-
215
- when "redmine","redmine_wiki","redmine-wiki","redminewiki"
216
- begin
217
-
218
- mid_tab= " "*3
219
-
220
- bsym= "*"
221
- isym= "_"
222
-
223
- htsym= "* "
224
- mtsym= htsym[0]*2 +" "
225
- stsym= htsym[0]*3 +" "
226
-
227
- hheader= "h3. "
228
- mheader= "h4. "
229
- sheader= "h5. "
230
-
231
- container_markup_begin= "<pre><code class=\""
232
- container_markup_end= "\">"
233
- container_markup_close= "</code></pre>"
234
-
235
- toc_mark= "\n{{>toc}}\n"
236
-
237
- end
238
-
239
- when "github","wiki","md"
240
- begin
241
-
242
- mid_tab= " "*3
243
-
244
- bsym= "*"
245
- isym= "_"
246
-
247
- htsym= "* "
248
- mtsym= " * "
249
- stsym= " * "
250
-
251
- hheader= "## "
252
- mheader= "### "
253
- sheader= "#### "
254
-
255
- container_markup_begin= "```"
256
- container_markup_end= ""
257
- container_markup_close= "```"
258
- toc_mark= ""
259
-
260
- end
261
-
262
- else
263
- raise ArgumentError, "invalid :type has been set, try github or redmine"
264
-
265
- end
266
-
267
- end
268
-
269
- # site name
270
- begin
271
- write_out_array = Array.new
272
- write_out_array.push "#{hheader}#{$0} REST Interface Documentation\n\n"
273
- end
274
-
275
- # description
276
- begin
277
- args[:desc_files].each do |extra_desc_file_path|
278
-
279
- write_out_array.push "#{sheader}#{extra_desc_file_path.split(File::Separator).last.split('.')[0].camelcase}\n"
280
- write_out_array.push " "+File.open(extra_desc_file_path,"r").read+"\n"
281
-
282
- end
283
- end
284
-
285
- # table of contents
286
- begin
287
- write_out_array.push toc_mark
288
- end
289
-
290
- # classes array
291
- begin
292
- rest_models= Array.new
293
- end
294
- if args[:target_class].nil?
295
- Grape::API.each_subclass do |one_class|
296
- rest_models.push(one_class)
297
- end
298
- else
299
- if args[:target_class].class != Class && args[:target_class] != nil
300
- raise ArgumentError, "invalid input :target_class is not a Class obj"
301
- end
302
- rest_models.push(args[:target_class])
303
- end
304
-
305
- rest_models.each do |rest_api_model|
306
- next if Grape::API == rest_api_model
307
- rest_api_model.routes.map do |route|
308
-
309
-
310
- method_name= "#{hheader}Request: #{route.route_path} call: #{route.route_method.to_s.downcase} part"
311
-
312
- # check that does the method already in the documentation
313
- unless write_out_array.include?(method_name)
314
-
315
- # create call name
316
- begin
317
- write_out_array.push method_name
318
- end
319
-
320
- # request
321
- begin
322
-
323
- # create request description
324
- begin
325
- write_out_array.push("\n"+(uni_tab*1)+"#{mheader}Request description")
326
- case true
327
-
328
- when route.route_description.class <= String
329
- route.route_description.each_line do |one_line|
330
- write_out_array.push((uni_tab*2)+htsym+one_line.chomp)
331
- end
332
-
333
- when route.route_description.class <= Hash
334
- begin
335
-
336
- description_msg = nil
337
-
338
- [:d,:desc,:description].each do |sym|
339
- description_msg ||= route.route_description[sym]
340
- end
341
-
342
- description_msg ||= "No description available for this path"
343
- description_msg= [*description_msg]
344
-
345
- description_msg.dup.each do |element|
346
- next unless element.include?("\n")
347
-
348
- index_n= description_msg.index(element)
349
- description_msg.delete(element)
350
- new_elements= element.split("\n")
351
- new_elements.size.times do |counter_n|
352
- description_msg.insert(index_n + counter_n - 1, new_elements[counter_n - 1] )
353
- end
354
-
355
- end
356
-
357
- description_msg.each do |one_line|
358
- write_out_array.push((uni_tab*2)+htsym+one_line.chomp)
359
- end
360
-
361
- end
362
-
363
-
364
- end
365
- end
366
-
367
- # pre request
368
- begin
369
- write_out_array.push("\n#{mheader}request\n")
370
- end
371
-
372
- # create route method
373
- begin
374
- write_out_array.push((uni_tab*2)+"#{htsym}#{bsym}method:#{bsym}#{mid_tab} #{route.route_method}")
375
- end
376
-
377
- # create route path
378
- begin
379
- write_out_array.push((uni_tab*2)+"#{htsym}#{bsym}path:#{bsym}#{mid_tab} #{route.route_path}")
380
- end
381
-
382
- # create route content_type
383
- begin
384
- write_out_array.push((uni_tab*2)+"#{htsym}#{bsym}headers:#{bsym}#{mid_tab}")
385
- rest_api_model.content_types.each do |one_format_type,one_format_header|
386
- write_out_array.push "#{mtsym}#{uni_tab*2}#{one_format_header}"
387
- end
388
-
389
- write_out_array.push ""
390
- end
391
-
392
- # parameters
393
- begin
394
- new_docs_element= Array.new
395
- if route.route_params.count == 0
396
- new_docs_element.push " No specified or special params"
397
- else
398
- new_docs_element.push ""
399
- new_docs_element.push "#{htsym}#{isym}#{bsym}Parameters#{bsym}#{isym}"
400
- route.route_params.each do |key,value|
401
- new_docs_element.push "#{mtsym}#{isym}#{key}#{isym}"
402
- value.each do |value_key,value_value|
403
- new_docs_element.push "#{stsym}#{value_key}: #{value_value}"
404
- end
405
- end
406
- new_docs_element.push "\n"
407
- end
408
- refactored_element= Array.new
409
- new_docs_element.each do |one_element|
410
- refactored_element.push((uni_tab*2)+one_element)
411
- end
412
- write_out_array.push refactored_element.join("\n")
413
- end
414
-
415
- end
416
-
417
- # response
418
- begin
419
-
420
- # pre response
421
- begin
422
- write_out_array.push("\n#{mheader}response\n")
423
- end
424
-
425
- #> TODO make better implementation for others to use
426
- #create route content_type
427
- begin
428
- if !Grape::Endpoint.config_obj.nil?
429
-
430
- write_out_array.push((uni_tab*2)+"#{sheader}Extra headers:")
431
-
432
- Grape::Endpoint.header_config_obj.each do |header_key,header_value|
433
- write_out_array.push "#{htsym}#{header_key}: #{header_value.join(', ')}"
434
- end
435
-
436
- write_out_array.push ""
437
-
438
- end
439
- end if Grape::Endpoint.respond_to?(:config_obj) && Grape::Endpoint.respond_to?(:header_config_obj)
440
-
441
- # create response bodies
442
- begin
443
- #TODO check out why not working normaly with evry path!
444
- write_out_array.push((uni_tab*2)+"#{sheader}*body:*")
445
- wiki_body(route,container_markup_begin,container_markup_end,container_markup_close ).each do |one_element|
446
- write_out_array.push one_element
447
- end
448
- write_out_array.push ""
449
- end
450
-
451
- end
452
-
453
- # error resp
454
- begin
455
-
456
- # pre error
457
- begin
458
- write_out_array.push("\n#{mheader}response in case of failure\n")
459
- end
460
-
461
- # create error response headers
462
- begin
463
-
464
- end
465
-
466
- # create error response bodies
467
- begin
468
- #write_out_array.push((uni_tab*2)+"*body:*")
469
- write_out_array.push((uni_tab*2)+"#{htsym}*Internal Server Error:500*")
470
- end
471
-
472
- end
473
-
474
- # after space
475
- begin
476
- write_out_array.push "\n----\n"
477
- end
478
-
479
- end
480
-
481
- end
482
- end
483
-
484
- File.new(args[:path],"w").write write_out_array.join("\n")
485
-
486
- return nil
487
- end
488
-
489
- alias :create_ppt_doc :create_wiki_doc
490
-
491
- end
492
- end
493
- end
494
-
495
- Grape.__send__ :extend, ::GrapeDoc::Extend::Doc
@@ -1,58 +0,0 @@
1
-
2
- module GrapeDSL
3
- module EXT
4
-
5
- module ArrayMP
6
- def convert_all_value_to_grape_dsl_format
7
-
8
- self.count.times do |index|
9
-
10
- case true
11
-
12
- when self[index].class <= Hash
13
- self[index].convert_all_value_to_grape_dsl_format
14
-
15
- when self[index].class <= Array
16
- self[index].convert_all_value_to_grape_dsl_format
17
-
18
- else
19
- self[index]= self[index].to_s
20
-
21
-
22
- end
23
-
24
- end
25
-
26
- return self
27
- end
28
- end
29
-
30
- module HashMP
31
- def convert_all_value_to_grape_dsl_format
32
-
33
- self.each do |key,value|
34
-
35
- case true
36
-
37
- when value.class <= Hash
38
- value.convert_all_value_to_grape_dsl_format
39
-
40
- when value.class <= Array
41
- value.convert_all_value_to_grape_dsl_format
42
-
43
- else
44
- self[key]= value.to_s
45
-
46
- end
47
-
48
- end
49
-
50
- return self
51
- end
52
- end
53
-
54
- end
55
- end
56
-
57
- Array.__send__ :include, GrapeDSL::EXT::ArrayMP
58
- Hash.__send__ :include, GrapeDSL::EXT::HashMP