grape-dsl 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +8 -8
  2. data/VERSION +1 -1
  3. data/lib/grape-dsl/doc.rb +89 -57
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2E2YzI4MjRlZjRiMjQ3MTljN2UxNTM1NWE0MmJkYjMzZWQ3ZjNlOQ==
4
+ NjFjODNmMTM2ZTA4MGMxM2JkNDY3MjBjYTYxMGNkYWIyYTQ0ZmJiYw==
5
5
  data.tar.gz: !binary |-
6
- ZDczZDFkNGQ0Njk4MjFiMzVmNGU1MzZkZmJmYTM3ZDgwYzZmY2RkYw==
6
+ MGQ1ZDM5ZjkzNmIxOTIxYTI3NzZjZWUyNzEwMzJhYjk2OGIwYTY4Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDJlNzExMWIzMzdjOTg1ZWU3YjRmMGRhYWRjYmYzZWVjNzRmM2I4NWYwZDc4
10
- YjFiOTQyOWU3ZGVhNzhkMTg4ZGY2M2IwNzg0OGNhZDM0OTJiYzhhYTI1ZmU4
11
- NDQ5NzRhY2U0ZDVlYTcxZGQwYTMwY2Y5NTQ3MjM0YTY5OWFlNGE=
9
+ ZDAyZDAwNWU1Nzc2OWY4ZTA3ODk0OGJlYzdkZTA4MmI3Yjg0ZTkwMTVlMTlm
10
+ NzY1NjllNDY0ZTQ1MTAzNTgwMjMzYWU0MjIwMmRjYmNmNzdmZTRmYjhiMjZl
11
+ ZjliYjYzM2IxMTkzNDNhYjEzMDQ0OWRkMTY3OTZlN2NlZGM1ZTQ=
12
12
  data.tar.gz: !binary |-
13
- MzE1ZTdjNTkwNjMxYTA0ZDVlMDdlMjgxYzI5NDE4ZDliNjQ5OWRkODFjYmVm
14
- Mjc0ZjkxYjE1NmUzODgyOWEwOWY0ZDY1M2U4OGMwOWZlMzE2OTA1ZjcxOGFk
15
- YTEwMGRkMTc4OTE0ZjYzZjFiOTY4ZDcyM2RhZjU5MzllZjY5MTE=
13
+ NGY2NjY1YzFkMjI5MDYzMmVmMTA0Nzk3NDBhN2JmZjRkZTFlMmI4OWQ3ZmRj
14
+ Nzc5NTNkZWQyNjAxODVjMWQ0NmIzZWU2YWMwMDlmNDFlYzJmYzRmMzQ1Mjlk
15
+ ZTgyOWU3ZWUwNTVhZDI1M2IzOThjOTMzNjIyYWI1ZDg3NDI0NDU=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
data/lib/grape-dsl/doc.rb CHANGED
@@ -56,8 +56,12 @@ end
56
56
  module Grape
57
57
  class << self
58
58
 
59
+ def syntax_highlight target,wrapper_begin,wrapper_end
60
+ return "#{wrapper_begin}#{target}#{wrapper_end}"
61
+ end
62
+
59
63
  # helpers for doc generation
60
- def redmine_body(route)
64
+ def wiki_body(route,wrapper_begin,wrapper_end,wrapper_close)
61
65
 
62
66
  description_key= :body
63
67
  tmp_array= Array.new()
@@ -143,7 +147,7 @@ module Grape
143
147
 
144
148
 
145
149
 
146
- tmp_array.push("<pre><code class=\"#{content_type.to_s.upcase}\">")
150
+ tmp_array.push syntax_highlight(content_type.to_s,wrapper_begin,wrapper_end)
147
151
 
148
152
  require "json"
149
153
 
@@ -160,16 +164,12 @@ module Grape
160
164
  formatted_string.gsub!(/^"/," \"")
161
165
 
162
166
  tmp_array.push formatted_string
163
- tmp_array.push("</code></pre>")
167
+ tmp_array.push wrapper_close
164
168
  end
165
169
 
166
170
  when "txt"
167
171
  begin
168
-
169
- tmp_array.push("<pre>")
170
172
  tmp_array.push(params.inspect)
171
- tmp_array.push("</pre>")
172
-
173
173
  end
174
174
 
175
175
 
@@ -225,7 +225,7 @@ module Grape
225
225
  ## for all grape subclass (directs and indirects)
226
226
  #Grape.create_redmine_wiki_doc path: File.expand_path(File.join(File.dirname(__FILE__),"test_file.txt"))
227
227
  #
228
- def create_redmine_wiki_doc(*args)
228
+ def create_wiki_doc(*args)
229
229
 
230
230
  # default set in args
231
231
  begin
@@ -254,24 +254,85 @@ module Grape
254
254
  end
255
255
  end
256
256
 
257
-
257
+ args[:type] ||= args[:doc_type]
258
+ args[:type] ||= 'wiki'
258
259
 
259
260
  #args[:path],
260
261
  #args[:extra_desc_file]
261
262
  #args[:target_class]
263
+ #args[:type]
264
+
265
+ end
266
+
267
+
268
+ # defaults
269
+ begin
270
+
271
+ uni_tab= ""
272
+ case args[:type].to_s.downcase
273
+
274
+ when "redmine","redmine_wiki","redmine-wiki","redminewiki"
275
+ begin
276
+
277
+ mid_tab= " "*3
278
+
279
+ bsym= "*"
280
+ isym= "_"
281
+
282
+ htsym= "* "
283
+ mtsym= htsym[0]*2 +" "
284
+ stsym= htsym[0]*3 +" "
285
+
286
+ hheader= "h3. "
287
+ mheader= "h4. "
288
+ sheader= "h5. "
289
+
290
+ container_markup_begin= "<pre><code class=\""
291
+ container_markup_end= "\">"
292
+ container_markup_close= "</code></pre>"
293
+
294
+ end
295
+
296
+ when "github","wiki","md"
297
+ begin
298
+
299
+ mid_tab= " "*3
300
+
301
+ bsym= "*"
302
+ isym= "_"
303
+
304
+ htsym= "* "
305
+ mtsym= htsym[0]*2 +" "
306
+ stsym= htsym[0]*3 +" "
307
+
308
+ hheader= "# "
309
+ mheader= hheader[0]*2 +" "
310
+ sheader= hheader[0]*3 +" "
311
+
312
+ container_markup_begin= "```"
313
+ container_markup_end= ""
314
+ container_markup_close= "```"
315
+
316
+ end
317
+
318
+ else
319
+ raise ArgumentError, "invalid :type has been set, try github or redmine"
320
+
321
+ end
262
322
 
263
323
  end
264
324
 
265
325
  # site name
266
326
  begin
267
327
  write_out_array = Array.new
268
- write_out_array.push "h1. Database Rest Control Layer Documentation\n"
269
- write_out_array.push "h2. REST application routes:\n"
328
+ write_out_array.push "#{hheader}Database Rest Control Layer Documentation\n"
329
+ write_out_array.push "#{mheader}REST application routes:\n"
270
330
  end
271
331
 
332
+
272
333
  # description
273
334
  begin
274
- write_out_array.push "h3. this is the documentation for #{$0} rest calls\n\n"+
335
+ write_out_array.push "#{sheader}this is the documentation for #{$0} rest calls\n\n"+
275
336
  " the main function is to create a control layer to the database,\n"+
276
337
  "with interactive commands, that can handle multiple way from ask requests,\n"+
277
338
  "like regexp search by string, or different parameters for an array ask,\n"+
@@ -280,7 +341,7 @@ module Grape
280
341
  "like read from db, create in the db or update in the db by xy params, and how.\n"
281
342
 
282
343
  args[:desc_files].each do |extra_desc_file_path|
283
- write_out_array.push "h3. #{extra_desc_file_path.split(File::Separator).last.split('.')[0].downcase.capitalize}\n"
344
+ write_out_array.push "#{sheader}#{extra_desc_file_path.split(File::Separator).last.split('.')[0].downcase.capitalize}\n"
284
345
  write_out_array.push "<pre>"
285
346
  write_out_array.push File.open(extra_desc_file_path,"r").read
286
347
  write_out_array.push "</pre>\n"
@@ -292,7 +353,6 @@ module Grape
292
353
  write_out_array.push "\n{{>toc}}\n"
293
354
  end
294
355
 
295
-
296
356
  # classes array
297
357
  begin
298
358
  rest_models= Array.new
@@ -312,27 +372,8 @@ module Grape
312
372
  next if Grape::API == rest_api_model
313
373
  rest_api_model.routes.map do |route|
314
374
 
315
- # defaults
316
- begin
317
-
318
- uni_tab= " "*0
319
- mid_tab= " "*3
320
-
321
- bsym= "*"
322
- isym= "_"
323
-
324
- htsym= "* "
325
- mtsym= "** "
326
- stsym= "*** "
327
375
 
328
- hheader= "h3. "
329
- mheader= "h4. "
330
- sheader= "h5. "
331
- method_name= "#{hheader}Request: #{route.route_path} call: #{route.route_method.to_s.downcase} part"
332
-
333
-
334
-
335
- end
376
+ method_name= "#{hheader}Request: #{route.route_path} call: #{route.route_method.to_s.downcase} part"
336
377
 
337
378
  # check that does the method already in the documentation
338
379
  unless write_out_array.include?(method_name)
@@ -395,20 +436,6 @@ module Grape
395
436
  write_out_array.push ""
396
437
  end
397
438
 
398
- # create request type for code format class
399
- # create request body contents
400
- #begin
401
- # if rest_api_model.content_types.count == 1
402
- # write_out_array.push((uni_tab*2)+"#{htsym}*body:*")
403
- #
404
- # redmine_body(rest_api_model,route).each do |one_element|
405
- # write_out_array.push one_element
406
- # end
407
- #
408
- # end
409
- # write_out_array.push ""
410
- #end
411
-
412
439
  # parameters
413
440
  begin
414
441
  new_docs_element= Array.new
@@ -442,21 +469,26 @@ module Grape
442
469
  write_out_array.push("\n#{mheader}response\n")
443
470
  end
444
471
 
445
- # create route content_type
472
+ #create route content_type
446
473
  begin
447
- write_out_array.push((uni_tab*2)+"#{htsym}#{bsym}headers:#{bsym}#{mid_tab}")
448
- rest_api_model.content_types.each do |one_format_type,one_format_header|
449
- write_out_array.push "#{mtsym}#{uni_tab*2}#{one_format_header}"
450
- end
474
+ if !Grape::Endpoint.config_obj.nil?
451
475
 
452
- write_out_array.push ""
476
+ write_out_array.push((uni_tab*2)+"#{sheader}Extra headers:")
477
+
478
+ Grape::Endpoint.header_config_obj.each do |header_key,header_value|
479
+ write_out_array.push "#{htsym}#{header_key}: #{header_value.join(', ')}"
480
+ end
481
+
482
+ write_out_array.push ""
483
+
484
+ end
453
485
  end
454
486
 
455
487
  # create response bodies
456
488
  begin
457
489
  #TODO check out why not working normaly with evry path!
458
- write_out_array.push((uni_tab*2)+"#{htsym}*body:*")
459
- redmine_body(route).each do |one_element|
490
+ write_out_array.push((uni_tab*2)+"#{sheader}*body:*")
491
+ wiki_body(route,container_markup_begin,container_markup_end,container_markup_close ).each do |one_element|
460
492
  write_out_array.push one_element
461
493
  end
462
494
  write_out_array.push ""
@@ -500,7 +532,7 @@ module Grape
500
532
  return nil
501
533
  end
502
534
 
503
- alias :create_ppt_doc :create_redmine_wiki_doc
535
+ alias :create_ppt_doc :create_wiki_doc
504
536
 
505
537
  end
506
538
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.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-02-04 00:00:00.000000000 Z
11
+ date: 2014-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: procemon