yard-api 0.2.2 → 0.2.3

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -3
  3. data/config/yard_api.yml +10 -1
  4. data/lib/yard-api/options.rb +8 -0
  5. data/lib/yard-api/tags/argument_tag.rb +0 -10
  6. data/lib/yard-api/tags.rb +0 -1
  7. data/lib/yard-api/templates/helpers/base_helper.rb +16 -1
  8. data/lib/yard-api/templates/helpers/html_helper.rb +7 -0
  9. data/lib/yard-api/templates/helpers/route_helper.rb +8 -0
  10. data/lib/yard-api/verifier.rb +5 -6
  11. data/lib/yard-api/version.rb +1 -1
  12. data/tasks/yard_api.rake +1 -0
  13. data/templates/api/appendix/json/setup.rb +1 -22
  14. data/templates/api/fulldoc/html/css/common.css +155 -102
  15. data/templates/api/fulldoc/html/css/highlight.css +125 -42
  16. data/templates/api/{layout/html/scripts.erb → fulldoc/html/js/app.js} +24 -20
  17. data/templates/api/fulldoc/html/js/highlight/styles/mono-blue.css +125 -42
  18. data/templates/api/fulldoc/html/setup.rb +1 -1
  19. data/templates/api/fulldoc/json/setup.rb +4 -8
  20. data/templates/api/layout/html/_dynamic_styles.erb +36 -11
  21. data/templates/api/layout/html/layout.erb +3 -2
  22. data/templates/api/layout/html/setup.rb +9 -2
  23. data/templates/api/layout/html/sidebar.erb +5 -4
  24. data/templates/api/layout/json/setup.rb +0 -3
  25. data/templates/api/method_details/html/header.erb +14 -3
  26. data/templates/api/method_details/html/method_signature.erb +10 -2
  27. data/templates/api/method_details/html/setup.rb +10 -15
  28. data/templates/api/tags/html/_example_code_block.erb +44 -1
  29. data/templates/api/tags/html/argument/_list.erb +20 -15
  30. data/templates/api/tags/html/argument/_table.erb +1 -1
  31. data/templates/api/tags/html/argument.erb +2 -2
  32. data/templates/api/tags/html/example_request.erb +3 -3
  33. data/templates/api/tags/html/example_response.erb +2 -2
  34. data/templates/api/topic/html/method_details_list.erb +4 -4
  35. data/templates/api/topic/html/topic_doc.erb +5 -5
  36. metadata +3 -6
  37. data/templates/api/docstring/json/setup.rb +0 -4
  38. data/templates/api/fulldoc/html/js/highlight.zip +0 -0
  39. data/templates/api/topic/json/setup.rb +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ebf62e002470fba445a8cb1b434bd41cdebc2e6
4
- data.tar.gz: 0170bf9ab9cb17ba47c9e6f9ecd08a1c0ce4ab8e
3
+ metadata.gz: ab2e2a361011adda668edbcad1b71ba857fe61ab
4
+ data.tar.gz: c3ed5abc5b2de588e9722179e97acbc4c044986a
5
5
  SHA512:
6
- metadata.gz: 436c1737925db7af1753f0a77045baf474e26162b24187a396a339a74a71b9f5767cc0e73920c6e052b1b6fae7b0c3490e4719b164437b289f2e571805c43349
7
- data.tar.gz: cff13bc7797c6870aec42885f5956c3078968c1ec39ea2cd4f9ec6470596cc4173fdb32f92d8aeddfdcd3a56603fe9bf434af29653f04074efb70fc9e0afbb04
6
+ metadata.gz: d81dc23669668ed42dfc44e15c317b6199ab4be26cecfbc690abc0ab58b1209c0b15a984dd302ca7f0de8c00153f4e102ee0c060a354241724fc054c7b270957
7
+ data.tar.gz: 936a31ac15cecde12085d147565e92f51edef9251370ef33d9488ba9aa25d82473d64f48ca756a1235a3e6dbbd3d3f56abcd03ce27079379164e689eaafda338
data/README.md CHANGED
@@ -2,11 +2,9 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/amireh/yard-api.png)](https://travis-ci.org/amireh/yard-api)
4
4
 
5
- TODO
6
-
7
5
  ## Usage
8
6
 
9
- TODO
7
+ See [https://amireh.github.io/yard-api].
10
8
 
11
9
  ### Compatibility options
12
10
 
@@ -34,8 +32,23 @@ Read that file to view all the available options.
34
32
 
35
33
  - can only document classes and class methods; modules, root objects, and constants are ignored
36
34
 
35
+ ## Generating the docs for YARD-API
36
+
37
+ 1. go to the `gh-pages` branch, check it out if you haven't
38
+ 2. run `bin/generate-docs`
39
+ 3. browse `index.html`
40
+
37
41
  ## Changelog
38
42
 
43
+ **28/7/2015 [0.2.3]**
44
+
45
+ - dropped the `@argument_scope` tag
46
+ - JSON is available as an output format now
47
+ - added usage documentation, found at [http://amireh.github.io/yard-api]
48
+ - added an example app
49
+ - various style improvements
50
+ - `@example_request` is now able to output a sample cURL command.
51
+
39
52
  **0.1.7**
40
53
 
41
54
  - new compatibility option `leading_argument_name_fix`
data/config/yard_api.yml CHANGED
@@ -7,6 +7,9 @@ readme: doc/api/README.md
7
7
  # as in the layout as the primary heading.
8
8
  title: Rails API Project
9
9
 
10
+ url_title: my_app
11
+ url_prefix: /api
12
+
10
13
  # The resource index is a mega-index page that contains all the API resources.
11
14
  resource_index: true
12
15
 
@@ -100,4 +103,10 @@ spacer: 20
100
103
  # @argument [Type specifier] name_specifier
101
104
  #
102
105
  # But that may not be viable in very large, existing projects.
103
- leading_argument_name_fix: false
106
+ leading_argument_name_fix: false
107
+
108
+ use_beta_flag: true
109
+ use_beta_banner: false
110
+
111
+ show_footer: true
112
+ readme_page_title: Home
@@ -5,6 +5,8 @@ module YARD::APIPlugin
5
5
  default_attr :no_save, false
6
6
 
7
7
  default_attr :title, 'Rails API Project'
8
+ default_attr :url_title, 'my_app'
9
+ default_attr :url_prefix, '/api'
8
10
  default_attr :window_title, 'Rails API Project Documentation'
9
11
  default_attr :version, ''
10
12
  default_attr :static, []
@@ -31,6 +33,12 @@ module YARD::APIPlugin
31
33
 
32
34
  default_attr :leading_argument_name_fix, false
33
35
 
36
+ default_attr :use_beta_flag, true
37
+ default_attr :use_beta_banner, false
38
+
39
+ default_attr :show_footer, true
40
+ default_attr :readme_page_title, 'Home'
41
+
34
42
  attr_accessor :readme
35
43
  end
36
44
  end
@@ -47,16 +47,6 @@ module YARD::APIPlugin::Tags
47
47
  end
48
48
  end
49
49
 
50
- def unscoped_name
51
- scope_tag = @object.tag(:argument_scope)
52
-
53
- if scope_tag && @name =~ /^#{scope_tag.text.gsub(/\[\]/, '')}\[([^\]]+)\]$/
54
- $1
55
- else
56
- @name
57
- end
58
- end
59
-
60
50
  private
61
51
 
62
52
  def parse_is_required(types=[])
data/lib/yard-api/tags.rb CHANGED
@@ -2,7 +2,6 @@ require 'yard-api/tags/argument_tag'
2
2
 
3
3
  YARD::Tags::Library.define_tag("API endpoint", :API)
4
4
  YARD::Tags::Library.define_tag("API endpoint argument", :argument, YARD::APIPlugin::Tags::ArgumentTag)
5
- YARD::Tags::Library.define_tag("API endpoint argument scope", :argument_scope)
6
5
  YARD::Tags::Library.define_tag("API response field", :request_field)
7
6
  YARD::Tags::Library.define_tag("API response field", :response_field)
8
7
  YARD::Tags::Library.define_tag("API example request", :example_request, :with_title_and_text)
@@ -100,10 +100,25 @@ module YARD::Templates::Helpers::BaseHelper
100
100
  appendix
101
101
  end
102
102
 
103
- def tag_partial(name, tag)
103
+ def tag_partial(name, tag, locals={})
104
104
  options[:tag] = tag
105
+ locals.each_pair { |key, value| options[key] = value }
105
106
  out = erb(name)
106
107
  options.delete(:tag)
108
+ locals.keys.each { |key| options.delete(key.to_sym) }
107
109
  out
108
110
  end
111
+
112
+ def get_current_routes
113
+ controller_name = object.parent.path.underscore
114
+ controller_name.sub!("_controller", '') unless controller_name.include?('/')
115
+
116
+ action = object.path.sub(/^.*#/, '').sub(/_with_.*$/, '')
117
+
118
+ YARD::Templates::Helpers::RouteHelper.api_methods_for_controller_and_action(controller_name, action)
119
+ end
120
+
121
+ def get_current_route
122
+ get_current_routes.first
123
+ end
109
124
  end
@@ -98,7 +98,14 @@ module YARD::Templates::Helpers::HtmlHelper
98
98
  end
99
99
  end
100
100
 
101
+ # TODO: this has to work with the All Resources page.
101
102
  def sidebar_link(title, href, options={})
103
+ options[:class_name] ||= begin
104
+ if object.is_a?(String) && "#{url_for(topicize(object))}.html" == href
105
+ options[:class_name] = 'active'
106
+ end
107
+ end
108
+
102
109
  options[:class_name] ||= (object == href ? 'active' : nil)
103
110
 
104
111
  <<-HTML
@@ -15,5 +15,13 @@ module YARD::Templates::Helpers
15
15
  controller_path.gsub!(/^\/|_controller$/, '')
16
16
  @routes.find_all { |r| matches_controller_and_action?(r, controller_path, action) }
17
17
  end
18
+
19
+ def self.get_route_path(route)
20
+ route.path.spec.to_s.gsub("(.:format)", "")
21
+ end
22
+
23
+ def self.get_route_verb(route)
24
+ route.verb.source =~ /\^?(\w*)\$/ ? $1.upcase : route.verb.source
25
+ end
18
26
  end
19
27
  end
@@ -25,14 +25,13 @@ module YARD
25
25
  when :root, :module, :constant
26
26
  false
27
27
  when :method, :class
28
- is_api = !object.tags('API').empty?
29
- is_internal = !object.tags('internal').empty?
28
+ return false if object.tags('internal').any?
30
29
 
31
- if @verbose && !is_api && !is_internal
32
- log "Resource #{object} will be ignored as it contains no @API tag."
30
+ object.tags('API').any?.tap do |is_api|
31
+ if @verbose && !is_api
32
+ log "Resource #{object} will be ignored as it contains no @API tag."
33
+ end
33
34
  end
34
-
35
- is_api && !is_internal
36
35
  else
37
36
  object.parent.nil? && relevant_object?(object.parent)
38
37
  end
@@ -1,5 +1,5 @@
1
1
  module YARD
2
2
  module APIPlugin
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
data/tasks/yard_api.rake CHANGED
@@ -6,6 +6,7 @@ runner = YARD::APIPlugin::YardocTask.new
6
6
  desc 'generate YARD API docs'
7
7
  task :yard_api => :environment do |t|
8
8
  output = runner.config['output']
9
+ # TODO: make this compatible with json output format
9
10
  puts <<-Message
10
11
  API Documentation successfully generated in #{output}
11
12
  See #{output}/index.html
@@ -1,25 +1,4 @@
1
- # include T('default/appendix/html')
2
-
1
+ # TODO
3
2
  def init
4
3
  super
5
4
  end
6
-
7
- def appendix
8
- controllers = options[:controllers]
9
-
10
- if options[:all_resources]
11
- controllers = options[:resources].flatten.select { |o|
12
- o.is_a?(YARD::CodeObjects::NamespaceObject)
13
- }
14
- end
15
-
16
- unless controllers && controllers.is_a?(Array)
17
- return
18
- end
19
-
20
- @appendixes = controllers.collect do |controller|
21
- controller.children.select { |tag| :appendix == tag.type }
22
- end.flatten.uniq
23
-
24
- super
25
- end
@@ -2,33 +2,27 @@ body {
2
2
  font-family: "Open Sans", Calibri, Candara, "Helvetica Neue", Arial, sans-serif;
3
3
  font-size: 15px;
4
4
  line-height: 1.4;
5
- margin: 0;
5
+ margin: 1em;
6
6
  padding: 0;
7
7
  color: #333;
8
8
  }
9
9
 
10
- a, #sidebar a:visited {
10
+ a {
11
11
  color: #4183c4;
12
12
  }
13
- a:visited {
14
- color: #8B3377;
13
+
14
+ a:hover, a:focus {
15
+ text-decoration: none;
15
16
  }
16
- a:hover,
17
- a:focus,
18
- #sidebar a.current,
19
- #sidebar a:hover,
20
- #sidebar a:focus {
21
- color: #99173C;
17
+
18
+ a.active {
19
+ font-weight: bold;
22
20
  }
23
21
 
24
22
  #content {
25
23
  margin: 0 auto;
26
24
  }
27
25
 
28
- p, h4 {
29
- margin: 0.8em 0;
30
- }
31
-
32
26
  code {
33
27
  margin: 0 2px;
34
28
  padding: 0px 5px;
@@ -42,93 +36,83 @@ code {
42
36
  h1 {
43
37
  font-size: 1.6em;
44
38
  padding: 0.6em 0;
45
- margin: 10px 0;
46
- }
47
- #content h1 {
48
- border-bottom: 1px solid #ddd;
39
+ margin: 0.6em 0;
49
40
  }
50
41
 
51
42
  h2 {
52
- border-bottom: 1px #ddd solid;
53
- padding: 0 0 3px;
54
43
  font-size: 1.4em;
55
- margin-top: 30px;
44
+ padding: 0.6em 0;
45
+ margin: 0.6em 0;
56
46
  }
57
- h3.beta {
58
- border: 1px solid black;
59
- background-color: #E5E8FF;
60
- text-align: center;
61
- padding: 6px;
62
- font-weight: bold;
47
+
48
+ .endpoint__beta-banner {
49
+ border-left: 5px solid rgba(255,0,0,0.65);
50
+ background-color: #ffc;
51
+ padding: 0.6em;
52
+ font-size: 85%;
53
+ }
54
+
55
+ .method-details__beta-flag {
56
+ color: #CC0000;
57
+ background: #fca;
58
+ padding: 0.5em 0.6em;
59
+ font-size: 85%;
63
60
  }
61
+
64
62
  #sidebar {
65
63
  position: fixed;
66
64
  overflow: auto;
67
65
  bottom: 0;
68
66
  top: 0;
69
- left: 0;
70
- background: #f8f8f8;
71
- border-right: 1px solid #ddd;
67
+ left: 1em;
72
68
  }
69
+
73
70
  #sidebar h1 {
74
71
  margin-bottom: 0;
75
- margin-left: 20px;
76
72
  border-bottom: 1px solid #ddd;
77
73
  }
78
- #sidebar a,
79
- #sidebar h2 {
80
- display:block;
81
- border: none;
82
- font-size: 1.1em;
83
- }
84
- #sidebar h2 {
85
- padding: 10px 0;
86
- font-size: 20px;
87
- font-weight: normal;
88
- text-transform: uppercase;
89
- text-shadow: 0 1px 0 white;
90
- margin: 0;
91
- }
92
- #sidebar h2.first {
93
- border-top:none;
94
- }
95
- #sidebar h2,
96
- #sidebar a {
97
- border-right: 5px solid transparent;
98
- }
74
+
99
75
  #sidebar a {
100
- padding: 5px 0;
76
+ display: block;
77
+ color: inherit;
78
+ padding: 0.35em 0;
101
79
  text-decoration: none;
102
- font-size: 13px;
103
- font-weight: bold;
104
80
  }
105
81
 
106
- #content a[name^="method."] {
107
- outline: none;
82
+ #sidebar a:hover {
83
+ text-decoration: underline;
108
84
  }
109
- .method_details_list h2 {
85
+
86
+ #sidebar a.active {
87
+ color: #4183c4;
110
88
  }
111
89
 
90
+ .sidebar__heading {
91
+ color: #939da3;
92
+ text-transform: uppercase;
93
+ font-size: 1em;
94
+ margin-bottom: 0.5em;
95
+ padding-bottom: 0;
96
+ margin-top: 1em;
97
+ }
112
98
 
113
- .method_details h3.endpoint {
114
- font-size: 14px;
99
+ .endpoint__path {
100
+ font-size: 90%;
115
101
  font-weight: normal;
116
102
  font-family: Monaco, Consolas, Courier, monospace;
117
- padding: 6px 10px;
118
- margin-top: 18px;
119
- background: #f8f8f8;
120
- border: 1px solid #ddd;
121
- border-radius: 2px;
103
+ padding: 1em;
104
+ margin-top: 1em;
105
+ background: #ffc;
122
106
  }
123
107
 
124
- .method_details .verb {
108
+ .method-details .verb {
125
109
  font-weight: bold;
126
110
  }
127
- .method_details .id-fragment {
111
+ .method-details .id-fragment {
128
112
  color: #CC0000;
129
113
  }
130
114
 
131
- h2 .defined-in {
115
+ .method-details__defined-in {
132
116
  float:right;
133
117
  font-size:10px;
134
118
  padding-top:10px;
@@ -137,32 +121,27 @@ h2 .defined-in {
137
121
 
138
122
  /* Footer */
139
123
  #footer {
140
- margin-top: 20px;
141
- margin-left: 180px;
142
- border-top: 1px solid #ddd;
124
+ margin: 1em 0;
125
+ border-top: 1px solid #ccc;
143
126
  text-align: center;
144
- color: #999;
127
+ color: #666;
128
+ font-size: 85%;
145
129
  }
146
130
 
147
131
  #footer a {
148
- color: #999;
132
+ color: #666;
149
133
  }
150
134
 
151
- pre.code,
152
- div.syntaxhighlighter {
153
- background-color: #f8f8f8;
154
- border: 1px solid #ddd;
155
- font-size: 13px;
156
- line-height: 19px;
157
- overflow: auto;
158
- padding: 6px 10px;
159
- border-radius: 3px;
135
+ /* highlight.js overrides */
136
+ pre.code, div.syntaxhighlighter {
160
137
  font-family: Monaco, Consolas, Courier, monospace;
138
+ background-color: #ffd;
139
+ font-size: 85%;
140
+ overflow: auto;
141
+ padding: 0.5em 1em;
161
142
  }
162
143
 
163
- .syntaxhighlighter .line code,
164
- pre.code code,
165
- .endpoint-errors code {
144
+ .syntaxhighlighter .line code, pre.code code, .endpoint-errors code {
166
145
  white-space: nowrap;
167
146
  background: none;
168
147
  border: none;
@@ -171,6 +150,7 @@ pre.code code,
171
150
  padding: 0;
172
151
  border-radius: 0;
173
152
  }
153
+
174
154
  .syntaxhighlighter {
175
155
  overflow: auto;
176
156
  }
@@ -191,26 +171,15 @@ table#quicklinks th {
191
171
  padding: 12px;
192
172
  }
193
173
 
194
- h2.api_method_name a {
174
+ a.method-details__name-link {
195
175
  text-decoration: none;
196
- color: black;
176
+ color: inherit;
197
177
  }
198
178
 
199
179
  div.appendix img {
200
180
  max-width: 100%;
201
181
  }
202
182
 
203
- .argument-required {
204
- font-style: normal;
205
- color: #CC0000;
206
- }
207
-
208
- li .argument-required {
209
- font-size: 12px;
210
- padding: 2px 4px;
211
- font-weight: bold;
212
- }
213
-
214
183
  .example-title {
215
184
  padding: 5px 0;
216
185
  font-size: 11px;
@@ -218,10 +187,6 @@ li .argument-required {
218
187
  color: #777;
219
188
  }
220
189
 
221
- .fade {
222
- color: #777;
223
- }
224
-
225
190
  blockquote {
226
191
  border-left: 4px solid #DDD;
227
192
  padding: 0 15px;
@@ -279,3 +244,91 @@ hr {
279
244
 
280
245
  .emits-tag {
281
246
  }
247
+
248
+ /* --------------------------------------------------------------------------
249
+ * ARGUMENTS
250
+ * -------------------------------------------------------------------------- */
251
+ h4 {
252
+ margin: 2em 0;
253
+ padding: 1em 0;
254
+ border-bottom: 1px solid #ccc;
255
+ color: #666;
256
+ }
257
+
258
+ .argument-listing {
259
+ list-style: none;
260
+ margin: 0;
261
+ padding: 0;
262
+ }
263
+
264
+ .argument-listing__argument {
265
+ padding: 0;
266
+ margin: 2em 0;
267
+ display: block;
268
+ min-height: 4em;
269
+ }
270
+
271
+ .argument-listing__argument-details {
272
+ /*display: inline-block;*/
273
+ width: 40%;
274
+ max-width: 260px;
275
+ text-align: right;
276
+ vertical-align: top;
277
+ float: left;
278
+ }
279
+
280
+ .argument-listing__argument-name,
281
+ .argument-listing__argument-type,
282
+ .argument-listing__argument-values,
283
+ .argument-listing__argument-required {
284
+ display: block;
285
+ }
286
+
287
+ code.argument-listing__argument-name {
288
+ border: none;
289
+ padding: 0;
290
+ margin: 0;
291
+ overflow: auto;
292
+ }
293
+
294
+ /* fade these out to give more emphasis to the name */
295
+ .argument-listing__argument-type,
296
+ .argument-listing__argument-values,
297
+ .argument-listing__argument-required {
298
+ font-size: 85%;
299
+ color: #777;
300
+ }
301
+
302
+ .argument-listing__argument-required {
303
+ font-style: normal;
304
+ color: #CC0000;
305
+ font-weight: bold;
306
+ opacity: 0.6;
307
+ }
308
+
309
+ .argument-listing__argument-text {
310
+ vertical-align: top;
311
+ margin-left: 1em;
312
+ margin-left: 260px;
313
+ padding-left: 1em;
314
+ }
315
+
316
+ .argument-listing__argument-text > p {
317
+ margin-top: 0;
318
+ }
319
+
320
+ .example-codeblocks__tabs {
321
+ margin-bottom: -0.5em; /* negate the margin of the example block */
322
+ background: #ffc;
323
+ padding: 0.5em 1em;
324
+ font-size: 85%;
325
+ }
326
+
327
+ .example-codeblocks__tab {
328
+ margin-right: 0.5em;
329
+ cursor: pointer;
330
+ }
331
+
332
+ .example-codeblocks__tabs a.active {
333
+ font-weight: bold;
334
+ }