raddocs 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/public/application.css +3 -1
- data/lib/raddocs.rb +12 -1
- data/lib/raddocs/app.rb +19 -8
- data/lib/raddocs/configuration.rb +31 -0
- data/lib/raddocs/middleware.rb +11 -0
- data/lib/raddocs/models.rb +295 -0
- data/lib/views/example.haml +51 -39
- data/lib/views/index.haml +4 -4
- data/lib/views/layout.haml +5 -1
- data/lib/views/nav.haml +8 -0
- metadata +12 -34
- data/lib/raddocs/parameters.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51c3f683fc4b32ffe21f3b00883e54ede5f9874d
|
4
|
+
data.tar.gz: 04fb0bab660edaca38e10723ac9a7ab16ff2b795
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7236230c824fe40288d3ae3bf972249c056a111789f03db775adecc452b9bdc9d44a92a31fb9adc21c12769cdecdc018d0a1949d6cf9526b0179ad70dbecb18d
|
7
|
+
data.tar.gz: cd3d939196c54291544192b8e968499f9297947c5526d26ce5dd817c36169c0cd9d6c808d160d3bb6bb543979cff836b68271f24c7edbcd09abd49a6a7f0423a
|
data/lib/public/application.css
CHANGED
data/lib/raddocs.rb
CHANGED
@@ -2,16 +2,27 @@ Encoding.default_external = Encoding::UTF_8
|
|
2
2
|
|
3
3
|
require 'sinatra/base'
|
4
4
|
require 'json'
|
5
|
+
|
5
6
|
require 'raddocs/configuration'
|
6
7
|
require 'raddocs/app'
|
7
8
|
require 'raddocs/middleware'
|
8
|
-
|
9
|
+
|
10
|
+
require 'raddocs/models'
|
9
11
|
|
10
12
|
module Raddocs
|
13
|
+
# @return [Raddocs::Configuration] the current configuration
|
11
14
|
def self.configuration
|
12
15
|
@configuration ||= Configuration.new
|
13
16
|
end
|
14
17
|
|
18
|
+
# Configure Raddocs
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
# Raddocs.configure do |config|
|
22
|
+
# config.url_prefix = "/documentation"
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# @yieldparam configuration [Raddocs::Configuration]
|
15
26
|
def self.configure
|
16
27
|
yield configuration if block_given?
|
17
28
|
end
|
data/lib/raddocs/app.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
module Raddocs
|
2
|
+
# Sinatra app that serves all documentation
|
2
3
|
class App < Sinatra::Base
|
3
4
|
set :haml, :format => :html5
|
4
5
|
set :root, File.join(File.dirname(__FILE__), "..")
|
5
6
|
|
7
|
+
# Main index, displays all examples grouped by resource
|
6
8
|
get "/" do
|
7
|
-
index =
|
9
|
+
index = Index.new(File.join(docs_dir, "index.json"))
|
8
10
|
haml :index, :locals => { :index => index }
|
9
11
|
end
|
10
12
|
|
13
|
+
# Allows for overriding styles
|
11
14
|
get "/custom-css/*" do
|
12
15
|
file = "#{docs_dir}/styles/#{params[:splat][0]}"
|
13
16
|
|
@@ -19,6 +22,11 @@ module Raddocs
|
|
19
22
|
File.read(file)
|
20
23
|
end
|
21
24
|
|
25
|
+
# Catch all for example pages.
|
26
|
+
# Loads files from the docs dir and appends '.json'.
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
# "/orders/create_an_order" => "docs/api/orders/create_an_order.json"
|
22
30
|
get "/*" do
|
23
31
|
file = "#{docs_dir}/#{params[:splat][0]}.json"
|
24
32
|
|
@@ -26,13 +34,13 @@ module Raddocs
|
|
26
34
|
raise Sinatra::NotFound
|
27
35
|
end
|
28
36
|
|
29
|
-
|
37
|
+
index = Index.new(File.join(docs_dir, "index.json"))
|
38
|
+
example = Example.new(file)
|
30
39
|
|
31
|
-
example
|
32
|
-
example["parameters"] = Parameters.new(example["parameters"]).parse
|
33
|
-
haml :example, :locals => { :example => example }
|
40
|
+
haml :example, :locals => { index: index, example: example }
|
34
41
|
end
|
35
42
|
|
43
|
+
# Page not found
|
36
44
|
not_found do
|
37
45
|
"Example does not exist"
|
38
46
|
end
|
@@ -56,6 +64,9 @@ module Raddocs
|
|
56
64
|
Raddocs.configuration.api_name
|
57
65
|
end
|
58
66
|
|
67
|
+
# Loads all necessary css files
|
68
|
+
#
|
69
|
+
# @see Raddocs::Configuration for loading external files
|
59
70
|
def css_files
|
60
71
|
files = ["#{url_location}/codemirror.css", "#{url_location}/application.css"]
|
61
72
|
|
@@ -72,10 +83,10 @@ module Raddocs
|
|
72
83
|
|
73
84
|
files
|
74
85
|
end
|
75
|
-
end
|
76
86
|
|
77
|
-
|
78
|
-
|
87
|
+
def docs_dir
|
88
|
+
Raddocs.configuration.docs_dir
|
89
|
+
end
|
79
90
|
end
|
80
91
|
end
|
81
92
|
end
|
@@ -1,5 +1,17 @@
|
|
1
1
|
module Raddocs
|
2
|
+
# Configure Raddocs
|
3
|
+
# @see Raddocs.configure Raddocs.configure
|
4
|
+
# @example
|
5
|
+
# Raddocs.configure do |config|
|
6
|
+
# # config is this class
|
7
|
+
# config.api_name = "My API"
|
8
|
+
# end
|
2
9
|
class Configuration
|
10
|
+
# Configures a new setting, creates two methods
|
11
|
+
#
|
12
|
+
# @param name [Symbol] name of the setting
|
13
|
+
# @param opts [Hash]
|
14
|
+
# @option opts [Object] default default value of setting
|
3
15
|
def self.add_setting(name, opts = {})
|
4
16
|
define_method("#{name}=") { |value| settings[name] = value }
|
5
17
|
define_method("#{name}") do
|
@@ -13,13 +25,32 @@ module Raddocs
|
|
13
25
|
end
|
14
26
|
end
|
15
27
|
|
28
|
+
# @!attribute docs_dir
|
29
|
+
# @return [String] defaults to 'doc/api'
|
16
30
|
add_setting :docs_dir, :default => "doc/api"
|
31
|
+
|
32
|
+
# @!attribute docs_mime_type
|
33
|
+
# @return [Regexp] defaults to Regexp.new("text/docs\+plain")
|
17
34
|
add_setting :docs_mime_type, :default => /text\/docs\+plain/
|
35
|
+
|
36
|
+
# @!attribute api_name
|
37
|
+
# @return [String] defaults to "Api Documentation"
|
18
38
|
add_setting :api_name, :default => "Api Documentation"
|
39
|
+
|
40
|
+
# @!attribute include_bootstrap
|
41
|
+
# @return [Boolean] defaults to true
|
19
42
|
add_setting :include_bootstrap, :default => true
|
43
|
+
|
44
|
+
# @!attribute external_css
|
45
|
+
# @return [Array] array of Strings, defaults to []
|
20
46
|
add_setting :external_css, :default => []
|
47
|
+
|
48
|
+
# @!attribute url_prefix
|
49
|
+
# @return [String] defaults to nil
|
21
50
|
add_setting :url_prefix, :default => nil
|
22
51
|
|
52
|
+
private
|
53
|
+
|
23
54
|
def settings
|
24
55
|
@settings ||= {}
|
25
56
|
end
|
data/lib/raddocs/middleware.rb
CHANGED
@@ -1,4 +1,15 @@
|
|
1
1
|
module Raddocs
|
2
|
+
# Rack middleware
|
3
|
+
#
|
4
|
+
# This lets you cURL for documentation.
|
5
|
+
#
|
6
|
+
# curl -H "Accept: text/docs+plain" http://localhost/orders
|
7
|
+
#
|
8
|
+
# This will return all of the docs for a given resource, "orders." It is returned
|
9
|
+
# as a giant flat file containing all of the documentation. "combined_text" output
|
10
|
+
# must be selected in `rspec_api_documentation`.
|
11
|
+
#
|
12
|
+
# The route matches the folder structure of the docs.
|
2
13
|
class Middleware
|
3
14
|
def initialize(app)
|
4
15
|
@app = app
|
@@ -0,0 +1,295 @@
|
|
1
|
+
module Raddocs
|
2
|
+
# Index page model
|
3
|
+
class Index
|
4
|
+
def initialize(file)
|
5
|
+
@attrs = JSON.parse(File.read(file))
|
6
|
+
end
|
7
|
+
|
8
|
+
# @return [Array] array of {Raddocs::Resource Resources}
|
9
|
+
def resources
|
10
|
+
@attrs.fetch("resources", {}).map do |resource|
|
11
|
+
Resource.new(resource["name"], resource["examples"])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Group of examples related to a specific resource, eg "Orders"
|
17
|
+
class Resource < Struct.new(:name, :examples)
|
18
|
+
# @return [Array] array of {Raddocs::IndexExample IndexExamples}
|
19
|
+
def examples
|
20
|
+
@examples ||= super.map do |example|
|
21
|
+
IndexExample.new(example)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Example model for the index page
|
27
|
+
#
|
28
|
+
# Has an extra link attribute that is required only on this page.
|
29
|
+
class IndexExample
|
30
|
+
attr_reader :description, :link
|
31
|
+
|
32
|
+
def initialize(attributes)
|
33
|
+
@description = attributes.fetch("description")
|
34
|
+
@link = attributes.fetch("link")
|
35
|
+
end
|
36
|
+
|
37
|
+
# Link to example page is the same name as the file minus ".json"
|
38
|
+
def href
|
39
|
+
link.gsub(".json", "")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Example page model
|
44
|
+
class Example
|
45
|
+
attr_reader :resource, :description, :explanation, :parameters, :response_fields,
|
46
|
+
:requests
|
47
|
+
|
48
|
+
def initialize(file)
|
49
|
+
@attrs = JSON.parse(File.read(file))
|
50
|
+
|
51
|
+
@resource = @attrs.fetch("resource")
|
52
|
+
@description = @attrs.fetch("description")
|
53
|
+
@explanation = @attrs.fetch("explanation", nil)
|
54
|
+
@parameters = Parameters.new(@attrs.fetch("parameters"))
|
55
|
+
@response_fields = ResponseFields.new(@attrs.fetch("response_fields"))
|
56
|
+
@requests = @attrs.fetch("requests").map { |request| Request.new(request) }
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [Boolean] true if explanation is present
|
60
|
+
def explanation?
|
61
|
+
!explanation.nil?
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# An example's parameters, requires a class because the table can display unknown columns
|
66
|
+
class Parameters
|
67
|
+
attr_reader :extra_keys, :params
|
68
|
+
|
69
|
+
SPECIAL_KEYS = ["name", "description", "required", "scope"]
|
70
|
+
|
71
|
+
# Collection object for parameters to pull out unknown keys so they can be
|
72
|
+
# displayed on the example page.
|
73
|
+
#
|
74
|
+
# @example
|
75
|
+
# params = Parameters.new([
|
76
|
+
# {"name" => "page", "description" => "Page number", "Type" => "Integer"}
|
77
|
+
# ])
|
78
|
+
# params.extra_keys
|
79
|
+
# # => ["Type"]
|
80
|
+
#
|
81
|
+
# @param params [Array] array of {Raddocs::Parameter Parameters}
|
82
|
+
#
|
83
|
+
def initialize(params)
|
84
|
+
@params = params.map { |param| Parameter.new(param) }
|
85
|
+
@extra_keys = params.flat_map(&:keys).uniq - SPECIAL_KEYS
|
86
|
+
end
|
87
|
+
|
88
|
+
# @return [Boolean] true if params contains elements
|
89
|
+
def present?
|
90
|
+
@params.count > 0
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Parameter of a request
|
95
|
+
#
|
96
|
+
# Can have an unknown columns
|
97
|
+
#
|
98
|
+
# @example
|
99
|
+
# Parameter.new({
|
100
|
+
# "name" => "page",
|
101
|
+
# "description" => "Page number",
|
102
|
+
# "Type" => "Integer"
|
103
|
+
# })
|
104
|
+
#
|
105
|
+
class Parameter
|
106
|
+
attr_reader :name, :description, :required, :scope
|
107
|
+
|
108
|
+
# @param attributes [Hash]
|
109
|
+
# @option attributes [String] "name" Required
|
110
|
+
# @option attributes [String] "description" Required
|
111
|
+
# @option attributes [boolean] "required" defaults to false
|
112
|
+
# @option attributes [String] "scope" Scope of the parameter, eg 'order[]', defaults to nil
|
113
|
+
def initialize(attributes)
|
114
|
+
@attrs = attributes
|
115
|
+
|
116
|
+
@name = attributes.fetch("name")
|
117
|
+
@description = attributes.fetch("description")
|
118
|
+
@required = attributes.fetch("required", false)
|
119
|
+
@scope = attributes.fetch("scope", nil)
|
120
|
+
end
|
121
|
+
|
122
|
+
# @return [Boolean] true if required is true
|
123
|
+
def required?
|
124
|
+
!!@required
|
125
|
+
end
|
126
|
+
|
127
|
+
# @return [Boolean] true if scope is present
|
128
|
+
def scope?
|
129
|
+
!!@scope
|
130
|
+
end
|
131
|
+
|
132
|
+
def scope
|
133
|
+
Array(@scope).each_with_index.map do |scope, index|
|
134
|
+
if index == 0
|
135
|
+
scope
|
136
|
+
else
|
137
|
+
"[#{scope}]"
|
138
|
+
end
|
139
|
+
end.join
|
140
|
+
end
|
141
|
+
|
142
|
+
# Allows unknown keys to be accessed
|
143
|
+
# @param key [String]
|
144
|
+
# @return [Object]
|
145
|
+
def [](key)
|
146
|
+
@attrs[key]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# An example's response fields, requires a class because the table can display
|
151
|
+
# unknown columns
|
152
|
+
class ResponseFields
|
153
|
+
attr_reader :extra_keys, :fields
|
154
|
+
|
155
|
+
SPECIAL_KEYS = ["name", "description", "scope"]
|
156
|
+
|
157
|
+
def initialize(response_fields)
|
158
|
+
return unless response_fields # Might not be present
|
159
|
+
@fields = response_fields.map { |field| ResponseField.new(field) }
|
160
|
+
@extra_keys = response_fields.flat_map(&:keys).uniq - SPECIAL_KEYS
|
161
|
+
end
|
162
|
+
|
163
|
+
# @return [Boolean] true if fields contains elements
|
164
|
+
def present?
|
165
|
+
@fields.count > 0
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Fields of a response
|
170
|
+
#
|
171
|
+
# Can have an unknown columns
|
172
|
+
#
|
173
|
+
# @example
|
174
|
+
# Parameter.new({
|
175
|
+
# "name" => "page",
|
176
|
+
# "description" => "Page number",
|
177
|
+
# "Type" => "Integer"
|
178
|
+
# })
|
179
|
+
#
|
180
|
+
class ResponseField
|
181
|
+
attr_reader :name, :description, :scope
|
182
|
+
|
183
|
+
def initialize(attributes)
|
184
|
+
@attrs = attributes
|
185
|
+
|
186
|
+
@name = attributes.fetch("name")
|
187
|
+
@description = attributes.fetch("description")
|
188
|
+
@scope = attributes.fetch("scope", nil)
|
189
|
+
end
|
190
|
+
|
191
|
+
# @return [Boolean] true if scope is present
|
192
|
+
def scope?
|
193
|
+
!!@scope
|
194
|
+
end
|
195
|
+
|
196
|
+
# Allows unknown keys to be accessed
|
197
|
+
# @param key [String]
|
198
|
+
# @return [Object]
|
199
|
+
def [](key)
|
200
|
+
@attrs[key]
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
# Documented response
|
205
|
+
#
|
206
|
+
# @param attributes [Hash]
|
207
|
+
class Request
|
208
|
+
attr_reader :request_method, :request_path, :request_body,
|
209
|
+
:curl, :response_status, :response_body
|
210
|
+
|
211
|
+
# @param attributes [Hash]
|
212
|
+
# @option attributes [Hash] "request_headers"
|
213
|
+
# Hash of request headers, not in rack format
|
214
|
+
# @option attributes [String] "request_method"
|
215
|
+
# @option attributes [String] "request_path"
|
216
|
+
# @option attributes [Hash] "request_query_parameters"
|
217
|
+
# Query parameters pulled from the request if a GET request
|
218
|
+
# @option attributes [String] "request_body"
|
219
|
+
# @option attributes [String] "curl" Formatted
|
220
|
+
# cURL request
|
221
|
+
# @option attributes [String] "response_status"
|
222
|
+
# @option attributes [Hash] "response_headers"
|
223
|
+
# Hash of response headers, not in rack format
|
224
|
+
# @option attributes [String] "response_body"
|
225
|
+
def initialize(attributes)
|
226
|
+
@attrs = attributes
|
227
|
+
|
228
|
+
@request_headers = attributes.fetch("request_headers")
|
229
|
+
@request_method = attributes.fetch("request_method")
|
230
|
+
@request_path = attributes.fetch("request_path")
|
231
|
+
@request_query_parameters = attributes.fetch("request_query_parameters", nil)
|
232
|
+
@request_body = attributes.fetch("request_body", nil)
|
233
|
+
@curl = attributes.fetch("curl", nil)
|
234
|
+
@response_status = attributes.fetch("response_status")
|
235
|
+
@response_headers = attributes.fetch("response_headers", {})
|
236
|
+
@response_body = attributes.fetch("response_body", nil)
|
237
|
+
end
|
238
|
+
|
239
|
+
# There are unwanted indents if this was a simple each and output in haml
|
240
|
+
def request_headers
|
241
|
+
@request_headers.map do |header, value|
|
242
|
+
"#{header}: #{value}"
|
243
|
+
end.join("\n")
|
244
|
+
end
|
245
|
+
|
246
|
+
# @return [String] joined query parameters, eg: "key=value\nkey=value"
|
247
|
+
def request_query_parameters
|
248
|
+
@request_query_parameters.map { |k,v| "#{k}=#{v}" }.join("\n")
|
249
|
+
end
|
250
|
+
|
251
|
+
# @return [Boolean] true if request query parameters are present
|
252
|
+
def request_query_parameters?
|
253
|
+
!@request_query_parameters.empty?
|
254
|
+
end
|
255
|
+
|
256
|
+
# @return [Boolean] true if request body is present
|
257
|
+
def request_body?
|
258
|
+
!@request_body.nil?
|
259
|
+
end
|
260
|
+
|
261
|
+
# Request headers must be set
|
262
|
+
# @return [String] Content type of the request
|
263
|
+
def request_content_type
|
264
|
+
@request_headers["Content-Type"]
|
265
|
+
end
|
266
|
+
|
267
|
+
# @return [Boolean] true if cURL command is present
|
268
|
+
def curl?
|
269
|
+
!@curl.nil?
|
270
|
+
end
|
271
|
+
|
272
|
+
# @return [Boolean] true if the response is present
|
273
|
+
def response?
|
274
|
+
!@response_status.nil?
|
275
|
+
end
|
276
|
+
|
277
|
+
# There are unwanted indents if this was a simple each and output in haml
|
278
|
+
def response_headers
|
279
|
+
@response_headers.map do |header, value|
|
280
|
+
"#{header}: #{value}"
|
281
|
+
end.join("\n")
|
282
|
+
end
|
283
|
+
|
284
|
+
# @return [Boolean] true if response body is present
|
285
|
+
def response_body?
|
286
|
+
!@response_body.nil?
|
287
|
+
end
|
288
|
+
|
289
|
+
# Response headers must be set
|
290
|
+
# @return [String] Content type of the response
|
291
|
+
def response_content_type
|
292
|
+
@response_headers["Content-Type"]
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
data/lib/views/example.haml
CHANGED
@@ -27,99 +27,111 @@
|
|
27
27
|
.nav-bar
|
28
28
|
= link_to "« Back to Index", "/"
|
29
29
|
|
30
|
-
%h1== #{example
|
30
|
+
%h1== #{example.resource} API
|
31
31
|
.article
|
32
|
-
%h2= example
|
32
|
+
%h2= example.description
|
33
33
|
|
34
|
-
- if example
|
34
|
+
- if example.explanation?
|
35
35
|
%p.explanation
|
36
|
-
= example
|
36
|
+
= example.explanation
|
37
37
|
|
38
|
-
- if example
|
38
|
+
- if example.parameters.present?
|
39
39
|
%h3 Parameters
|
40
40
|
%table.parameters
|
41
41
|
%thead
|
42
42
|
%tr
|
43
43
|
%th Name
|
44
44
|
%th Description
|
45
|
-
- example
|
45
|
+
- example.parameters.extra_keys.each do |key|
|
46
46
|
%th= key
|
47
47
|
%tbody
|
48
|
-
- example
|
48
|
+
- example.parameters.params.each do |param|
|
49
49
|
%tr.parameter
|
50
|
-
%td{:class => ("required" if param
|
51
|
-
- if param
|
52
|
-
%span.name #{param
|
50
|
+
%td{:class => ("required" if param.required?)}
|
51
|
+
- if param.scope?
|
52
|
+
%span.name #{param.scope}[#{param.name}]
|
53
53
|
- else
|
54
|
-
%span.name= param
|
54
|
+
%span.name= param.name
|
55
55
|
%td
|
56
|
-
%span.description= param
|
57
|
-
- example
|
56
|
+
%span.description= param.description
|
57
|
+
- example.parameters.extra_keys.each do |key|
|
58
58
|
%td
|
59
59
|
%span.extras= param[key]
|
60
60
|
|
61
|
+
- if example.response_fields.present?
|
62
|
+
%h3 Response Fields
|
63
|
+
%table.response-fields
|
64
|
+
%thead
|
65
|
+
%tr
|
66
|
+
%th Name
|
67
|
+
%th Description
|
68
|
+
- example.response_fields.extra_keys.each do |key|
|
69
|
+
%th= key
|
70
|
+
%tbody
|
71
|
+
- example.response_fields.fields.each do |field|
|
72
|
+
%tr.response-field
|
73
|
+
%td
|
74
|
+
- if field.scope?
|
75
|
+
%span.name #{field.scope}[#{field.name}]
|
76
|
+
- else
|
77
|
+
%span.name= field.name
|
78
|
+
%td
|
79
|
+
%span.description= field.description
|
80
|
+
- example.response_fields.extra_keys.each do |key|
|
81
|
+
%td
|
82
|
+
%span.extras= field[key]
|
61
83
|
|
62
|
-
- example
|
84
|
+
- example.requests.each_with_index do |request, index|
|
63
85
|
.request{ :id => "request-#{index}" }
|
64
86
|
%h3 Request
|
65
87
|
|
66
88
|
%section.headers
|
67
89
|
%h4 Headers
|
68
90
|
%pre.headers
|
69
|
-
:ruby
|
70
|
-
# There are unwanted indents if this was a simple each and output in haml
|
71
|
-
headers = request["request_headers"].map do |header, value|
|
72
|
-
"#{header}: #{value}"
|
73
|
-
end
|
74
91
|
:preserve
|
75
|
-
#{
|
92
|
+
#{request.request_headers}
|
76
93
|
|
77
94
|
%section.route
|
78
95
|
%h4 Route
|
79
|
-
%pre.route.highlight== #{request
|
96
|
+
%pre.route.highlight== #{request.request_method} #{request.request_path}
|
80
97
|
|
81
|
-
- if
|
98
|
+
- if request.request_query_parameters?
|
82
99
|
%section.query-parameters
|
83
100
|
%h4 Query Parameters
|
84
101
|
%pre.query-parameters.highlight
|
85
|
-
= request
|
102
|
+
= request.request_query_parameters
|
86
103
|
|
87
|
-
- if request
|
104
|
+
- if request.request_body?
|
88
105
|
%section.body
|
89
106
|
%h4 Body
|
90
|
-
.content{ "data-content-type" => request
|
107
|
+
.content{ "data-content-type" => request.request_content_type }
|
91
108
|
%textarea
|
92
109
|
:preserve
|
93
|
-
#{request
|
110
|
+
#{request.request_body}
|
94
111
|
|
95
|
-
- if request
|
112
|
+
- if request.curl?
|
96
113
|
%section.curl
|
97
114
|
%h4 cURL
|
98
|
-
%pre= request
|
115
|
+
%pre= request.curl
|
99
116
|
|
100
|
-
- if request
|
117
|
+
- if request.response?
|
101
118
|
.response
|
102
119
|
%h3 Response
|
103
120
|
|
104
121
|
%section.headers
|
105
122
|
%h4 Headers
|
106
123
|
%pre.headers
|
107
|
-
:ruby
|
108
|
-
# There are unwanted indents if this was a simple each and output in haml
|
109
|
-
headers = request["response_headers"].map do |header, value|
|
110
|
-
"#{header}: #{html_escape(value)}"
|
111
|
-
end
|
112
124
|
:preserve
|
113
|
-
#{
|
125
|
+
#{request.response_headers}
|
114
126
|
|
115
127
|
%section.status
|
116
128
|
%h4 Status
|
117
|
-
%pre.status= request
|
129
|
+
%pre.status= request.response_status
|
118
130
|
|
119
|
-
- if request
|
131
|
+
- if request.response_body?
|
120
132
|
%section.body
|
121
133
|
%h4 Body
|
122
|
-
.content{ "data-content-type" => request
|
134
|
+
.content{ "data-content-type" => request.response_content_type }
|
123
135
|
%textarea
|
124
136
|
:preserve
|
125
|
-
#{request
|
137
|
+
#{request.response_body}
|
data/lib/views/index.haml
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
%h1= api_name
|
2
2
|
|
3
|
-
- index
|
3
|
+
- index.resources.each do |resource|
|
4
4
|
.resource
|
5
|
-
%h2= resource
|
5
|
+
%h2= resource.name
|
6
6
|
%ul.examples
|
7
|
-
- resource
|
7
|
+
- resource.examples.each do |example|
|
8
8
|
%li.example
|
9
|
-
= link_to example
|
9
|
+
= link_to example.description, "/#{example.href}"
|
data/lib/views/layout.haml
CHANGED
data/lib/views/nav.haml
ADDED
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: 0.5.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: 2015-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -76,20 +76,14 @@ dependencies:
|
|
76
76
|
requirements:
|
77
77
|
- - "~>"
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: '
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 2.9.0
|
79
|
+
version: '3.0'
|
83
80
|
type: :development
|
84
81
|
prerelease: false
|
85
82
|
version_requirements: !ruby/object:Gem::Requirement
|
86
83
|
requirements:
|
87
84
|
- - "~>"
|
88
85
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
90
|
-
- - ">="
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: 2.9.0
|
86
|
+
version: '3.0'
|
93
87
|
- !ruby/object:Gem::Dependency
|
94
88
|
name: rack-test
|
95
89
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,9 +91,6 @@ dependencies:
|
|
97
91
|
- - "~>"
|
98
92
|
- !ruby/object:Gem::Version
|
99
93
|
version: '0.6'
|
100
|
-
- - ">="
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: 0.6.1
|
103
94
|
type: :development
|
104
95
|
prerelease: false
|
105
96
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -107,49 +98,34 @@ dependencies:
|
|
107
98
|
- - "~>"
|
108
99
|
- !ruby/object:Gem::Version
|
109
100
|
version: '0.6'
|
110
|
-
- - ">="
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version: 0.6.1
|
113
101
|
- !ruby/object:Gem::Dependency
|
114
102
|
name: capybara
|
115
103
|
requirement: !ruby/object:Gem::Requirement
|
116
104
|
requirements:
|
117
105
|
- - "~>"
|
118
106
|
- !ruby/object:Gem::Version
|
119
|
-
version: '
|
120
|
-
- - ">="
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
version: 1.1.2
|
107
|
+
version: '2.3'
|
123
108
|
type: :development
|
124
109
|
prerelease: false
|
125
110
|
version_requirements: !ruby/object:Gem::Requirement
|
126
111
|
requirements:
|
127
112
|
- - "~>"
|
128
113
|
- !ruby/object:Gem::Version
|
129
|
-
version: '
|
130
|
-
- - ">="
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
version: 1.1.2
|
114
|
+
version: '2.3'
|
133
115
|
- !ruby/object:Gem::Dependency
|
134
116
|
name: rake
|
135
117
|
requirement: !ruby/object:Gem::Requirement
|
136
118
|
requirements:
|
137
119
|
- - "~>"
|
138
120
|
- !ruby/object:Gem::Version
|
139
|
-
version: '0
|
140
|
-
- - ">="
|
141
|
-
- !ruby/object:Gem::Version
|
142
|
-
version: 0.9.2.2
|
121
|
+
version: '10.0'
|
143
122
|
type: :development
|
144
123
|
prerelease: false
|
145
124
|
version_requirements: !ruby/object:Gem::Requirement
|
146
125
|
requirements:
|
147
126
|
- - "~>"
|
148
127
|
- !ruby/object:Gem::Version
|
149
|
-
version: '0
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: 0.9.2.2
|
128
|
+
version: '10.0'
|
153
129
|
description: Browse documentation generated by the rspec_api_documentation gem
|
154
130
|
email:
|
155
131
|
- eric@oestrich.org
|
@@ -170,10 +146,11 @@ files:
|
|
170
146
|
- lib/raddocs/app.rb
|
171
147
|
- lib/raddocs/configuration.rb
|
172
148
|
- lib/raddocs/middleware.rb
|
173
|
-
- lib/raddocs/
|
149
|
+
- lib/raddocs/models.rb
|
174
150
|
- lib/views/example.haml
|
175
151
|
- lib/views/index.haml
|
176
152
|
- lib/views/layout.haml
|
153
|
+
- lib/views/nav.haml
|
177
154
|
homepage: http://github.com/oestrich/raddocs
|
178
155
|
licenses:
|
179
156
|
- MIT
|
@@ -194,8 +171,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
171
|
version: 1.3.6
|
195
172
|
requirements: []
|
196
173
|
rubyforge_project:
|
197
|
-
rubygems_version: 2.2.
|
174
|
+
rubygems_version: 2.2.2
|
198
175
|
signing_key:
|
199
176
|
specification_version: 4
|
200
177
|
summary: rspec_api_documentation browser
|
201
178
|
test_files: []
|
179
|
+
has_rdoc:
|
data/lib/raddocs/parameters.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module Raddocs
|
2
|
-
class Parameters
|
3
|
-
def initialize(params)
|
4
|
-
@params = params
|
5
|
-
end
|
6
|
-
|
7
|
-
def parse
|
8
|
-
extra_keys = @params.flat_map(&:keys).uniq - ["name", "description", "required", "scope"]
|
9
|
-
|
10
|
-
{
|
11
|
-
"extra_keys" => extra_keys,
|
12
|
-
"data" => @params
|
13
|
-
}
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|