yard-api 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -3
- data/config/yard_api.yml +10 -1
- data/lib/yard-api/options.rb +8 -0
- data/lib/yard-api/tags/argument_tag.rb +0 -10
- data/lib/yard-api/tags.rb +0 -1
- data/lib/yard-api/templates/helpers/base_helper.rb +16 -1
- data/lib/yard-api/templates/helpers/html_helper.rb +7 -0
- data/lib/yard-api/templates/helpers/route_helper.rb +8 -0
- data/lib/yard-api/verifier.rb +5 -6
- data/lib/yard-api/version.rb +1 -1
- data/tasks/yard_api.rake +1 -0
- data/templates/api/appendix/json/setup.rb +1 -22
- data/templates/api/fulldoc/html/css/common.css +155 -102
- data/templates/api/fulldoc/html/css/highlight.css +125 -42
- data/templates/api/{layout/html/scripts.erb → fulldoc/html/js/app.js} +24 -20
- data/templates/api/fulldoc/html/js/highlight/styles/mono-blue.css +125 -42
- data/templates/api/fulldoc/html/setup.rb +1 -1
- data/templates/api/fulldoc/json/setup.rb +4 -8
- data/templates/api/layout/html/_dynamic_styles.erb +36 -11
- data/templates/api/layout/html/layout.erb +3 -2
- data/templates/api/layout/html/setup.rb +9 -2
- data/templates/api/layout/html/sidebar.erb +5 -4
- data/templates/api/layout/json/setup.rb +0 -3
- data/templates/api/method_details/html/header.erb +14 -3
- data/templates/api/method_details/html/method_signature.erb +10 -2
- data/templates/api/method_details/html/setup.rb +10 -15
- data/templates/api/tags/html/_example_code_block.erb +44 -1
- data/templates/api/tags/html/argument/_list.erb +20 -15
- data/templates/api/tags/html/argument/_table.erb +1 -1
- data/templates/api/tags/html/argument.erb +2 -2
- data/templates/api/tags/html/example_request.erb +3 -3
- data/templates/api/tags/html/example_response.erb +2 -2
- data/templates/api/topic/html/method_details_list.erb +4 -4
- data/templates/api/topic/html/topic_doc.erb +5 -5
- metadata +3 -6
- data/templates/api/docstring/json/setup.rb +0 -4
- data/templates/api/fulldoc/html/js/highlight.zip +0 -0
- data/templates/api/topic/json/setup.rb +0 -25
@@ -4,12 +4,16 @@ RouteHelper = YARD::Templates::Helpers::RouteHelper
|
|
4
4
|
|
5
5
|
def init
|
6
6
|
sections :header, [:method_signature, T('docstring')]
|
7
|
+
|
8
|
+
|
9
|
+
super
|
7
10
|
end
|
8
11
|
|
9
12
|
def header
|
10
13
|
routes = get_current_routes
|
14
|
+
route = options[:current_route] = routes.first
|
11
15
|
|
12
|
-
unless route
|
16
|
+
unless route
|
13
17
|
::YARD::APIPlugin.log(
|
14
18
|
"[error] Unable to find route for object: #{object}",
|
15
19
|
::Logger::ERROR
|
@@ -39,20 +43,11 @@ def header
|
|
39
43
|
end
|
40
44
|
|
41
45
|
@props[:routes] = routes.map do |route|
|
42
|
-
{
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
{
|
47
|
+
path: RouteHelper.get_route_path(route),
|
48
|
+
verb: RouteHelper.get_route_verb(route)
|
49
|
+
}
|
46
50
|
end
|
47
51
|
|
48
52
|
erb(:header)
|
49
|
-
end
|
50
|
-
|
51
|
-
def get_current_routes
|
52
|
-
controller_name = object.parent.path.underscore
|
53
|
-
controller_name.sub!("_controller", '') unless controller_name.include?('/')
|
54
|
-
|
55
|
-
action = object.path.sub(/^.*#/, '').sub(/_with_.*$/, '')
|
56
|
-
|
57
|
-
RouteHelper.api_methods_for_controller_and_action(controller_name, action)
|
58
|
-
end
|
53
|
+
end
|
@@ -1,8 +1,51 @@
|
|
1
1
|
<% tag = options[:tag] %>
|
2
|
+
<% multi_dialect = options[:multi_dialect] %>
|
2
3
|
<% title = tag.name %>
|
4
|
+
<%
|
5
|
+
json_blob = begin
|
6
|
+
JSON.parse(tag.text).to_json
|
7
|
+
rescue JSON::ParserError => e
|
8
|
+
puts '*' * 80
|
9
|
+
puts " Invalid JSON payload in endpoint: #{object.path.to_s}"
|
10
|
+
puts " Please make sure it is valid JSON."
|
11
|
+
puts '*' * 80
|
12
|
+
|
13
|
+
if api_options.strict then
|
14
|
+
raise e
|
15
|
+
else
|
16
|
+
return
|
17
|
+
end
|
18
|
+
end
|
19
|
+
%>
|
3
20
|
|
4
21
|
<% if title && !title.empty? %>
|
5
22
|
<header class="example-title"><%= title.strip %></header>
|
6
23
|
<% end %>
|
7
24
|
|
8
|
-
<
|
25
|
+
<div class="example-codeblocks">
|
26
|
+
<% if multi_dialect %>
|
27
|
+
<div class="example-codeblocks__tabs">
|
28
|
+
<a class="example-codeblocks__tab">JSON</a>
|
29
|
+
<a class="example-codeblocks__tab">cURL</a>
|
30
|
+
</div>
|
31
|
+
<% end %>
|
32
|
+
|
33
|
+
<pre class="example-codeblocks__example example code js"><%= html_syntax_highlight(tag.text, :plain) %></pre>
|
34
|
+
<% if multi_dialect %>
|
35
|
+
<pre class="example-codeblocks__example example code shell">
|
36
|
+
curl \
|
37
|
+
-X <%= YARD::Templates::Helpers::RouteHelper.get_route_verb(options[:current_route]) %> \
|
38
|
+
-H "Authorization: Bearer $TOKEN" \
|
39
|
+
-H 'Content-Type: application/json' \
|
40
|
+
-H 'Accept: application/json' \
|
41
|
+
-d '<%= JSON.parse(tag.text).to_json %>' \
|
42
|
+
<%=
|
43
|
+
[
|
44
|
+
"http://<#{api_options.url_title}>",
|
45
|
+
api_options.url_prefix,
|
46
|
+
YARD::Templates::Helpers::RouteHelper.get_route_path(options[:current_route])
|
47
|
+
].compact.reject(&:empty?).join('')
|
48
|
+
%>
|
49
|
+
</pre>
|
50
|
+
<% end %>
|
51
|
+
</div>
|
@@ -1,21 +1,26 @@
|
|
1
|
-
<ul class="argument">
|
1
|
+
<ul class="argument-listing">
|
2
2
|
<% @argument_tags.each do |tag| %>
|
3
|
-
<li>
|
4
|
-
<
|
5
|
-
|
6
|
-
|
7
|
-
<span class="argument-values fade">
|
8
|
-
<em>[ <%= tag.accepted_values.join(', ') %> ]</em>
|
9
|
-
</span>
|
10
|
-
<% end %>
|
3
|
+
<li class="argument-listing__argument">
|
4
|
+
<div class="argument-listing__argument-details">
|
5
|
+
<code class="argument-listing__argument-name"><%= h tag.name %></code>
|
6
|
+
<span class="argument-listing__argument-type"><%= tag.type %></span>
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
<% if (tag.accepted_values || []).any? %>
|
9
|
+
<span class="argument-listing__argument-values">
|
10
|
+
<span>[ <%= tag.accepted_values.join(', ') %> ]</span>
|
11
|
+
</span>
|
12
|
+
<% end %>
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
<% if tag.is_required %>
|
15
|
+
<span class="argument-listing__argument-required">Required</span>
|
16
|
+
<% end %>
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<div class="argument-listing__argument-text">
|
20
|
+
<% if !tag.text.empty? %>
|
21
|
+
<%= html_markup_markdown(tag.text) %>
|
22
|
+
<% end %>
|
23
|
+
</div>
|
19
24
|
</li>
|
20
25
|
<% end %>
|
21
26
|
</ul>
|
@@ -14,7 +14,7 @@
|
|
14
14
|
<tbody>
|
15
15
|
<% @argument_tags.each do |tag| %>
|
16
16
|
<tr>
|
17
|
-
<td><code class="argument-name"><%= h tag.
|
17
|
+
<td><code class="argument-name"><%= h tag.name %></code></td>
|
18
18
|
<td><span class="argument-type"><%= tag.type %></span></td>
|
19
19
|
|
20
20
|
<% if has_accepted_values %>
|
@@ -1,13 +1,13 @@
|
|
1
1
|
<% if object.has_tag?(:example_request) %>
|
2
2
|
<div class="examples">
|
3
3
|
<% if object.tags(:example_request).length > 1 %>
|
4
|
-
<h4>Example Requests
|
4
|
+
<h4>Example Requests</h4>
|
5
5
|
<% else %>
|
6
|
-
<h4>Example Request
|
6
|
+
<h4>Example Request</h4>
|
7
7
|
<% end %>
|
8
8
|
|
9
9
|
<% object.tags(:example_request).each do |tag| %>
|
10
|
-
<%= tag_partial '_example_code_block', tag %>
|
10
|
+
<%= tag_partial '_example_code_block', tag, { multi_dialect: true } %>
|
11
11
|
<% end %>
|
12
12
|
</div>
|
13
13
|
<% end %>
|
@@ -2,9 +2,9 @@
|
|
2
2
|
<% tags = object.tags(:example_response) %>
|
3
3
|
<div class="examples example_response">
|
4
4
|
<% if tags.length > 1 %>
|
5
|
-
<h4>Example Responses
|
5
|
+
<h4>Example Responses</h4>
|
6
6
|
<% else %>
|
7
|
-
<h4>Example Response
|
7
|
+
<h4>Example Response</h4>
|
8
8
|
<% end %>
|
9
9
|
|
10
10
|
<% tags.each do |tag| %>
|
@@ -1,5 +1,5 @@
|
|
1
|
-
<div
|
2
|
-
<% @meths.each_with_index do |meth, i| %>
|
3
|
-
|
4
|
-
<% end %>
|
1
|
+
<div>
|
2
|
+
<% @meths.each_with_index do |meth, i| %>
|
3
|
+
<%= yieldall :object => meth, :index => i %>
|
4
|
+
<% end %>
|
5
5
|
</div>
|
@@ -11,17 +11,17 @@
|
|
11
11
|
<% end %>
|
12
12
|
|
13
13
|
<section>
|
14
|
-
<
|
15
|
-
|
16
|
-
|
14
|
+
<h2>Interfaces</h2>
|
15
|
+
|
16
|
+
<ul id="quicklinks"></ul>
|
17
17
|
</section>
|
18
18
|
|
19
19
|
<% @json_objects.each do |name, json| %>
|
20
20
|
<% properties = render_properties(json) %>
|
21
21
|
<div class='object_definition'>
|
22
22
|
<h3>
|
23
|
-
<a name="<%= name %>"></a><%= name %> object
|
23
|
+
<a name="<%= name %>"></a><%= name %> object synopsis:
|
24
24
|
</h3>
|
25
25
|
<pre class="example code"><%= html_syntax_highlight(properties ? properties : json, :plain) %></pre>
|
26
26
|
</div>
|
27
|
-
<% end %>
|
27
|
+
<% end %>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yard-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmad Amireh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
@@ -96,10 +96,9 @@ files:
|
|
96
96
|
- templates/api/appendix/json/setup.rb
|
97
97
|
- templates/api/docstring/html/setup.rb
|
98
98
|
- templates/api/docstring/html/text.erb
|
99
|
-
- templates/api/docstring/json/setup.rb
|
100
99
|
- templates/api/fulldoc/html/css/common.css
|
101
100
|
- templates/api/fulldoc/html/css/highlight.css
|
102
|
-
- templates/api/fulldoc/html/js/
|
101
|
+
- templates/api/fulldoc/html/js/app.js
|
103
102
|
- templates/api/fulldoc/html/js/highlight/CHANGES.md
|
104
103
|
- templates/api/fulldoc/html/js/highlight/LICENSE
|
105
104
|
- templates/api/fulldoc/html/js/highlight/README.md
|
@@ -164,7 +163,6 @@ files:
|
|
164
163
|
- templates/api/layout/html/footer.erb
|
165
164
|
- templates/api/layout/html/headers.erb
|
166
165
|
- templates/api/layout/html/layout.erb
|
167
|
-
- templates/api/layout/html/scripts.erb
|
168
166
|
- templates/api/layout/html/setup.rb
|
169
167
|
- templates/api/layout/html/sidebar.erb
|
170
168
|
- templates/api/layout/json/layout.erb
|
@@ -195,7 +193,6 @@ files:
|
|
195
193
|
- templates/api/topic/html/method_details_list.erb
|
196
194
|
- templates/api/topic/html/setup.rb
|
197
195
|
- templates/api/topic/html/topic_doc.erb
|
198
|
-
- templates/api/topic/json/setup.rb
|
199
196
|
- yard-api.gemspec
|
200
197
|
homepage: https://github.com/amireh/yard-api
|
201
198
|
licenses:
|
Binary file
|
@@ -1,25 +0,0 @@
|
|
1
|
-
def init
|
2
|
-
# sections :header, [:topic_doc, :method_details_list, [T('method_details')]]
|
3
|
-
sections :method_details_list, [T('method_details')]
|
4
|
-
@resource = object
|
5
|
-
# @beta = options[:controllers].any? { |c| c.tag('beta') }
|
6
|
-
puts "Topic: HEE? #{@resource}"
|
7
|
-
end
|
8
|
-
|
9
|
-
def method_details_list
|
10
|
-
@meths = options[:controllers].map { |c| c.meths(:inherited => false, :included => false) }.flatten
|
11
|
-
@meths = run_verifier(@meths)
|
12
|
-
|
13
|
-
# puts "Methods: #{@meths}"
|
14
|
-
|
15
|
-
buffer = [];
|
16
|
-
|
17
|
-
@meths.each_with_index do |meth, i|
|
18
|
-
# puts "#{i} => #{meth.tags}"
|
19
|
-
buffer.push(yieldall :object => meth, :index => i)
|
20
|
-
end
|
21
|
-
|
22
|
-
puts "Buffer: #{buffer.to_json}"
|
23
|
-
|
24
|
-
buffer.to_json
|
25
|
-
end
|