sinatra-docdsl 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -12
- data/lib/docdsl.rb +76 -76
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
OGIzYTJiNDE4ZmRiYTMxNDgxYmMxNDJmMWUzOGVhZGRkOTk0NjBmOQ==
|
3
|
+
metadata.gz: 50ed51e11b947de2d96212b08c9a577f5d182525
|
4
|
+
data.tar.gz: f48deba4353e341b1adf8f38aecf8ffb6db81180
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NzA2ODc1ZWJmY2EyZDI3Yjg0ZWQ0MWZkYTdhNzYwMjliZDY4NWQzZjIyOWFk
|
11
|
-
OWUzOGM4MjdkMjE0NjQ0ODA2NGY4YTU0YTE1ODhhZjk3ZGU1OWY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NGZmYjc0NTJlZDEyNjJiNzQxYjlmZmMyY2M3MDlmNjI4ZTljMTdlYmRiZTIz
|
14
|
-
NGJhZWEyOWM4MGVjNzFiNjgyMWIzZTIyMTM3OWM0Mzc1ZmJjNDA4NGUxZmZk
|
15
|
-
MmVkNDJiM2U1NWNhMThkNWZjNGM5ODI4ODk1MzEzMDhmMjI0Zjg=
|
6
|
+
metadata.gz: ff01d25759bd3d99288f1e6a5b1f44d6b81465b5eeeba6f3f42f8bf40d2f3681d541a91553d61bbdbb215b2a14cbb33c4d97ebf60a842f0970ebaa33ee8e1d8b
|
7
|
+
data.tar.gz: ef6cf62bfa46d797e64a6c92f90445e1e6b6ae0eddd086a625c1e6b4a0987453c9d9bb748e1292a1986810c23701841cda0c02a14b4838732852b2dadd6e3a81
|
data/lib/docdsl.rb
CHANGED
@@ -5,7 +5,7 @@ module Sinatra
|
|
5
5
|
module DocDsl
|
6
6
|
class PageDoc
|
7
7
|
attr_accessor :the_title,:the_header,:the_footer,:the_introduction,:entries,:the_url_prefix
|
8
|
-
|
8
|
+
|
9
9
|
def initialize(&block)
|
10
10
|
@the_title='DocDSL Documentation'
|
11
11
|
@the_header="API"
|
@@ -24,35 +24,35 @@ module Sinatra
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def title(t)
|
29
29
|
@the_title=t
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def header(h)
|
33
33
|
@the_header=h
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def footer(f)
|
37
37
|
@the_footer=f
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def introduction(i)
|
41
41
|
@the_introduction=i
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def configure_renderer(&block)
|
45
45
|
@render_function=block
|
46
|
-
end
|
47
|
-
|
46
|
+
end
|
47
|
+
|
48
48
|
def render
|
49
49
|
@render_function.call
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def url_prefix(prefix)
|
53
53
|
@the_url_prefix=prefix
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def json
|
57
57
|
entries=[]
|
58
58
|
@entries.each do |entry|
|
@@ -62,11 +62,11 @@ module Sinatra
|
|
62
62
|
:title=> @the_title,:header=>@the_header,:footer=>@the_footer,:introduction=>@the_introduction,
|
63
63
|
:endPoints=>entries
|
64
64
|
}
|
65
|
-
|
65
|
+
|
66
66
|
[200,{'content-type' => 'application/json;charset=UTF8'},object.to_json]
|
67
67
|
end
|
68
|
-
|
69
|
-
def definition_list(title, definitions)
|
68
|
+
|
69
|
+
def definition_list(title, definitions)
|
70
70
|
if definitions.length > 0
|
71
71
|
definitions.inject("### #{title}\n\n") do | dl, (k,v) |
|
72
72
|
dl << "
|
@@ -78,7 +78,7 @@ module Sinatra
|
|
78
78
|
''
|
79
79
|
end
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def render_md
|
83
83
|
begin
|
84
84
|
html=Kramdown::Document.new(to_markdown).to_html
|
@@ -104,15 +104,15 @@ HTML
|
|
104
104
|
[500,"oops, #{e.to_s}\n#{e.backtrace}"]
|
105
105
|
end
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
def md
|
109
109
|
[200,{'content-type' => 'text/plain;charset=UTF8'},to_markdown]
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
def to_markdown
|
113
113
|
markdown="
|
114
114
|
#{@the_header}
|
115
|
-
|
115
|
+
|
116
116
|
# #{@the_title}
|
117
117
|
|
118
118
|
#{@the_introduction}
|
@@ -123,36 +123,36 @@ HTML
|
|
123
123
|
params = definition_list("Url Parameters", entry.params)
|
124
124
|
query_params = definition_list("Query Parameters", entry.query_params)
|
125
125
|
header_params = definition_list("Header Parameters", entry.headers)
|
126
|
-
|
126
|
+
|
127
127
|
if entry.the_payload
|
128
128
|
payload="
|
129
129
|
### Request body
|
130
130
|
|
131
|
-
#{entry.the_payload}
|
132
|
-
|
131
|
+
#{entry.the_payload}
|
132
|
+
|
133
133
|
"
|
134
134
|
if(entry.sample_request)
|
135
135
|
payload << "
|
136
136
|
~~~ javascript
|
137
|
-
#{JSON.pretty_generate(entry.sample_request)}
|
137
|
+
#{::JSON.pretty_generate(entry.sample_request)}
|
138
138
|
~~~
|
139
139
|
|
140
140
|
"
|
141
141
|
end
|
142
142
|
end
|
143
143
|
payload ||=''
|
144
|
-
|
145
|
-
|
146
|
-
if entry.the_response
|
144
|
+
|
145
|
+
|
146
|
+
if entry.the_response
|
147
147
|
response="
|
148
148
|
### Response
|
149
149
|
#{entry.the_response}
|
150
150
|
|
151
|
-
"
|
151
|
+
"
|
152
152
|
if(entry.sample_response)
|
153
153
|
response << "
|
154
154
|
~~~ javascript
|
155
|
-
#{JSON.pretty_generate(entry.sample_response)}
|
155
|
+
#{::JSON.pretty_generate(entry.sample_response)}
|
156
156
|
~~~
|
157
157
|
|
158
158
|
"
|
@@ -180,13 +180,13 @@ HTML
|
|
180
180
|
#{status_codes}
|
181
181
|
"
|
182
182
|
end
|
183
|
-
|
183
|
+
|
184
184
|
markdown << "
|
185
185
|
#{@the_footer}
|
186
186
|
"
|
187
187
|
markdown
|
188
188
|
end
|
189
|
-
|
189
|
+
|
190
190
|
def html
|
191
191
|
begin
|
192
192
|
body= <<-HTML
|
@@ -203,7 +203,7 @@ HTML
|
|
203
203
|
<div id="container">
|
204
204
|
<h1 id="title">#{@the_header}</h1>
|
205
205
|
<p>#{@the_introduction}</p>
|
206
|
-
|
206
|
+
|
207
207
|
#{render_html_entries}
|
208
208
|
<br/>
|
209
209
|
<hr>
|
@@ -215,10 +215,10 @@ HTML
|
|
215
215
|
[200,{'content-type' => 'text/html;charset=UTF8'},body]
|
216
216
|
rescue => e
|
217
217
|
[500,"oops, #{e.to_s}\n#{e.backtrace}"]
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
def render_html_entries
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def render_html_entries
|
222
222
|
@entries.inject('') { | markup, entry|
|
223
223
|
path = entry.paths.join(', ')
|
224
224
|
if entry.params.length >0
|
@@ -228,16 +228,16 @@ HTML
|
|
228
228
|
params << "</dl>\n"
|
229
229
|
end
|
230
230
|
params ||= ''
|
231
|
-
|
231
|
+
|
232
232
|
if entry.query_params.length >0
|
233
233
|
query_params = entry.query_params.inject("<h3>Query Parameters</h3>\n<dl>") { |li,(k,v)|
|
234
234
|
li << "<dt>:%s</dt><dd>%s</dd>" % [k,v]
|
235
235
|
}
|
236
236
|
query_params << "</dl>\n"
|
237
|
-
end
|
237
|
+
end
|
238
238
|
query_params ||=''
|
239
|
-
|
240
|
-
|
239
|
+
|
240
|
+
|
241
241
|
if entry.headers.length >0
|
242
242
|
headers = entry.headers.inject("<h3>Header Parameters</h3>\n<dl>") { |li,(k,v)|
|
243
243
|
li << "<dt>%s</dt><dd>%s</dd>" % [k,v]
|
@@ -245,11 +245,11 @@ HTML
|
|
245
245
|
headers << "</dl>\n"
|
246
246
|
end
|
247
247
|
headers ||= ''
|
248
|
-
|
248
|
+
|
249
249
|
if entry.the_payload
|
250
250
|
payload="<dt>Payload</dt><dd>#{entry.the_payload}\n"
|
251
251
|
if(entry.sample_request)
|
252
|
-
payload << "<pre>#{JSON.pretty_generate(entry.sample_request)}</pre>"
|
252
|
+
payload << "<pre>#{::JSON.pretty_generate(entry.sample_request)}</pre>"
|
253
253
|
end
|
254
254
|
payload << "</dd>"
|
255
255
|
end
|
@@ -263,10 +263,10 @@ HTML
|
|
263
263
|
end
|
264
264
|
status_codes << "</dl>\n"
|
265
265
|
end
|
266
|
-
|
267
|
-
response="<dt>Response</dt><dd>#{entry.the_response}\n#{statuscodes}\n"
|
266
|
+
|
267
|
+
response="<dt>Response</dt><dd>#{entry.the_response}\n#{statuscodes}\n"
|
268
268
|
if(entry.sample_response)
|
269
|
-
response << "<pre>#{JSON.pretty_generate(entry.sample_response)}</pre>"
|
269
|
+
response << "<pre>#{::JSON.pretty_generate(entry.sample_response)}</pre>"
|
270
270
|
end
|
271
271
|
response << "</dd>"
|
272
272
|
end
|
@@ -276,19 +276,19 @@ HTML
|
|
276
276
|
} << ""
|
277
277
|
end
|
278
278
|
end
|
279
|
-
|
279
|
+
|
280
280
|
class DocEntry
|
281
281
|
attr_accessor :desc,:params,:paths,:query_params,:headers,:the_payload,:the_response,:sample_request,:sample_response,:status_codes
|
282
|
-
|
282
|
+
|
283
283
|
def initialize(description, &block)
|
284
284
|
@paths=[]
|
285
285
|
@desc=description
|
286
286
|
@params={}
|
287
287
|
@query_params={}
|
288
|
-
@headers={}
|
288
|
+
@headers={}
|
289
289
|
@the_payload=nil
|
290
290
|
@sample_request=nil
|
291
|
-
@the_response=nil
|
291
|
+
@the_response=nil
|
292
292
|
@sample_response=nil
|
293
293
|
@status_codes={}
|
294
294
|
if(block)
|
@@ -299,41 +299,41 @@ HTML
|
|
299
299
|
end
|
300
300
|
end
|
301
301
|
end
|
302
|
-
|
302
|
+
|
303
303
|
def <<(path)
|
304
304
|
self.paths << path
|
305
305
|
end
|
306
|
-
|
306
|
+
|
307
307
|
def to_s
|
308
308
|
self.inspect
|
309
309
|
end
|
310
|
-
|
310
|
+
|
311
311
|
def describe(desc)
|
312
312
|
@desc=desc
|
313
313
|
end
|
314
|
-
|
314
|
+
|
315
315
|
def payload(desc, example=nil)
|
316
316
|
@the_payload=desc
|
317
317
|
@sample_request=example
|
318
318
|
end
|
319
|
-
|
319
|
+
|
320
320
|
def response(desc,example=nil)
|
321
|
-
@the_response=desc
|
322
|
-
@sample_response=example
|
321
|
+
@the_response=desc
|
322
|
+
@sample_response=example
|
323
323
|
end
|
324
|
-
|
324
|
+
|
325
325
|
def param(name,desc)
|
326
|
-
@params[name]=desc
|
326
|
+
@params[name]=desc
|
327
327
|
end
|
328
|
-
|
328
|
+
|
329
329
|
def header(name,desc)
|
330
|
-
@headers[name]=desc
|
330
|
+
@headers[name]=desc
|
331
331
|
end
|
332
|
-
|
332
|
+
|
333
333
|
def query_param(name,desc)
|
334
|
-
@query_params[name]=desc
|
334
|
+
@query_params[name]=desc
|
335
335
|
end
|
336
|
-
|
336
|
+
|
337
337
|
def status(code,meaning=nil)
|
338
338
|
official_meaning=status_codes_map[code]
|
339
339
|
if meaning
|
@@ -342,7 +342,7 @@ HTML
|
|
342
342
|
@status_codes[code]=official_meaning
|
343
343
|
end
|
344
344
|
end
|
345
|
-
|
345
|
+
|
346
346
|
def status_codes_map
|
347
347
|
{
|
348
348
|
100=> 'Continue',
|
@@ -385,44 +385,44 @@ HTML
|
|
385
385
|
503=> 'Temporarily Unavailable'
|
386
386
|
}
|
387
387
|
end
|
388
|
-
|
388
|
+
|
389
389
|
def json
|
390
390
|
{
|
391
|
-
:description=>@desc,
|
392
|
-
:url_parameters=>@params,
|
393
|
-
:paths=>@paths,
|
394
|
-
:query_parameters=>@query_params,
|
395
|
-
:headers=>@headers,
|
396
|
-
:payload=>@the_payload,
|
391
|
+
:description=>@desc,
|
392
|
+
:url_parameters=>@params,
|
393
|
+
:paths=>@paths,
|
394
|
+
:query_parameters=>@query_params,
|
395
|
+
:headers=>@headers,
|
396
|
+
:payload=>@the_payload,
|
397
397
|
:sample_request=>@sample_request,
|
398
398
|
:response=>@the_response,
|
399
399
|
:status_codes=>@status_codes,
|
400
400
|
:sample_response=>@sample_response
|
401
401
|
}
|
402
402
|
end
|
403
|
-
end
|
404
|
-
|
405
|
-
def doc_endpoint(path)
|
403
|
+
end
|
404
|
+
|
405
|
+
def doc_endpoint(path)
|
406
406
|
page_doc=@page_doc
|
407
|
-
get path do
|
407
|
+
get path do
|
408
408
|
begin
|
409
409
|
page_doc.render
|
410
410
|
rescue Exception=>e
|
411
411
|
[500,"#{e.message} #{e.backtrace.inspect}"]
|
412
412
|
end
|
413
|
-
end
|
413
|
+
end
|
414
414
|
end
|
415
|
-
|
415
|
+
|
416
416
|
def page(&block)
|
417
417
|
@page_doc ||= PageDoc.new(&block)
|
418
418
|
end
|
419
|
-
|
419
|
+
|
420
420
|
def documentation(description,&block)
|
421
421
|
@page_doc ||= PageDoc.new
|
422
422
|
@last_doc=DocEntry.new(description,&block)
|
423
423
|
(@page_doc.entries ||= []) << @last_doc
|
424
424
|
end
|
425
|
-
|
425
|
+
|
426
426
|
def method_added(method)
|
427
427
|
# gets called everytime a method is added to the app.
|
428
428
|
# only triggers if the previous method was a documentation ... call
|
metadata
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-docdsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jilles van Gurp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
requirement: !ruby/object:Gem::Requirement
|
21
21
|
requirements:
|
22
|
-
- -
|
22
|
+
- - '>='
|
23
23
|
- !ruby/object:Gem::Version
|
24
24
|
version: '0'
|
25
25
|
prerelease: false
|
@@ -41,17 +41,17 @@ require_paths:
|
|
41
41
|
- lib
|
42
42
|
required_ruby_version: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - '>='
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
48
|
requirements:
|
49
|
-
- -
|
49
|
+
- - '>='
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
53
|
rubyforge_project:
|
54
|
-
rubygems_version: 2.
|
54
|
+
rubygems_version: 2.1.11
|
55
55
|
signing_key:
|
56
56
|
specification_version: 4
|
57
57
|
summary: Documentation DSL for Sinatra
|