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.
@@ -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}**&nbsp;&nbsp;`#{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