rspec_api_documentation 0.9.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rspec_api_documentation.rb +11 -8
- data/lib/rspec_api_documentation/api_documentation.rb +1 -2
- data/lib/rspec_api_documentation/configuration.rb +0 -2
- data/lib/rspec_api_documentation/curl.rb +1 -1
- data/lib/rspec_api_documentation/example.rb +1 -1
- data/lib/rspec_api_documentation/writers/combined_json_writer.rb +20 -0
- data/lib/rspec_api_documentation/writers/combined_text_writer.rb +106 -0
- data/lib/rspec_api_documentation/writers/formatter.rb +11 -0
- data/lib/rspec_api_documentation/writers/html_writer.rb +102 -0
- data/lib/rspec_api_documentation/writers/index_writer.rb +16 -0
- data/lib/rspec_api_documentation/writers/json_iodocs_writer.rb +111 -0
- data/lib/rspec_api_documentation/writers/json_writer.rb +111 -0
- data/templates/rspec_api_documentation/html_example.mustache +12 -41
- data/templates/rspec_api_documentation/html_index.mustache +9 -2
- metadata +10 -28
- data/lib/rspec_api_documentation/combined_json_writer.rb +0 -18
- data/lib/rspec_api_documentation/combined_text_writer.rb +0 -104
- data/lib/rspec_api_documentation/html_writer.rb +0 -107
- data/lib/rspec_api_documentation/index_writer.rb +0 -14
- data/lib/rspec_api_documentation/json_iodocs_writer.rb +0 -107
- data/lib/rspec_api_documentation/json_writer.rb +0 -111
- data/lib/rspec_api_documentation/wurl_writer.rb +0 -110
- data/templates/assets/img/glyphicons-halflings-white.png +0 -0
- data/templates/assets/img/glyphicons-halflings.png +0 -0
- data/templates/assets/javascripts/application.js +0 -250
- data/templates/assets/javascripts/codemirror.js +0 -3636
- data/templates/assets/javascripts/jquery-1-7-2.js +0 -9401
- data/templates/assets/javascripts/jquery-base64.js +0 -189
- data/templates/assets/javascripts/jquery-livequery.js +0 -226
- data/templates/assets/javascripts/jquery-ui-1-8-16-min.js +0 -791
- data/templates/assets/javascripts/mode/css/css.js +0 -124
- data/templates/assets/javascripts/mode/htmlmixed/htmlmixed.js +0 -85
- data/templates/assets/javascripts/mode/javascript/javascript.js +0 -361
- data/templates/assets/javascripts/mode/xml/xml.js +0 -325
- data/templates/assets/stylesheets/application.css +0 -68
- data/templates/assets/stylesheets/bootstrap.css +0 -4960
- data/templates/assets/stylesheets/codemirror.css +0 -230
- data/templates/rspec_api_documentation/example.json +0 -1
- data/templates/rspec_api_documentation/index.json +0 -1
- data/templates/rspec_api_documentation/wurl_example.mustache +0 -242
- data/templates/rspec_api_documentation/wurl_index.mustache +0 -27
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'rspec_api_documentation/writers/formatter'
|
2
|
+
|
3
|
+
module RspecApiDocumentation
|
4
|
+
module Writers
|
5
|
+
class JsonWriter
|
6
|
+
attr_accessor :index, :configuration
|
7
|
+
delegate :docs_dir, :to => :configuration
|
8
|
+
|
9
|
+
def initialize(index, configuration)
|
10
|
+
self.index = index
|
11
|
+
self.configuration = configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.write(index, configuration)
|
15
|
+
writer = new(index, configuration)
|
16
|
+
writer.write
|
17
|
+
end
|
18
|
+
|
19
|
+
def write
|
20
|
+
File.open(docs_dir.join("index.json"), "w+") do |f|
|
21
|
+
f.write Formatter.to_json(JsonIndex.new(index, configuration))
|
22
|
+
end
|
23
|
+
index.examples.each do |example|
|
24
|
+
json_example = JsonExample.new(example, configuration)
|
25
|
+
FileUtils.mkdir_p(docs_dir.join(json_example.dirname))
|
26
|
+
File.open(docs_dir.join(json_example.dirname, json_example.filename), "w+") do |f|
|
27
|
+
f.write Formatter.to_json(json_example)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class JsonIndex
|
34
|
+
def initialize(index, configuration)
|
35
|
+
@index = index
|
36
|
+
@configuration = configuration
|
37
|
+
end
|
38
|
+
|
39
|
+
def sections
|
40
|
+
IndexWriter.sections(examples, @configuration)
|
41
|
+
end
|
42
|
+
|
43
|
+
def examples
|
44
|
+
@index.examples.map { |example| JsonExample.new(example, @configuration) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def as_json(opts = nil)
|
48
|
+
sections.inject({:resources => []}) do |h, section|
|
49
|
+
h[:resources].push(
|
50
|
+
:name => section[:resource_name],
|
51
|
+
:examples => section[:examples].map { |example|
|
52
|
+
{
|
53
|
+
:description => example.description,
|
54
|
+
:link => "#{example.dirname}/#{example.filename}",
|
55
|
+
:groups => example.metadata[:document]
|
56
|
+
}
|
57
|
+
}
|
58
|
+
)
|
59
|
+
h
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class JsonExample
|
65
|
+
def initialize(example, configuration)
|
66
|
+
@example = example
|
67
|
+
@host = configuration.curl_host
|
68
|
+
end
|
69
|
+
|
70
|
+
def method_missing(method, *args, &block)
|
71
|
+
@example.send(method, *args, &block)
|
72
|
+
end
|
73
|
+
|
74
|
+
def respond_to?(method, include_private = false)
|
75
|
+
super || @example.respond_to?(method, include_private)
|
76
|
+
end
|
77
|
+
|
78
|
+
def dirname
|
79
|
+
resource_name.downcase.gsub(/\s+/, '_')
|
80
|
+
end
|
81
|
+
|
82
|
+
def filename
|
83
|
+
basename = description.downcase.gsub(/\s+/, '_').gsub(/[^a-z_]/, '')
|
84
|
+
"#{basename}.json"
|
85
|
+
end
|
86
|
+
|
87
|
+
def as_json(opts = nil)
|
88
|
+
{
|
89
|
+
:resource => resource_name,
|
90
|
+
:http_method => http_method,
|
91
|
+
:route => route,
|
92
|
+
:description => description,
|
93
|
+
:explanation => explanation,
|
94
|
+
:parameters => respond_to?(:parameters) ? parameters : [],
|
95
|
+
:requests => requests
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
def requests
|
100
|
+
super.map do |hash|
|
101
|
+
if @host
|
102
|
+
hash[:curl] = hash[:curl].output(@host) if hash[:curl].is_a? RspecApiDocumentation::Curl
|
103
|
+
else
|
104
|
+
hash[:curl] = nil
|
105
|
+
end
|
106
|
+
hash
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -3,45 +3,6 @@
|
|
3
3
|
<head>
|
4
4
|
<title>{{resource_name}} API</title>
|
5
5
|
<meta charset="utf-8">
|
6
|
-
<link rel="stylesheet" href="{{url_prefix}}/assets/stylesheets/bootstrap.css"/>
|
7
|
-
<link rel="stylesheet" href="{{url_prefix}}/assets/stylesheets/codemirror.css"/>
|
8
|
-
<link rel="stylesheet" href="{{url_prefix}}/assets/stylesheets/application.css"/>
|
9
|
-
<script src="{{url_prefix}}/assets/javascripts/jquery-1-7-2.js"></script>
|
10
|
-
<script src="{{url_prefix}}/assets/javascripts/codemirror.js"></script>
|
11
|
-
<script src="{{url_prefix}}/assets/javascripts/mode/css/css.js"></script>
|
12
|
-
<script src="{{url_prefix}}/assets/javascripts/mode/htmlmixed/htmlmixed.js"></script>
|
13
|
-
<script src="{{url_prefix}}/assets/javascripts/mode/javascript/javascript.js"></script>
|
14
|
-
<script src="{{url_prefix}}/assets/javascripts/mode/xml/xml.js"></script>
|
15
|
-
<script>
|
16
|
-
function mirror(textarea, contentType, options) {
|
17
|
-
$textarea = $(textarea);
|
18
|
-
if ($textarea.val() != '') {
|
19
|
-
if(contentType.indexOf('json') >= 0) {
|
20
|
-
$textarea.val(JSON.stringify(JSON.parse($textarea.val()), undefined, 2));
|
21
|
-
options.json = true;
|
22
|
-
options.mode = 'javascript';
|
23
|
-
} else if (contentType.indexOf('javascript') >= 0) {
|
24
|
-
options.mode = 'javascript';
|
25
|
-
} else if (contentType.indexOf('xml') >= 0) {
|
26
|
-
options.mode = 'xml';
|
27
|
-
} else {
|
28
|
-
options.mode = 'htmlmixed';
|
29
|
-
}
|
30
|
-
}
|
31
|
-
return CodeMirror.fromTextArea(textarea, options);
|
32
|
-
};
|
33
|
-
|
34
|
-
$(function(){
|
35
|
-
$(".request.body").each(function(i, el) {
|
36
|
-
el = $(el);
|
37
|
-
mirror(el.find("textarea")[0], el.data("content-type"), { "readOnly": true, "lineNumbers": true });
|
38
|
-
});
|
39
|
-
$(".response.body").each(function(i, el) {
|
40
|
-
el = $(el);
|
41
|
-
mirror(el.find("textarea")[0], el.data("content-type"), { "readOnly": true, "lineNumbers": true });
|
42
|
-
});
|
43
|
-
});
|
44
|
-
</script>
|
45
6
|
<style>
|
46
7
|
td.required .name:after {
|
47
8
|
float: right;
|
@@ -54,6 +15,16 @@
|
|
54
15
|
padding: 15px;
|
55
16
|
font-size: 130%;
|
56
17
|
}
|
18
|
+
|
19
|
+
pre {
|
20
|
+
white-space: pre-wrap;
|
21
|
+
}
|
22
|
+
|
23
|
+
body {
|
24
|
+
margin-left: auto;
|
25
|
+
margin-right: auto;
|
26
|
+
width: 900px;
|
27
|
+
}
|
57
28
|
</style>
|
58
29
|
</head>
|
59
30
|
<body>
|
@@ -109,7 +80,7 @@
|
|
109
80
|
|
110
81
|
{{# request_body }}
|
111
82
|
<h4>Body</h4>
|
112
|
-
<
|
83
|
+
<pre class="request body">{{{ request_body }}}</pre>
|
113
84
|
{{/ request_body }}
|
114
85
|
|
115
86
|
{{# curl }}
|
@@ -125,7 +96,7 @@
|
|
125
96
|
<pre class="response status">{{ response_status }} {{ response_status_text}}</pre>
|
126
97
|
{{# response_body }}
|
127
98
|
<h4>Body</h4>
|
128
|
-
<
|
99
|
+
<pre class="response body">{{{ response_body }}}</pre>
|
129
100
|
{{/ response_body }}
|
130
101
|
{{/ response_status }}
|
131
102
|
{{/ requests }}
|
@@ -3,7 +3,14 @@
|
|
3
3
|
<head>
|
4
4
|
<title>{{ api_name }}</title>
|
5
5
|
<meta charset="utf-8">
|
6
|
-
|
6
|
+
|
7
|
+
<style>
|
8
|
+
body {
|
9
|
+
margin-left: auto;
|
10
|
+
margin-right: auto;
|
11
|
+
width: 900px;
|
12
|
+
}
|
13
|
+
</style>
|
7
14
|
</head>
|
8
15
|
<body>
|
9
16
|
<div class="container">
|
@@ -16,7 +23,7 @@
|
|
16
23
|
<ul>
|
17
24
|
{{# examples }}
|
18
25
|
<li>
|
19
|
-
<a href="{{
|
26
|
+
<a href="{{ dirname }}/{{ filename }}">{{ description }}</a>
|
20
27
|
</li>
|
21
28
|
{{/ examples }}
|
22
29
|
</ul>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_api_documentation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-06-24 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rspec
|
@@ -234,48 +234,29 @@ files:
|
|
234
234
|
- lib/tasks/docs.rake
|
235
235
|
- lib/rspec_api_documentation/rack_test_client.rb
|
236
236
|
- lib/rspec_api_documentation/api_formatter.rb
|
237
|
-
- lib/rspec_api_documentation/html_writer.rb
|
238
237
|
- lib/rspec_api_documentation/curl.rb
|
239
|
-
- lib/rspec_api_documentation/json_iodocs_writer.rb
|
240
238
|
- lib/rspec_api_documentation/index.rb
|
241
239
|
- lib/rspec_api_documentation/headers.rb
|
242
|
-
- lib/rspec_api_documentation/wurl_writer.rb
|
243
240
|
- lib/rspec_api_documentation/oauth2_mac_client.rb
|
244
241
|
- lib/rspec_api_documentation/dsl/callback.rb
|
245
242
|
- lib/rspec_api_documentation/dsl/endpoint.rb
|
246
243
|
- lib/rspec_api_documentation/dsl/resource.rb
|
247
|
-
- lib/rspec_api_documentation/json_writer.rb
|
248
244
|
- lib/rspec_api_documentation/dsl.rb
|
245
|
+
- lib/rspec_api_documentation/writers/html_writer.rb
|
246
|
+
- lib/rspec_api_documentation/writers/json_iodocs_writer.rb
|
247
|
+
- lib/rspec_api_documentation/writers/json_writer.rb
|
248
|
+
- lib/rspec_api_documentation/writers/combined_json_writer.rb
|
249
|
+
- lib/rspec_api_documentation/writers/formatter.rb
|
250
|
+
- lib/rspec_api_documentation/writers/index_writer.rb
|
251
|
+
- lib/rspec_api_documentation/writers/combined_text_writer.rb
|
249
252
|
- lib/rspec_api_documentation/configuration.rb
|
250
|
-
- lib/rspec_api_documentation/combined_json_writer.rb
|
251
253
|
- lib/rspec_api_documentation/example.rb
|
252
254
|
- lib/rspec_api_documentation/api_documentation.rb
|
253
255
|
- lib/rspec_api_documentation/test_server.rb
|
254
256
|
- lib/rspec_api_documentation/railtie.rb
|
255
|
-
- lib/rspec_api_documentation/index_writer.rb
|
256
|
-
- lib/rspec_api_documentation/combined_text_writer.rb
|
257
257
|
- lib/rspec_api_documentation/client_base.rb
|
258
|
-
- templates/assets/javascripts/jquery-1-7-2.js
|
259
|
-
- templates/assets/javascripts/codemirror.js
|
260
|
-
- templates/assets/javascripts/jquery-base64.js
|
261
|
-
- templates/assets/javascripts/jquery-ui-1-8-16-min.js
|
262
|
-
- templates/assets/javascripts/mode/javascript/javascript.js
|
263
|
-
- templates/assets/javascripts/mode/css/css.js
|
264
|
-
- templates/assets/javascripts/mode/xml/xml.js
|
265
|
-
- templates/assets/javascripts/mode/htmlmixed/htmlmixed.js
|
266
|
-
- templates/assets/javascripts/jquery-livequery.js
|
267
|
-
- templates/assets/javascripts/application.js
|
268
|
-
- templates/assets/img/glyphicons-halflings-white.png
|
269
|
-
- templates/assets/img/glyphicons-halflings.png
|
270
|
-
- templates/assets/stylesheets/application.css
|
271
|
-
- templates/assets/stylesheets/codemirror.css
|
272
|
-
- templates/assets/stylesheets/bootstrap.css
|
273
258
|
- templates/rspec_api_documentation/html_index.mustache
|
274
|
-
- templates/rspec_api_documentation/index.json
|
275
|
-
- templates/rspec_api_documentation/wurl_example.mustache
|
276
259
|
- templates/rspec_api_documentation/html_example.mustache
|
277
|
-
- templates/rspec_api_documentation/example.json
|
278
|
-
- templates/rspec_api_documentation/wurl_index.mustache
|
279
260
|
homepage: http://smartlogicsolutions.com
|
280
261
|
licenses: []
|
281
262
|
post_install_message:
|
@@ -301,3 +282,4 @@ signing_key:
|
|
301
282
|
specification_version: 3
|
302
283
|
summary: A double black belt for your docs
|
303
284
|
test_files: []
|
285
|
+
has_rdoc:
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rspec_api_documentation/json_writer'
|
2
|
-
|
3
|
-
module RspecApiDocumentation
|
4
|
-
class CombinedJsonWriter
|
5
|
-
def self.write(index, configuration)
|
6
|
-
File.open(configuration.docs_dir.join("combined.json"), "w+") do |f|
|
7
|
-
examples = []
|
8
|
-
index.examples.each do |rspec_example|
|
9
|
-
examples << JsonExample.new(rspec_example, configuration).to_json
|
10
|
-
end
|
11
|
-
|
12
|
-
f.write "["
|
13
|
-
f.write examples.join(",")
|
14
|
-
f.write "]"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
module RspecApiDocumentation
|
2
|
-
class CombinedTextWriter
|
3
|
-
def self.write(index, configuration)
|
4
|
-
index.examples.each do |rspec_example|
|
5
|
-
example = CombinedTextExample.new(rspec_example)
|
6
|
-
FileUtils.mkdir_p(configuration.docs_dir.join(example.resource_name))
|
7
|
-
File.open(configuration.docs_dir.join(example.resource_name, "index.txt"), "a+") do |f|
|
8
|
-
f.print example.description
|
9
|
-
f.print example.parameters
|
10
|
-
|
11
|
-
example.requests.each_with_index do |(request, response), i|
|
12
|
-
f.puts "Request:"
|
13
|
-
f.puts request
|
14
|
-
f.puts
|
15
|
-
f.puts "Response:"
|
16
|
-
f.puts response
|
17
|
-
|
18
|
-
if i + 1 < example.requests.count
|
19
|
-
f.puts
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
unless rspec_example == index.examples.last
|
24
|
-
f.puts
|
25
|
-
f.puts
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.format_hash(hash, separator="=")
|
32
|
-
hash.sort_by { |k, v| k }.inject("") do |out, (k, v)|
|
33
|
-
out << " #{k}#{separator}#{v}\n"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class CombinedTextExample
|
39
|
-
attr_reader :example
|
40
|
-
|
41
|
-
def initialize(example)
|
42
|
-
@example = example
|
43
|
-
end
|
44
|
-
|
45
|
-
def resource_name
|
46
|
-
example.resource_name.downcase.gsub(/\s+/, '_')
|
47
|
-
end
|
48
|
-
|
49
|
-
def description
|
50
|
-
example.description + "\n" + "-" * example.description.length + "\n\n"
|
51
|
-
end
|
52
|
-
|
53
|
-
def parameters
|
54
|
-
return "" unless example.metadata[:parameters]
|
55
|
-
"Parameters:\n" + example.metadata[:parameters].inject("") do |out, parameter|
|
56
|
-
out << " * #{parameter[:name]} - #{parameter[:description]}\n"
|
57
|
-
end + "\n"
|
58
|
-
end
|
59
|
-
|
60
|
-
def requests
|
61
|
-
return [] unless example.metadata[:requests]
|
62
|
-
example.metadata[:requests].map do |request|
|
63
|
-
[format_request(request), format_response(request)]
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
def format_request(request)
|
69
|
-
[
|
70
|
-
[
|
71
|
-
" #{request[:request_method]} #{request[:request_path]}",
|
72
|
-
format_hash(request[:request_headers], ": ")
|
73
|
-
],
|
74
|
-
[
|
75
|
-
format_string(request[:request_body]) || format_hash(request[:request_query_parameters])
|
76
|
-
]
|
77
|
-
].map { |x| x.compact.join("\n") }.reject(&:blank?).join("\n\n") + "\n"
|
78
|
-
end
|
79
|
-
|
80
|
-
def format_response(request)
|
81
|
-
[
|
82
|
-
[
|
83
|
-
" Status: #{request[:response_status]} #{request[:response_status_text]}",
|
84
|
-
format_hash(request[:response_headers], ": ")
|
85
|
-
],
|
86
|
-
[
|
87
|
-
format_string(request[:response_body])
|
88
|
-
]
|
89
|
-
].map { |x| x.compact.join("\n") }.reject(&:blank?).join("\n\n") + "\n"
|
90
|
-
end
|
91
|
-
|
92
|
-
def format_string(string)
|
93
|
-
return unless string
|
94
|
-
string.split("\n").map { |line| " #{line}" }.join("\n")
|
95
|
-
end
|
96
|
-
|
97
|
-
def format_hash(hash, separator="=")
|
98
|
-
return unless hash
|
99
|
-
hash.sort_by { |k, v| k }.map do |k, v|
|
100
|
-
" #{k}#{separator}#{v}"
|
101
|
-
end.join("\n")
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'mustache'
|
2
|
-
|
3
|
-
module RspecApiDocumentation
|
4
|
-
class HtmlWriter
|
5
|
-
attr_accessor :index, :configuration
|
6
|
-
|
7
|
-
def initialize(index, configuration)
|
8
|
-
warn "[NOTICE] Assets will be gone from the next release. Please use Raddocs for nicer looking docs"
|
9
|
-
self.index = index
|
10
|
-
self.configuration = configuration
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.write(index, configuration)
|
14
|
-
writer = new(index, configuration)
|
15
|
-
writer.write
|
16
|
-
end
|
17
|
-
|
18
|
-
def write
|
19
|
-
File.open(configuration.docs_dir.join("index.html"), "w+") do |f|
|
20
|
-
f.write HtmlIndex.new(index, configuration).render
|
21
|
-
end
|
22
|
-
index.examples.each do |example|
|
23
|
-
html_example = HtmlExample.new(example, configuration)
|
24
|
-
FileUtils.mkdir_p(configuration.docs_dir.join(html_example.dirname))
|
25
|
-
File.open(configuration.docs_dir.join(html_example.dirname, html_example.filename), "w+") do |f|
|
26
|
-
f.write html_example.render
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class HtmlIndex < Mustache
|
33
|
-
def initialize(index, configuration)
|
34
|
-
@index = index
|
35
|
-
@configuration = configuration
|
36
|
-
self.template_path = configuration.template_path
|
37
|
-
end
|
38
|
-
|
39
|
-
def api_name
|
40
|
-
@configuration.api_name
|
41
|
-
end
|
42
|
-
|
43
|
-
def sections
|
44
|
-
IndexWriter.sections(examples, @configuration)
|
45
|
-
end
|
46
|
-
|
47
|
-
def url_prefix
|
48
|
-
@configuration.url_prefix
|
49
|
-
end
|
50
|
-
|
51
|
-
def examples
|
52
|
-
@index.examples.map { |example| HtmlExample.new(example, @configuration) }
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
class HtmlExample < Mustache
|
57
|
-
def initialize(example, configuration)
|
58
|
-
@example = example
|
59
|
-
@host = configuration.curl_host
|
60
|
-
self.template_path = configuration.template_path
|
61
|
-
end
|
62
|
-
|
63
|
-
def method_missing(method, *args, &block)
|
64
|
-
@example.send(method, *args, &block)
|
65
|
-
end
|
66
|
-
|
67
|
-
def respond_to?(method, include_private = false)
|
68
|
-
super || @example.respond_to?(method, include_private)
|
69
|
-
end
|
70
|
-
|
71
|
-
def dirname
|
72
|
-
resource_name.downcase.gsub(/\s+/, '_')
|
73
|
-
end
|
74
|
-
|
75
|
-
def filename
|
76
|
-
basename = description.downcase.gsub(/\s+/, '_').gsub(/[^a-z_]/, '')
|
77
|
-
basename = Digest::MD5.new.update(description).to_s if basename.blank?
|
78
|
-
"#{basename}.html"
|
79
|
-
end
|
80
|
-
|
81
|
-
def requests
|
82
|
-
super.map do |hash|
|
83
|
-
hash[:request_headers_text] = format_hash(hash[:request_headers])
|
84
|
-
hash[:request_query_parameters_text] = format_hash(hash[:request_query_parameters])
|
85
|
-
hash[:response_headers_text] = format_hash(hash[:response_headers])
|
86
|
-
if @host
|
87
|
-
hash[:curl] = hash[:curl].output(@host) if hash[:curl].is_a? RspecApiDocumentation::Curl
|
88
|
-
else
|
89
|
-
hash[:curl] = nil
|
90
|
-
end
|
91
|
-
hash
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def url_prefix
|
96
|
-
configuration.url_prefix
|
97
|
-
end
|
98
|
-
|
99
|
-
private
|
100
|
-
def format_hash(hash = {})
|
101
|
-
return nil unless hash.present?
|
102
|
-
hash.collect do |k, v|
|
103
|
-
"#{k}: #{v}"
|
104
|
-
end.join("\n")
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|