dox 1.2.0 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +6 -3
- data/.ruby-version +1 -1
- data/.travis.yml +7 -11
- data/CHANGES.md +17 -0
- data/Gemfile +1 -1
- data/README.md +90 -108
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/dox.gemspec +14 -13
- data/lib/dox.rb +9 -1
- data/lib/dox/config.rb +38 -5
- data/lib/dox/dsl/action.rb +10 -4
- data/lib/dox/dsl/documentation.rb +4 -0
- data/lib/dox/dsl/syntax.rb +1 -0
- data/lib/dox/entities/action.rb +33 -13
- data/lib/dox/entities/example.rb +11 -1
- data/lib/dox/entities/resource.rb +4 -5
- data/lib/dox/entities/resource_group.rb +2 -3
- data/lib/dox/formatter.rb +10 -11
- data/lib/dox/printers/action_printer.rb +18 -27
- data/lib/dox/printers/base_printer.rb +36 -17
- data/lib/dox/printers/document_printer.rb +27 -7
- data/lib/dox/printers/example_request_printer.rb +69 -0
- data/lib/dox/printers/example_response_printer.rb +86 -0
- data/lib/dox/printers/resource_group_printer.rb +7 -7
- data/lib/dox/printers/resource_printer.rb +12 -7
- data/lib/dox/util/http.rb +64 -0
- data/lib/dox/version.rb +1 -1
- metadata +90 -34
- data/lib/dox/printers/example_printer.rb +0 -100
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'rexml/document'
|
2
|
-
|
3
|
-
module Dox
|
4
|
-
module Printers
|
5
|
-
class ExamplePrinter < BasePrinter
|
6
|
-
def print(example)
|
7
|
-
self.example = example
|
8
|
-
print_example_request
|
9
|
-
print_example_response
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
attr_accessor :example
|
15
|
-
|
16
|
-
def print_example_request
|
17
|
-
@output.puts example_request_title
|
18
|
-
@output.puts example_request_headers
|
19
|
-
return unless example.request_body.present?
|
20
|
-
|
21
|
-
@output.puts example_request_body
|
22
|
-
end
|
23
|
-
|
24
|
-
def print_example_response
|
25
|
-
@output.puts example_response_title
|
26
|
-
|
27
|
-
if example.response_headers.present?
|
28
|
-
@output.puts example_response_headers
|
29
|
-
end
|
30
|
-
|
31
|
-
return unless example.response_body.present?
|
32
|
-
@output.puts example_response_body
|
33
|
-
end
|
34
|
-
|
35
|
-
def example_request_title
|
36
|
-
<<-HEREDOC
|
37
|
-
|
38
|
-
+ Request #{example.request_identifier}
|
39
|
-
**#{example.request_method.upcase}** `#{CGI.unescape(example.request_fullpath)}`
|
40
|
-
HEREDOC
|
41
|
-
end
|
42
|
-
|
43
|
-
def example_request_headers
|
44
|
-
<<-HEREDOC
|
45
|
-
|
46
|
-
+ Headers
|
47
|
-
|
48
|
-
#{indent_lines(12, print_headers(example.request_headers))}
|
49
|
-
HEREDOC
|
50
|
-
end
|
51
|
-
|
52
|
-
def example_request_body
|
53
|
-
<<-HEREDOC
|
54
|
-
|
55
|
-
+ Body
|
56
|
-
|
57
|
-
#{indent_lines(12, example.request_body)}
|
58
|
-
HEREDOC
|
59
|
-
end
|
60
|
-
|
61
|
-
def example_response_title
|
62
|
-
<<-HEREDOC
|
63
|
-
|
64
|
-
+ Response #{example.response_status}
|
65
|
-
HEREDOC
|
66
|
-
end
|
67
|
-
|
68
|
-
def example_response_headers
|
69
|
-
<<-HEREDOC
|
70
|
-
|
71
|
-
+ Headers
|
72
|
-
|
73
|
-
#{indent_lines(12, print_headers(example.response_headers))}
|
74
|
-
HEREDOC
|
75
|
-
end
|
76
|
-
|
77
|
-
def example_response_body
|
78
|
-
<<-HEREDOC
|
79
|
-
|
80
|
-
+ Body
|
81
|
-
|
82
|
-
#{indent_lines(12, example.response_body)}
|
83
|
-
HEREDOC
|
84
|
-
end
|
85
|
-
|
86
|
-
def print_headers(headers)
|
87
|
-
headers.map do |key, value|
|
88
|
-
"#{key}: #{value}"
|
89
|
-
end.join("\n")
|
90
|
-
end
|
91
|
-
|
92
|
-
def indent_lines(number_of_spaces, string)
|
93
|
-
string
|
94
|
-
.split("\n")
|
95
|
-
.map { |a| a.prepend(' ' * number_of_spaces) }
|
96
|
-
.join("\n")
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|