fdoc 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +15 -0
- data/lib/fdoc.rb +2 -1
- data/lib/fdoc/cli.rb +53 -15
- data/lib/fdoc/meta_service.rb +1 -1
- data/lib/fdoc/presenters/{html_presenter.rb → base_presenter.rb} +12 -17
- data/lib/fdoc/presenters/endpoint_presenter.rb +22 -24
- data/lib/fdoc/presenters/json_presenter.rb +31 -0
- data/lib/fdoc/presenters/meta_service_presenter.rb +25 -6
- data/lib/fdoc/presenters/response_code_presenter.rb +13 -4
- data/lib/fdoc/presenters/schema_presenter.rb +36 -4
- data/lib/fdoc/presenters/service_presenter.rb +25 -6
- data/lib/fdoc/templates/endpoint.html.erb +5 -5
- data/lib/fdoc/templates/endpoint.md.erb +40 -0
- data/lib/fdoc/templates/meta_service.html.erb +3 -1
- data/lib/fdoc/templates/meta_service.md.erb +20 -0
- data/lib/fdoc/templates/service.html.erb +4 -2
- data/lib/fdoc/templates/service.md.erb +18 -0
- data/lib/fdoc/templates/shared/endpoint_name.html.erb +8 -0
- data/lib/fdoc/templates/shared/endpoint_name.md.erb +1 -0
- data/lib/fdoc/templates/styles.css +1 -1
- data/spec/fdoc/cli_spec.rb +87 -40
- data/spec/fdoc/endpoint_scaffold_spec.rb +5 -5
- data/spec/fdoc/endpoint_spec.rb +18 -18
- data/spec/fdoc/presenters/base_presenter_spec.rb +28 -0
- data/spec/fdoc/presenters/endpoint_presenter_spec.rb +8 -1
- data/spec/fdoc/presenters/meta_service_presenter_spec.rb +38 -0
- data/spec/fdoc/presenters/schema_presenter_spec.rb +34 -0
- data/spec/fdoc/presenters/service_presenter_spec.rb +24 -1
- data/spec/fixtures/members/list/complex-params-GET.fdoc +20 -20
- data/spec/spec_helper.rb +1 -0
- metadata +14 -2
@@ -1,7 +1,12 @@
|
|
1
|
-
# An
|
2
|
-
class Fdoc::ServicePresenter < Fdoc::
|
1
|
+
# An BasePresenter for Fdoc::Service
|
2
|
+
class Fdoc::ServicePresenter < Fdoc::BasePresenter
|
3
3
|
attr_reader :service
|
4
4
|
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def_delegators :service, :name, :service_dir, :meta_service
|
8
|
+
|
9
|
+
|
5
10
|
def initialize(service, options = {})
|
6
11
|
super(options)
|
7
12
|
@service = service
|
@@ -11,6 +16,10 @@ class Fdoc::ServicePresenter < Fdoc::HtmlPresenter
|
|
11
16
|
render_erb('service.html.erb')
|
12
17
|
end
|
13
18
|
|
19
|
+
def to_markdown
|
20
|
+
render_erb('service.md.erb')
|
21
|
+
end
|
22
|
+
|
14
23
|
def name_as_link(options = {})
|
15
24
|
path = service.meta_service ? index_path(slug_name) : index_path
|
16
25
|
'<a href="%s">%s %s</a>' % [ path, options[:prefix], service.name ]
|
@@ -46,11 +55,21 @@ class Fdoc::ServicePresenter < Fdoc::HtmlPresenter
|
|
46
55
|
@endpoints
|
47
56
|
end
|
48
57
|
|
49
|
-
def description
|
50
|
-
render_markdown(service.description)
|
58
|
+
def description(options = {:render => true})
|
59
|
+
options[:render] ? render_markdown(service.description) : service.description
|
51
60
|
end
|
52
61
|
|
53
|
-
def discussion
|
54
|
-
render_markdown(service.discussion)
|
62
|
+
def discussion(options = {:render => true})
|
63
|
+
options[:render] ? render_markdown(service.discussion) : service.discussion
|
55
64
|
end
|
65
|
+
|
66
|
+
def relative_meta_service_path(file_name = nil)
|
67
|
+
service_path = service_dir.gsub(meta_service.meta_service_dir, "")
|
68
|
+
service_path = service_path.count("/").times.map { "../" }.join
|
69
|
+
if file_name
|
70
|
+
service_path = File.join(service_path, file_name)
|
71
|
+
end
|
72
|
+
service_path
|
73
|
+
end
|
74
|
+
|
56
75
|
end
|
@@ -11,7 +11,7 @@
|
|
11
11
|
<div id="page">
|
12
12
|
<div id="content">
|
13
13
|
<h1>
|
14
|
-
<%=
|
14
|
+
<%= render_erb('shared/endpoint_name.html.erb', endpoint_presenter.get_binding) %>
|
15
15
|
</h1>
|
16
16
|
|
17
17
|
<div id="nav">
|
@@ -31,19 +31,19 @@
|
|
31
31
|
<%= tag_with_anchor('h2', 'Request') %>
|
32
32
|
|
33
33
|
<%= tag_with_anchor('h3', 'Example Request') %>
|
34
|
-
<%= example_request %>
|
34
|
+
<%= example_request.to_html %>
|
35
35
|
|
36
36
|
<%= tag_with_anchor('h3', 'Request Parameters') %>
|
37
|
-
<%= request_parameters %>
|
37
|
+
<%= request_parameters.to_html %>
|
38
38
|
<% end %>
|
39
39
|
|
40
40
|
<%= tag_with_anchor('h2', 'Response') %>
|
41
41
|
<% if show_response? %>
|
42
42
|
<%= tag_with_anchor('h3', 'Example Response') %>
|
43
|
-
<%= example_response %>
|
43
|
+
<%= example_response.to_html %>
|
44
44
|
|
45
45
|
<%= tag_with_anchor('h3', 'Response Parameters') %>
|
46
|
-
<%= response_parameters %>
|
46
|
+
<%= response_parameters.to_html %>
|
47
47
|
<% end %>
|
48
48
|
|
49
49
|
<%= tag_with_anchor('h3', 'Response Codes') %>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# <%= endpoint.verb -%> <%= base_path -%><%= path -%><%= "deprecated" if deprecated? -%>
|
2
|
+
|
3
|
+
<%= description %>
|
4
|
+
|
5
|
+
<% if show_request? %>
|
6
|
+
## Request
|
7
|
+
### Example Request
|
8
|
+
```
|
9
|
+
<%= example_request.to_markdown %>
|
10
|
+
```
|
11
|
+
|
12
|
+
### Example Parameters
|
13
|
+
<%= request_parameters.to_markdown %>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
## Response
|
17
|
+
<% if show_response? %>
|
18
|
+
### Example Response
|
19
|
+
```
|
20
|
+
<%= example_response.to_markdown %>
|
21
|
+
```
|
22
|
+
|
23
|
+
### Response Parameters
|
24
|
+
<%= response_parameters.to_markdown %>
|
25
|
+
<% end %>
|
26
|
+
|
27
|
+
### Response Codes
|
28
|
+
<% if !successful_response_codes.empty? %>
|
29
|
+
#### Successful Response Codes
|
30
|
+
<% successful_response_codes.each do |response_code| %>
|
31
|
+
* <%= response_code.to_markdown %>
|
32
|
+
<% end %>
|
33
|
+
<% end %>
|
34
|
+
|
35
|
+
<% if !successful_response_codes.empty? %>
|
36
|
+
#### Failure Response Codes
|
37
|
+
<% failure_response_codes.each do |response_code| %>
|
38
|
+
* <%= response_code.to_markdown %>
|
39
|
+
<% end %>
|
40
|
+
<% end %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# <%= name %>
|
2
|
+
|
3
|
+
<%= description(:render => false) %>
|
4
|
+
|
5
|
+
<% services.each do |serv| %>
|
6
|
+
* <%= "[#{serv.name}](#{relative_service_path(serv, "index.md")})" %>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
## Endpoints
|
10
|
+
<% endpoints.each do |endpoint_ary| %>
|
11
|
+
### <%= endpoint_ary.first.prefix %>
|
12
|
+
<% endpoint_ary.each do |endpoint| %>
|
13
|
+
* <%= render_erb("shared/endpoint_name.md.erb", endpoint.get_binding) %>
|
14
|
+
<% end -%>
|
15
|
+
<% end -%>
|
16
|
+
|
17
|
+
<% if discussion %>
|
18
|
+
## Discussion
|
19
|
+
<%= discussion(:render => false) %>
|
20
|
+
<% end %>
|
@@ -31,8 +31,10 @@
|
|
31
31
|
<ul>
|
32
32
|
<% endpoint_ary.each do |endpoint| %>
|
33
33
|
<li>
|
34
|
-
<%= endpoint.
|
35
|
-
|
34
|
+
<a href="<%= endpoint.url %>">
|
35
|
+
<%= render_erb("shared/endpoint_name.html.erb", endpoint.get_binding) %>
|
36
|
+
</a>
|
37
|
+
</li>
|
36
38
|
<% end %>
|
37
39
|
</ul>
|
38
40
|
<% end %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# <%= name %>
|
2
|
+
<% if meta_service %>
|
3
|
+
### » <%= "[#{meta_service.name}](#{relative_meta_service_path("index.md")})" %>
|
4
|
+
<% end %>
|
5
|
+
|
6
|
+
<%= description(:render => false) %>
|
7
|
+
|
8
|
+
<% endpoints.each do |endpoint_ary| %>
|
9
|
+
### <%= endpoint_ary.first.prefix %>
|
10
|
+
<% endpoint_ary.each do |endpoint| %>
|
11
|
+
* <%= render_erb("shared/endpoint_name.md.erb", endpoint.get_binding) %>
|
12
|
+
<% end %>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<% if discussion %>
|
16
|
+
## Discussion
|
17
|
+
<%= discussion(:render => false) %>
|
18
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= endpoint.verb -%> [<%= base_path -%><%= path -%><%= "deprecated" if deprecated? -%>](<%= url('.md') %>)
|
data/spec/fdoc/cli_spec.rb
CHANGED
@@ -5,9 +5,10 @@ describe Fdoc::Cli do
|
|
5
5
|
let(:temporary_path) { Dir.mktmpdir("fdoc-cli") }
|
6
6
|
let(:fdoc_path) { File.expand_path("fdoc", temporary_path) }
|
7
7
|
let(:html_path) { File.expand_path("html", temporary_path) }
|
8
|
-
let(:
|
8
|
+
let(:markdown_path) { File.expand_path("markdown", temporary_path) }
|
9
|
+
let(:options) { { :format => 'html' } }
|
9
10
|
|
10
|
-
subject
|
11
|
+
subject { Fdoc::Cli.new([fdoc_path], options) }
|
11
12
|
|
12
13
|
before { FileUtils.mkdir_p(fdoc_path) }
|
13
14
|
|
@@ -28,7 +29,7 @@ describe Fdoc::Cli do
|
|
28
29
|
|
29
30
|
it "raises an exception" do
|
30
31
|
expect do
|
31
|
-
|
32
|
+
subject.convert(fdoc_path)
|
32
33
|
end.to raise_exception(Fdoc::NotFound)
|
33
34
|
end
|
34
35
|
end
|
@@ -37,7 +38,7 @@ describe Fdoc::Cli do
|
|
37
38
|
context "when the destination does not exist" do
|
38
39
|
it "makes a destination directory" do
|
39
40
|
expect do
|
40
|
-
|
41
|
+
subject.convert(fdoc_path)
|
41
42
|
end.to change { File.directory?(html_path) }.to(true)
|
42
43
|
end
|
43
44
|
end
|
@@ -47,70 +48,58 @@ describe Fdoc::Cli do
|
|
47
48
|
|
48
49
|
it "raises an exception" do
|
49
50
|
expect do
|
50
|
-
|
51
|
+
subject.convert(fdoc_path)
|
51
52
|
end.to raise_exception(Fdoc::NotADirectory)
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
55
56
|
it "copies the css to the destination" do
|
56
57
|
expect do
|
57
|
-
|
58
|
+
subject.convert(fdoc_path)
|
58
59
|
end.to change { File.exist?(styles_css_path) }.from(false)
|
59
60
|
end
|
60
61
|
|
61
|
-
|
62
|
-
let(:root_html) { File.expand_path("index.html", html_path) }
|
63
|
-
let(:members_html) do
|
64
|
-
File.expand_path("members_api/index.html", html_path)
|
65
|
-
end
|
66
|
-
let(:endpoint_html) do
|
67
|
-
File.expand_path("members_api/add-PUT.html", html_path)
|
68
|
-
end
|
69
|
-
|
62
|
+
shared_examples "when there is a meta service fdoc" do
|
70
63
|
before { with_fixture("sample_group.fdoc.meta") }
|
71
64
|
|
72
65
|
context "when no service fdoc exists" do
|
73
|
-
specify { expect {
|
66
|
+
specify { expect { subject.convert(fdoc_path) }.to raise_error }
|
74
67
|
end
|
75
68
|
|
76
69
|
context "when a service fdoc exists" do
|
77
70
|
before { with_fixture("members/members.fdoc.service") }
|
78
71
|
|
79
|
-
it "creates a root-level
|
72
|
+
it "creates a root-level file" do
|
80
73
|
expect do
|
81
|
-
|
82
|
-
end.to change { File.exist?(
|
74
|
+
subject.convert(fdoc_path)
|
75
|
+
end.to change { File.exist?(root_file) }.from(false)
|
83
76
|
end
|
84
77
|
|
85
|
-
it "writes the service-level
|
78
|
+
it "writes the service-level file" do
|
86
79
|
expect do
|
87
|
-
|
88
|
-
end.to change { File.exist?(
|
80
|
+
subject.convert(fdoc_path)
|
81
|
+
end.to change { File.exist?(members_file) }.from(false)
|
89
82
|
end
|
90
83
|
|
91
84
|
context "when an endpoint fdoc exists" do
|
92
85
|
before { with_fixture("members/add-PUT.fdoc") }
|
93
86
|
|
94
|
-
it "writes the endpoint
|
87
|
+
it "writes the endpoint file" do
|
95
88
|
expect do
|
96
|
-
|
97
|
-
end.to change { File.exist?(
|
89
|
+
subject.convert(fdoc_path)
|
90
|
+
end.to change { File.exist?(endpoint_file) }.from(false)
|
98
91
|
end
|
99
92
|
end
|
100
93
|
end
|
101
94
|
end
|
102
95
|
|
103
|
-
|
104
|
-
let(:root_html) { File.expand_path("index.html", html_path) }
|
105
|
-
let(:endpoint_html) do
|
106
|
-
File.expand_path("add-PUT.html", html_path)
|
107
|
-
end
|
96
|
+
shared_examples "when there is no meta service fdoc" do
|
108
97
|
|
109
98
|
context "when no service fdoc exists" do
|
110
99
|
it "creates a dummy index" do
|
111
100
|
expect do
|
112
|
-
|
113
|
-
end.to change { File.exist?(
|
101
|
+
subject.convert(fdoc_path)
|
102
|
+
end.to change { File.exist?(root_file) }.from(false)
|
114
103
|
end
|
115
104
|
end
|
116
105
|
|
@@ -121,8 +110,8 @@ describe Fdoc::Cli do
|
|
121
110
|
|
122
111
|
it "writes the service-level html file" do
|
123
112
|
expect do
|
124
|
-
|
125
|
-
end.to change { File.exist?(
|
113
|
+
subject.convert(fdoc_path)
|
114
|
+
end.to change { File.exist?(root_file) }.from(false)
|
126
115
|
end
|
127
116
|
|
128
117
|
context "when an endpoint fdoc exists" do
|
@@ -130,12 +119,61 @@ describe Fdoc::Cli do
|
|
130
119
|
|
131
120
|
it "writes the endpoint html file" do
|
132
121
|
expect do
|
133
|
-
|
134
|
-
end.to change { File.exist?(
|
122
|
+
subject.convert(fdoc_path)
|
123
|
+
end.to change { File.exist?(endpoint_file) }.from(false)
|
135
124
|
end
|
136
125
|
end
|
137
126
|
end
|
138
127
|
end
|
128
|
+
|
129
|
+
context "output HTML" do
|
130
|
+
|
131
|
+
context "when there is no meta service fdoc" do
|
132
|
+
let(:root_file) { File.expand_path("index.html", html_path) }
|
133
|
+
let(:members_file) do
|
134
|
+
File.expand_path("members_api/index.html", html_path)
|
135
|
+
end
|
136
|
+
let(:endpoint_file) do
|
137
|
+
File.expand_path("members_api/add-PUT.html", html_path)
|
138
|
+
end
|
139
|
+
|
140
|
+
it_behaves_like "when there is a meta service fdoc"
|
141
|
+
end
|
142
|
+
|
143
|
+
context "when there is no meta service fdoc" do
|
144
|
+
let(:root_file) { File.expand_path("index.html", html_path) }
|
145
|
+
let(:endpoint_file) do
|
146
|
+
File.expand_path("add-PUT.html", html_path)
|
147
|
+
end
|
148
|
+
it_behaves_like "when there is no meta service fdoc"
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
context "output Markdown" do
|
154
|
+
let(:options) { { :format => 'markdown' } }
|
155
|
+
|
156
|
+
context "when there is no meta service fdoc" do
|
157
|
+
let(:root_file) { File.expand_path("index.md", markdown_path) }
|
158
|
+
let(:members_file) do
|
159
|
+
File.expand_path("members_api/index.md", markdown_path)
|
160
|
+
end
|
161
|
+
let(:endpoint_file) do
|
162
|
+
File.expand_path("members_api/add-PUT.md", markdown_path)
|
163
|
+
end
|
164
|
+
|
165
|
+
it_behaves_like "when there is a meta service fdoc"
|
166
|
+
end
|
167
|
+
|
168
|
+
context "when there is no meta service fdoc" do
|
169
|
+
let(:root_file) { File.expand_path("index.md", markdown_path) }
|
170
|
+
let(:endpoint_file) do
|
171
|
+
File.expand_path("add-PUT.md", markdown_path)
|
172
|
+
end
|
173
|
+
it_behaves_like "when there is no meta service fdoc"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
139
177
|
end
|
140
178
|
end
|
141
179
|
|
@@ -203,12 +241,21 @@ describe Fdoc::Cli do
|
|
203
241
|
|
204
242
|
describe "#html_options" do
|
205
243
|
let(:html_path) { "/a/great/place/to/keep/html"}
|
244
|
+
let(:template_path) { '/a/great/place/to/keep/templates' }
|
206
245
|
|
207
|
-
before
|
246
|
+
before do
|
247
|
+
subject.origin_path = fdoc_path
|
248
|
+
subject.destination_root = html_path
|
249
|
+
end
|
208
250
|
|
209
251
|
its(:html_options) { should include(:static_html => true) }
|
210
252
|
its(:html_options) { should include(:html_directory => html_path) }
|
211
253
|
|
254
|
+
context "when a template_directory is provided" do
|
255
|
+
let(:options) { { :format => 'html', :templates => template_path } }
|
256
|
+
its(:html_options) { should include(:template_directory => template_path) }
|
257
|
+
end
|
258
|
+
|
212
259
|
context "when url_base_path is not provided" do
|
213
260
|
its(:html_options) { should include(:url_base_path => nil) }
|
214
261
|
end
|
@@ -222,7 +269,7 @@ describe Fdoc::Cli do
|
|
222
269
|
end
|
223
270
|
|
224
271
|
describe "#inside_service" do
|
225
|
-
let(:presenter) {
|
272
|
+
let(:presenter) { subject.service_presenters.first }
|
226
273
|
|
227
274
|
before do
|
228
275
|
subject.origin_path = fdoc_path
|
@@ -236,7 +283,7 @@ describe Fdoc::Cli do
|
|
236
283
|
end
|
237
284
|
|
238
285
|
it "leaves the output directory" do
|
239
|
-
|
286
|
+
subject.inside_service_presenter(presenter) do
|
240
287
|
Dir.pwd.should =~ %r|#{html_path}/members_api$|
|
241
288
|
end
|
242
289
|
end
|
@@ -248,7 +295,7 @@ describe Fdoc::Cli do
|
|
248
295
|
end
|
249
296
|
|
250
297
|
it "does not leave the output directory" do
|
251
|
-
|
298
|
+
subject.inside_service_presenter(presenter) do
|
252
299
|
Dir.pwd.should =~ /#{html_path}$/
|
253
300
|
end
|
254
301
|
end
|