raddocs 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/raddocs.rb +1 -0
- data/lib/raddocs/app.rb +34 -0
- data/lib/raddocs/configuration.rb +4 -0
- data/lib/raddocs/models.rb +25 -0
- data/lib/views/example.haml +140 -133
- data/lib/views/guide.erb +44 -0
- data/lib/views/index.haml +6 -0
- data/lib/views/layout.haml +5 -5
- metadata +18 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b989901e3d45fb5255c8c9222d1746879b9790b
|
4
|
+
data.tar.gz: cc742b1983b7f2e1cdbad403f1e9e35f1197482e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afe31bd9643682f6135d20b25f7d4155e266fd7dee9b4293d1d98c090217f90f6250935c93fb7ffbca154808bc26930c770ee56de33cba4e6c4e1245b7a9629c
|
7
|
+
data.tar.gz: 85bf7c3eb4a28549bff99c8a7c5d98495a0104abcbef4b8af1fed83679dd6ac284be03250a323473d8cd869be5d2792bf3aa2ebcb0bd7f9f3230b2d1b5db0fbf
|
data/lib/raddocs.rb
CHANGED
data/lib/raddocs/app.rb
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
# Load the constant
|
2
|
+
module Raddocs
|
3
|
+
class App < Sinatra::Base
|
4
|
+
class << self
|
5
|
+
attr_accessor :markdown
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
begin
|
11
|
+
require 'kramdown'
|
12
|
+
|
13
|
+
Raddocs::App.markdown = true
|
14
|
+
rescue LoadError
|
15
|
+
# do nothing, we won't load markdown files
|
16
|
+
end
|
17
|
+
|
1
18
|
module Raddocs
|
2
19
|
# Sinatra app that serves all documentation
|
3
20
|
class App < Sinatra::Base
|
@@ -22,6 +39,13 @@ module Raddocs
|
|
22
39
|
File.read(file)
|
23
40
|
end
|
24
41
|
|
42
|
+
if markdown
|
43
|
+
get "/guides/*" do
|
44
|
+
file = "#{guides_dir}/#{params[:splat][0]}.md"
|
45
|
+
erb :guide, locals: { guide: File.read(file) }, layout: false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
25
49
|
# Catch all for example pages.
|
26
50
|
# Loads files from the docs dir and appends '.json'.
|
27
51
|
#
|
@@ -87,6 +111,16 @@ module Raddocs
|
|
87
111
|
def docs_dir
|
88
112
|
Raddocs.configuration.docs_dir
|
89
113
|
end
|
114
|
+
|
115
|
+
def guides
|
116
|
+
YAML.load(File.read(File.join(guides_dir, "guides.yml"))).map do |guide_hash|
|
117
|
+
Guide.new(guide_hash)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def guides_dir
|
122
|
+
Raddocs.configuration.guides_dir
|
123
|
+
end
|
90
124
|
end
|
91
125
|
end
|
92
126
|
end
|
@@ -29,6 +29,10 @@ module Raddocs
|
|
29
29
|
# @return [String] defaults to 'doc/api'
|
30
30
|
add_setting :docs_dir, :default => "doc/api"
|
31
31
|
|
32
|
+
# @!attribute guides_dir
|
33
|
+
# @return [String] defaults to 'doc/guides'
|
34
|
+
add_setting :guides_dir, :default => "doc/guides"
|
35
|
+
|
32
36
|
# @!attribute docs_mime_type
|
33
37
|
# @return [Regexp] defaults to Regexp.new("text/docs\+plain")
|
34
38
|
add_setting :docs_mime_type, :default => /text\/docs\+plain/
|
data/lib/raddocs/models.rb
CHANGED
@@ -62,6 +62,21 @@ module Raddocs
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
# Guide page model
|
66
|
+
class Guide
|
67
|
+
attr_reader :title
|
68
|
+
|
69
|
+
def initialize(attributes)
|
70
|
+
@title = attributes.fetch("title")
|
71
|
+
@file = attributes.fetch("file")
|
72
|
+
end
|
73
|
+
|
74
|
+
def href
|
75
|
+
filename = @file.gsub(".md", "")
|
76
|
+
"guides/#{filename}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
65
80
|
# An example's parameters, requires a class because the table can display unknown columns
|
66
81
|
class Parameters
|
67
82
|
attr_reader :extra_keys, :params
|
@@ -258,6 +273,11 @@ module Raddocs
|
|
258
273
|
!@request_body.nil?
|
259
274
|
end
|
260
275
|
|
276
|
+
# @return [Boolean] true if request headers are present
|
277
|
+
def request_headers?
|
278
|
+
request_headers.length > 0
|
279
|
+
end
|
280
|
+
|
261
281
|
# Request headers must be set
|
262
282
|
# @return [String] Content type of the request
|
263
283
|
def request_content_type
|
@@ -286,6 +306,11 @@ module Raddocs
|
|
286
306
|
!@response_body.nil?
|
287
307
|
end
|
288
308
|
|
309
|
+
# @return [Boolean] true if response headers are present
|
310
|
+
def response_headers?
|
311
|
+
response_headers.length > 0
|
312
|
+
end
|
313
|
+
|
289
314
|
# Response headers must be set
|
290
315
|
# @return [String] Content type of the response
|
291
316
|
def response_content_type
|
data/lib/views/example.haml
CHANGED
@@ -1,137 +1,144 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
%
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
%
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
- if request.curl?
|
113
|
-
%section.curl
|
114
|
-
%h4 cURL
|
115
|
-
%pre= request.curl
|
116
|
-
|
117
|
-
- if request.response?
|
118
|
-
.response
|
119
|
-
%h3 Response
|
120
|
-
|
121
|
-
%section.headers
|
122
|
-
%h4 Headers
|
123
|
-
%pre.headers
|
124
|
-
:preserve
|
125
|
-
#{request.response_headers}
|
126
|
-
|
127
|
-
%section.status
|
128
|
-
%h4 Status
|
129
|
-
%pre.status= request.response_status
|
130
|
-
|
131
|
-
- if request.response_body?
|
1
|
+
.row-fluid
|
2
|
+
.span4.sidebar
|
3
|
+
= haml :nav, locals: { index: index, api_name: api_name }
|
4
|
+
|
5
|
+
.span10.main
|
6
|
+
:javascript
|
7
|
+
function mirror(textarea, contentType, options) {
|
8
|
+
$textarea = $(textarea);
|
9
|
+
if ($textarea.val() != '') {
|
10
|
+
if(contentType.indexOf('json') >= 0) {
|
11
|
+
$textarea.val(JSON.stringify(JSON.parse($textarea.val()), undefined, 2));
|
12
|
+
options.json = true;
|
13
|
+
options.mode = 'javascript';
|
14
|
+
} else if (contentType.indexOf('javascript') >= 0) {
|
15
|
+
options.mode = 'javascript';
|
16
|
+
} else if (contentType.indexOf('xml') >= 0) {
|
17
|
+
options.mode = 'xml';
|
18
|
+
} else {
|
19
|
+
options.mode = 'htmlmixed';
|
20
|
+
}
|
21
|
+
}
|
22
|
+
return CodeMirror.fromTextArea(textarea, options);
|
23
|
+
};
|
24
|
+
|
25
|
+
$(function(){
|
26
|
+
$(".request .body .content").each(function(i, el) {
|
27
|
+
el = $(el);
|
28
|
+
mirror(el.find("textarea")[0], el.data("content-type"), { "readOnly": true, "lineNumbers": true });
|
29
|
+
});
|
30
|
+
});
|
31
|
+
|
32
|
+
.nav-bar
|
33
|
+
= link_to "« Back to Index", "/"
|
34
|
+
|
35
|
+
%h1== #{example.resource} API
|
36
|
+
.article
|
37
|
+
%h2= example.description
|
38
|
+
|
39
|
+
- if example.explanation?
|
40
|
+
%p.explanation
|
41
|
+
= example.explanation
|
42
|
+
|
43
|
+
- if example.parameters.present?
|
44
|
+
%h3 Parameters
|
45
|
+
%table.parameters
|
46
|
+
%thead
|
47
|
+
%tr
|
48
|
+
%th Name
|
49
|
+
%th Description
|
50
|
+
- example.parameters.extra_keys.each do |key|
|
51
|
+
%th= key
|
52
|
+
%tbody
|
53
|
+
- example.parameters.params.each do |param|
|
54
|
+
%tr.parameter
|
55
|
+
%td{:class => ("required" if param.required?)}
|
56
|
+
- if param.scope?
|
57
|
+
%span.name #{param.scope}[#{param.name}]
|
58
|
+
- else
|
59
|
+
%span.name= param.name
|
60
|
+
%td
|
61
|
+
%span.description= param.description
|
62
|
+
- example.parameters.extra_keys.each do |key|
|
63
|
+
%td
|
64
|
+
%span.extras= param[key]
|
65
|
+
|
66
|
+
- if example.response_fields.present?
|
67
|
+
%h3 Response Fields
|
68
|
+
%table.response-fields
|
69
|
+
%thead
|
70
|
+
%tr
|
71
|
+
%th Name
|
72
|
+
%th Description
|
73
|
+
- example.response_fields.extra_keys.each do |key|
|
74
|
+
%th= key
|
75
|
+
%tbody
|
76
|
+
- example.response_fields.fields.each do |field|
|
77
|
+
%tr.response-field
|
78
|
+
%td
|
79
|
+
- if field.scope?
|
80
|
+
%span.name #{field.scope}[#{field.name}]
|
81
|
+
- else
|
82
|
+
%span.name= field.name
|
83
|
+
%td
|
84
|
+
%span.description= field.description
|
85
|
+
- example.response_fields.extra_keys.each do |key|
|
86
|
+
%td
|
87
|
+
%span.extras= field[key]
|
88
|
+
|
89
|
+
- example.requests.each_with_index do |request, index|
|
90
|
+
.request{ :id => "request-#{index}" }
|
91
|
+
%h3 Request
|
92
|
+
|
93
|
+
- if request.response_headers?
|
94
|
+
%section.headers
|
95
|
+
%h4 Headers
|
96
|
+
%pre.headers
|
97
|
+
:preserve
|
98
|
+
#{request.request_headers}
|
99
|
+
|
100
|
+
%section.route
|
101
|
+
%h4 Route
|
102
|
+
%pre.route.highlight== #{request.request_method} #{request.request_path}
|
103
|
+
|
104
|
+
- if request.request_query_parameters?
|
105
|
+
%section.query-parameters
|
106
|
+
%h4 Query Parameters
|
107
|
+
%pre.query-parameters.highlight
|
108
|
+
= request.request_query_parameters
|
109
|
+
|
110
|
+
- if request.request_body?
|
132
111
|
%section.body
|
133
112
|
%h4 Body
|
134
|
-
.content{ "data-content-type" => request.
|
113
|
+
.content{ "data-content-type" => request.request_content_type }
|
135
114
|
%textarea
|
136
115
|
:preserve
|
137
|
-
#{request.
|
116
|
+
#{request.request_body}
|
117
|
+
|
118
|
+
- if request.curl?
|
119
|
+
%section.curl
|
120
|
+
%h4 cURL
|
121
|
+
%pre= request.curl
|
122
|
+
|
123
|
+
- if request.response?
|
124
|
+
.response
|
125
|
+
%h3 Response
|
126
|
+
|
127
|
+
- if request.response_headers?
|
128
|
+
%section.headers
|
129
|
+
%h4 Headers
|
130
|
+
%pre.headers
|
131
|
+
:preserve
|
132
|
+
#{request.response_headers}
|
133
|
+
|
134
|
+
%section.status
|
135
|
+
%h4 Status
|
136
|
+
%pre.status= request.response_status
|
137
|
+
|
138
|
+
- if request.response_body?
|
139
|
+
%section.body
|
140
|
+
%h4 Body
|
141
|
+
.content{ "data-content-type" => request.response_content_type }
|
142
|
+
%textarea
|
143
|
+
:preserve
|
144
|
+
#{request.response_body}
|
data/lib/views/guide.erb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title><%= api_name %></title>
|
5
|
+
<% css_files.each do |file| %>
|
6
|
+
<link rel="stylesheet" href="<%= file %>" />
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<script src="#{url_location}/js/jquery-1-7-2.js"></script>
|
10
|
+
<script src="#{url_location}/js/codemirror.js"></script>
|
11
|
+
<script src="#{url_location}/js/mode/css/css.js"></script>
|
12
|
+
<script src="#{url_location}/js/mode/htmlmixed/htmlmixed.js"></script>
|
13
|
+
<script src="#{url_location}/js/mode/javascript/javascript.js"></script>
|
14
|
+
<script src="#{url_location}/js/mode/xml/xml.js"></script>
|
15
|
+
|
16
|
+
<style>
|
17
|
+
td.required .name:after {
|
18
|
+
float: right;
|
19
|
+
content: "required";
|
20
|
+
font-weight: normal;
|
21
|
+
color: #F08080;
|
22
|
+
}
|
23
|
+
|
24
|
+
p {
|
25
|
+
padding: 15px;
|
26
|
+
font-size: 130%;
|
27
|
+
}
|
28
|
+
|
29
|
+
nav {
|
30
|
+
margin-bottom: 15px;
|
31
|
+
}
|
32
|
+
</style>
|
33
|
+
</head>
|
34
|
+
<body>
|
35
|
+
|
36
|
+
<div class="container">
|
37
|
+
<nav>
|
38
|
+
<%= link_to "« Back to Index", "/" %>
|
39
|
+
</nav>
|
40
|
+
|
41
|
+
<%= Kramdown::Document.new(guide, input: "GFM", syntax_highlighter_opts: { line_numbers: false }).to_html %>
|
42
|
+
</div>
|
43
|
+
</body>
|
44
|
+
</html>
|
data/lib/views/index.haml
CHANGED
data/lib/views/layout.haml
CHANGED
@@ -2,14 +2,17 @@
|
|
2
2
|
%html
|
3
3
|
%head
|
4
4
|
%title= api_name
|
5
|
+
|
5
6
|
- css_files.each do |file|
|
6
7
|
%link{:rel => "stylesheet", :href => file}
|
8
|
+
|
7
9
|
%script(src="#{url_location}/js/jquery-1-7-2.js")
|
8
10
|
%script(src="#{url_location}/js/codemirror.js")
|
9
11
|
%script(src="#{url_location}/js/mode/css/css.js")
|
10
12
|
%script(src="#{url_location}/js/mode/htmlmixed/htmlmixed.js")
|
11
13
|
%script(src="#{url_location}/js/mode/javascript/javascript.js")
|
12
14
|
%script(src="#{url_location}/js/mode/xml/xml.js")
|
15
|
+
|
13
16
|
:css
|
14
17
|
td.required .name:after {
|
15
18
|
float: right;
|
@@ -22,10 +25,7 @@
|
|
22
25
|
padding: 15px;
|
23
26
|
font-size: 130%;
|
24
27
|
}
|
28
|
+
|
25
29
|
%body
|
26
30
|
.container
|
27
|
-
|
28
|
-
.span4.sidebar
|
29
|
-
= haml :nav, locals: { index: index, api_name: api_name }
|
30
|
-
.span8.main
|
31
|
-
= yield
|
31
|
+
= yield
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raddocs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Oestrich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -17,9 +17,6 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 1.3.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,9 +24,6 @@ dependencies:
|
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.3'
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 1.3.0
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: haml
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -37,9 +31,6 @@ dependencies:
|
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
33
|
version: '4.0'
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: 4.0.4
|
43
34
|
type: :runtime
|
44
35
|
prerelease: false
|
45
36
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -47,9 +38,6 @@ dependencies:
|
|
47
38
|
- - "~>"
|
48
39
|
- !ruby/object:Gem::Version
|
49
40
|
version: '4.0'
|
50
|
-
- - ">="
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: 4.0.4
|
53
41
|
- !ruby/object:Gem::Dependency
|
54
42
|
name: json
|
55
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -57,9 +45,6 @@ dependencies:
|
|
57
45
|
- - "~>"
|
58
46
|
- !ruby/object:Gem::Version
|
59
47
|
version: '1.8'
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 1.8.1
|
63
48
|
type: :runtime
|
64
49
|
prerelease: false
|
65
50
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -67,9 +52,6 @@ dependencies:
|
|
67
52
|
- - "~>"
|
68
53
|
- !ruby/object:Gem::Version
|
69
54
|
version: '1.8'
|
70
|
-
- - ">="
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version: 1.8.1
|
73
55
|
- !ruby/object:Gem::Dependency
|
74
56
|
name: rspec
|
75
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,6 +108,20 @@ dependencies:
|
|
126
108
|
- - "~>"
|
127
109
|
- !ruby/object:Gem::Version
|
128
110
|
version: '10.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: kramdown
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
129
125
|
description: Browse documentation generated by the rspec_api_documentation gem
|
130
126
|
email:
|
131
127
|
- eric@oestrich.org
|
@@ -148,6 +144,7 @@ files:
|
|
148
144
|
- lib/raddocs/middleware.rb
|
149
145
|
- lib/raddocs/models.rb
|
150
146
|
- lib/views/example.haml
|
147
|
+
- lib/views/guide.erb
|
151
148
|
- lib/views/index.haml
|
152
149
|
- lib/views/layout.haml
|
153
150
|
- lib/views/nav.haml
|
@@ -171,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
168
|
version: 1.3.6
|
172
169
|
requirements: []
|
173
170
|
rubyforge_project:
|
174
|
-
rubygems_version: 2.
|
171
|
+
rubygems_version: 2.5.1
|
175
172
|
signing_key:
|
176
173
|
specification_version: 4
|
177
174
|
summary: rspec_api_documentation browser
|