yard-api 0.3.7 → 1.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3af67e45e3ab8fd41ef0ec5cb1578e1978361579796e4d2720f9a09907ded38
4
- data.tar.gz: 488360b56b9a807e8e6a8671b3aeae13b83f3400d01cf6f826b0cbdf9881337b
3
+ metadata.gz: a0208f3a8c85cce1ea72f163295779b101976a8b35cdef210e23dc6b3997577b
4
+ data.tar.gz: cb55240abab2888e59c9929a56cf9c29f1cd70cbe038d4ec13f616a61e3b9b63
5
5
  SHA512:
6
- metadata.gz: b1dfd66a16c6e4a1d76a121b2fc74ab9cd813e1336bb51ef36b6c54d9baea7e39fff89cb125759f784cb18d629259d340e655010a32f4709b85e43f92529f936
7
- data.tar.gz: 85b89092da99271aad2c5b09b77ee32d5b1b93e25493ed16682263bed6cd3175c24c8ff21a4d3507fad9e3a5414b09079bae5c4bb095c3db4c0675a5a27bffdb
6
+ metadata.gz: 2aa7523f95c559e211d4c5bb812d1314c18f22b6712bb706df9cde72b8cb53eb5d3a8d00f626708cef43e283f5e2fc9dc0838055a9420f8843a8d064f4c74cc7
7
+ data.tar.gz: d9d12b708e52097531be4ba50ed4f5e8ab65b6eb4362f07b81a1da0253f4d6324d76114978efbaa4d9c0b425b6226709c156fdcbf74edbfc68eaa5227ee2e55e
data/README.md CHANGED
@@ -40,65 +40,7 @@ Read that file to view all the available options.
40
40
 
41
41
  ## Changelog
42
42
 
43
- **6/9/2015 [0.3.5]**
44
-
45
- - In JSON format, an API resource endpoint now contains the name as well.
46
- - Changed the `topicize()` helper in a way that makes the IDs (and URLs of
47
- some sections) much more readable
48
-
49
- **23/8/2015 [0.3.4]**
50
-
51
- - Fixed an issue that prevented overriding the Rake task's options at runtime.
52
- - Updated `config/yard_api.yml` to reflect the recently added options.
53
-
54
- **17/8/2015 [0.3.3]**
55
-
56
- - Improved the JSON format's output to be more concise and consistent.
57
-
58
- **30/7/2015 [0.3.1]**
59
-
60
- - Fixed a bug that was listing all the endpoints of a certain controller even if they do not have a route defined. Now, YARD-API will warn about endpoints that have an `@API` tag but could not be routed.
61
- - Greatly improved the performance of generating the Quicklinks table.
62
-
63
- **29/7/2015 [0.3.0]**
64
-
65
- - major rework of the linking logic, much improvements but some stuff is broken now
66
-
67
- **28/7/2015 [0.2.3]**
68
-
69
- - dropped the `@argument_scope` tag
70
- - JSON is available as an output format now
71
- - added usage documentation, found at [http://amireh.github.io/yard-api]
72
- - added an example app
73
- - various style improvements
74
- - `@example_request` is now able to output a sample cURL command.
75
-
76
- **0.1.7**
77
-
78
- - new compatibility option `leading_argument_name_fix`
79
-
80
- **15/9/2014**
81
-
82
- - `@argument` tags can now be formatted in a table by setting the `tabular_arguments` option to true
83
- - `@argument_scope`: a new tag that improves the formatting of endpoint arguments that are scoped by a common prefix (e.g, nested inside a json object), like `user[name]` => `name`
84
- - `@argument` can now parse accepted values in two formats; inline within the types array, or by explicitly writing it in the tag text using any of `Accepted values: [...]`, `Accepts: [...]`, or `Possible values: [...]`
85
- - A new option: `strict_arguments` that provides a default for the `is_required` property of `@argument` tags. This default is used if the tag does not explicitly state `Optional` or `Required` in its type specifier.
86
- - Support for dynamic javascript and style code based on options. See `templates/layout/setup.rb#inline_{javascripts,stylesheets}`
87
- - A new set of options for customizing layout: `content_width`, `sidebar_width` and `spacer`
88
- - `github_url` and `github_branch` options for tuning api endpoint source links
89
-
90
- **14/9/2014**
91
-
92
- - Support for single-page output through the `one_file` option
93
- - Support for resource index generation ("All Resources") through the `resource_index` option
94
-
95
- **10/9/2014**
96
-
97
- - Support for github-flavored markdown when you're using Markdown as a markup, and `redcarpet` as the provider
98
- - Syntax highlighting for multiple languages (with auto-detection) using [highlight.js](https://highlightjs.org/)
99
- - `@example_response` and `@example_request` tags now support a title for the response
100
- - A new option: `copyright` for displaying a copyright in the footer of every page
101
- - A new option: `footer_note` for displaying a custom note, like linking to the project's source code, in the footer of every page
43
+ See CHANGES.md.
102
44
 
103
45
  ## License
104
46
 
@@ -17,7 +17,7 @@ module YARD::APIPlugin::Markup
17
17
  }.freeze
18
18
 
19
19
  RendererOptions = {
20
- }.freeze
20
+ }
21
21
 
22
22
  def initialize(text, extensions_and_options=nil)
23
23
  @renderer = Redcarpet::Render::HTML.new(RendererOptions)
@@ -21,6 +21,7 @@ module YARD::APIPlugin
21
21
  default_attr :footer_note, ''
22
22
 
23
23
  default_attr :one_file, false
24
+ default_attr :include_internal, false
24
25
  default_attr :strict, false
25
26
  default_attr :verbose, ENV['VERBOSE'] || false
26
27
  default_attr :debug, ENV['DEBUG'] || false
@@ -100,7 +100,7 @@ module YARD::Templates::Helpers::HtmlHelper
100
100
  end
101
101
  end
102
102
 
103
- def sidebar_link(href, title, is_active)
103
+ def sidebar_link(href, title, is_active=false)
104
104
  link_url(href, title, { class: is_active ? 'active' : '' })
105
105
  end
106
106
 
@@ -31,8 +31,17 @@ module YARD::Templates::Helpers
31
31
  end
32
32
 
33
33
  def get_route_verb(route)
34
- route.verb.source =~ /\^?(\w*)\$/ ? $1.upcase : route.verb.source
34
+ verb = route.verb
35
+
36
+ case verb
37
+ when Regexp
38
+ verb.source =~ /\^?(\w*)\$/ ? $1.upcase : verb.source
39
+ when String
40
+ verb
41
+ else
42
+ "???"
43
+ end
35
44
  end
36
45
  end
37
46
  end
38
- end
47
+ end
@@ -22,13 +22,14 @@ module YARD
22
22
  end
23
23
 
24
24
  def relevant_object?(object)
25
+ doc_include_internal = !!YARD::APIPlugin.options[:include_internal]
25
26
  case object.type
26
27
  when :root, :module, :constant
27
28
  false
28
29
  when :api
29
30
  true
30
31
  when :method
31
- return false if object.has_tag?(:internal) || !object.has_tag?(:API)
32
+ return false if object.has_tag?(:internal) && !doc_include_internal || !object.has_tag?(:API)
32
33
  routes = @routes[object.object_id]
33
34
  routes ||= begin
34
35
  @routes[object.object_id] = YARD::Templates::Helpers::RouteHelper.routes_for_yard_object(object)
@@ -43,7 +44,7 @@ module YARD
43
44
 
44
45
  routes.any?
45
46
  when :class
46
- return false if object.has_tag?(:internal) || !object.has_tag?(:API)
47
+ return false if object.has_tag?(:internal) && !doc_include_internal || !object.has_tag?(:API)
47
48
  true
48
49
  else
49
50
  object.parent.nil? && relevant_object?(object.parent)
@@ -1,5 +1,5 @@
1
1
  module YARD
2
2
  module APIPlugin
3
- VERSION = "0.3.7"
3
+ VERSION = "1.1.2"
4
4
  end
5
5
  end
@@ -1,25 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- module YARD
4
- module Serializers
5
- # A serializer that writes data to standard output.
6
- class SpecSerializer < Base
7
- # Creates a serializer to print text to stdout
8
- #
9
- # @param [Fixnum, nil] wrap if wrap is a number, wraps text to +wrap+
10
- # columns, otherwise no wrapping is done.
11
- def initialize(buffer)
12
- @buffer = buffer
13
- end
14
-
15
- # Overrides serialize behaviour to write data to standard output
16
- def serialize(object, data)
17
- @buffer << data
18
- end
19
- end
20
- end
21
- end
22
-
23
3
  describe YARD::Templates::Engine.template(:api, :fulldoc) do
24
4
  before do
25
5
  Registry.clear
@@ -1,3 +1,6 @@
1
+ require 'json'
2
+ require 'pry'
3
+
1
4
  # This file was generated by the `rspec --init` command. Conventionally, all
2
5
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
6
  # The generated `.rspec` file contains `--require spec_helper` which will cause this
@@ -15,7 +18,6 @@
15
18
  #
16
19
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
20
  RSpec.configure do |config|
18
-
19
21
  require File.join(File.dirname(__FILE__), '..', 'lib', 'yard-api')
20
22
 
21
23
  # rspec-expectations config goes here. You can use an alternate
@@ -123,3 +125,26 @@ RSpec.configure do |config|
123
125
  YARD.parse_string str if str
124
126
  end
125
127
  end
128
+
129
+
130
+ module YARD
131
+ module Serializers
132
+ # A serializer that writes data to standard output.
133
+ class SpecSerializer < Base
134
+ attr_writer :basepath
135
+
136
+ # Creates a serializer to print text to stdout
137
+ #
138
+ # @param [Fixnum, nil] wrap if wrap is a number, wraps text to +wrap+
139
+ # columns, otherwise no wrapping is done.
140
+ def initialize(buffer)
141
+ @buffer = buffer
142
+ end
143
+
144
+ # Overrides serialize behaviour to write data to standard output
145
+ def serialize(object, data)
146
+ @buffer << data
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe YARD::Templates::Engine.template(:api, :fulldoc) do
4
+ before(:each) do
5
+ YARD::Registry.clear
6
+ end
7
+
8
+ after(:each) do
9
+ YARD::Registry.clear
10
+ end
11
+
12
+ before(:each) do
13
+ populate <<-'eof'
14
+ # @API Quizzes
15
+ # @internal
16
+ class QuizzesController < ApplicationController
17
+ end
18
+ eof
19
+ end
20
+
21
+ let(:serializer) { YARD::Serializers::SpecSerializer.new([]) }
22
+ let(:verifier) { YARD::APIPlugin::Verifier.new }
23
+
24
+ it 'should hide entities marked with @internal' do
25
+ entities = YARD::Registry.all
26
+
27
+ YARD::Templates::Engine.render({
28
+ objects: entities,
29
+ type: :fulldoc,
30
+ template: :api,
31
+ format: :json,
32
+ serializer: serializer
33
+ })
34
+
35
+ expect(entities.size).to be > 0
36
+ expect(verifier.run(entities).size).to be == 0
37
+ end
38
+
39
+ context 'when the "include_internal" option is turned on...' do
40
+ before(:each) do
41
+ set_option(:include_internal, true)
42
+ end
43
+
44
+ it 'should not hide entities marked with @internal' do
45
+ populate <<-'eof'
46
+ # @API Quizzes
47
+ # @internal
48
+ class QuizzesController < ApplicationController
49
+ end
50
+ eof
51
+
52
+ entities = YARD::Registry.all
53
+
54
+ YARD::Templates::Engine.render({
55
+ objects: entities,
56
+ type: :fulldoc,
57
+ template: :api,
58
+ format: :json,
59
+ serializer: serializer
60
+ })
61
+
62
+ expect(entities.size).to be > 0
63
+ expect(verifier.run(entities).size).to eq(entities.size)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,153 @@
1
+ /*
2
+
3
+ Original style from softwaremaniacs.org (c) Ivan Sagalaev <Maniac@SoftwareManiacs.Org>
4
+
5
+ */
6
+
7
+ .hljs {
8
+ display: block;
9
+ overflow-x: auto;
10
+ padding: 0.5em;
11
+ background: #f0f0f0;
12
+ -webkit-text-size-adjust: none;
13
+ }
14
+
15
+ .hljs,
16
+ .hljs-subst,
17
+ .hljs-tag .hljs-title,
18
+ .nginx .hljs-title {
19
+ color: black;
20
+ }
21
+
22
+ .hljs-string,
23
+ .hljs-title,
24
+ .hljs-constant,
25
+ .hljs-parent,
26
+ .hljs-tag .hljs-value,
27
+ .hljs-rules .hljs-value,
28
+ .hljs-preprocessor,
29
+ .hljs-pragma,
30
+ .haml .hljs-symbol,
31
+ .ruby .hljs-symbol,
32
+ .ruby .hljs-symbol .hljs-string,
33
+ .hljs-template_tag,
34
+ .django .hljs-variable,
35
+ .smalltalk .hljs-class,
36
+ .hljs-addition,
37
+ .hljs-flow,
38
+ .hljs-stream,
39
+ .bash .hljs-variable,
40
+ .apache .hljs-tag,
41
+ .apache .hljs-cbracket,
42
+ .tex .hljs-command,
43
+ .tex .hljs-special,
44
+ .erlang_repl .hljs-function_or_atom,
45
+ .asciidoc .hljs-header,
46
+ .markdown .hljs-header,
47
+ .coffeescript .hljs-attribute {
48
+ color: #800;
49
+ }
50
+
51
+ .smartquote,
52
+ .hljs-comment,
53
+ .hljs-annotation,
54
+ .hljs-template_comment,
55
+ .diff .hljs-header,
56
+ .hljs-chunk,
57
+ .asciidoc .hljs-blockquote,
58
+ .markdown .hljs-blockquote {
59
+ color: #888;
60
+ }
61
+
62
+ .hljs-number,
63
+ .hljs-date,
64
+ .hljs-regexp,
65
+ .hljs-literal,
66
+ .hljs-hexcolor,
67
+ .smalltalk .hljs-symbol,
68
+ .smalltalk .hljs-char,
69
+ .go .hljs-constant,
70
+ .hljs-change,
71
+ .lasso .hljs-variable,
72
+ .makefile .hljs-variable,
73
+ .asciidoc .hljs-bullet,
74
+ .markdown .hljs-bullet,
75
+ .asciidoc .hljs-link_url,
76
+ .markdown .hljs-link_url {
77
+ color: #080;
78
+ }
79
+
80
+ .hljs-label,
81
+ .hljs-javadoc,
82
+ .ruby .hljs-string,
83
+ .hljs-decorator,
84
+ .hljs-filter .hljs-argument,
85
+ .hljs-localvars,
86
+ .hljs-array,
87
+ .hljs-attr_selector,
88
+ .hljs-important,
89
+ .hljs-pseudo,
90
+ .hljs-pi,
91
+ .haml .hljs-bullet,
92
+ .hljs-doctype,
93
+ .hljs-deletion,
94
+ .hljs-envvar,
95
+ .hljs-shebang,
96
+ .apache .hljs-sqbracket,
97
+ .nginx .hljs-built_in,
98
+ .tex .hljs-formula,
99
+ .erlang_repl .hljs-reserved,
100
+ .hljs-prompt,
101
+ .asciidoc .hljs-link_label,
102
+ .markdown .hljs-link_label,
103
+ .vhdl .hljs-attribute,
104
+ .clojure .hljs-attribute,
105
+ .asciidoc .hljs-attribute,
106
+ .lasso .hljs-attribute,
107
+ .coffeescript .hljs-property,
108
+ .hljs-phony {
109
+ color: #88f;
110
+ }
111
+
112
+ .hljs-keyword,
113
+ .hljs-id,
114
+ .hljs-title,
115
+ .hljs-built_in,
116
+ .css .hljs-tag,
117
+ .hljs-javadoctag,
118
+ .hljs-phpdoc,
119
+ .hljs-dartdoc,
120
+ .hljs-yardoctag,
121
+ .smalltalk .hljs-class,
122
+ .hljs-winutils,
123
+ .bash .hljs-variable,
124
+ .apache .hljs-tag,
125
+ .hljs-type,
126
+ .hljs-typename,
127
+ .tex .hljs-command,
128
+ .asciidoc .hljs-strong,
129
+ .markdown .hljs-strong,
130
+ .hljs-request,
131
+ .hljs-status {
132
+ font-weight: bold;
133
+ }
134
+
135
+ .asciidoc .hljs-emphasis,
136
+ .markdown .hljs-emphasis {
137
+ font-style: italic;
138
+ }
139
+
140
+ .nginx .hljs-built_in {
141
+ font-weight: normal;
142
+ }
143
+
144
+ .coffeescript .javascript,
145
+ .javascript .xml,
146
+ .lasso .markup,
147
+ .tex .hljs-formula,
148
+ .xml .javascript,
149
+ .xml .vbscript,
150
+ .xml .css,
151
+ .xml .hljs-cdata {
152
+ opacity: 0.5;
153
+ }
@@ -55,7 +55,22 @@ def dump_object(obj)
55
55
  is_required = prop.has_key?('required') ? prop['required'] : false
56
56
  is_required_str = is_required ? 'Required' : 'Optional'
57
57
 
58
- ArgumentTag.new(nil, "[#{is_required_str}, #{prop['type']}] #{prop_name}\n #{prop['description']}")
58
+ {
59
+ "name" => prop_name,
60
+ "types" => Array(prop["type"]),
61
+ "is_required" => !!prop["required"],
62
+ "text" => prop.fetch('description', ''),
63
+ "example" => prop['example'],
64
+ "accepted_values" => Array(
65
+ first_in([
66
+ "accepted values",
67
+ "accepted_values",
68
+ "accepts",
69
+ "accepted",
70
+ "acceptable values",
71
+ ], prop)
72
+ )
73
+ }
59
74
  end
60
75
 
61
76
  {
@@ -64,7 +79,7 @@ def dump_object(obj)
64
79
  title: title,
65
80
  text: spec['description'] || '',
66
81
  controller: obj.object.path,
67
- schema: schema_tags.as_json.map { |e| e.delete('tag_name'); e }
82
+ schema: schema_tags
68
83
  }
69
84
  end
70
85
 
@@ -114,15 +129,13 @@ def get_route(object)
114
129
  route = routes.first
115
130
 
116
131
  if route.present?
117
- verb = if route.verb.source =~ /\^?(\w*)\$/
118
- $1.upcase
119
- else
120
- route.verb.source
121
- end
122
-
123
132
  {
124
- path: route.path.spec.to_s.gsub("(.:format)", ""),
125
- verb: verb
133
+ path: RouteHelper.get_route_path(route),
134
+ verb: RouteHelper.get_route_verb(route)
126
135
  }
127
136
  end
128
137
  end
138
+
139
+ def first_in(keys, obj)
140
+ obj[keys.detect { |k| obj.key?(k) }]
141
+ end
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  ['LICENSE', 'README.md', '.rspec', __FILE__]
16
16
  s.has_rdoc = 'yard'
17
17
  s.license = 'AGPL-3.0'
18
- s.add_dependency 'yard', '0.8.7'
18
+ s.add_dependency 'yard', '~> 0.9.15'
19
19
  s.add_dependency 'yard-appendix', '~> 0.1.8'
20
20
  s.add_development_dependency 'rspec', '~> 3.3'
21
21
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmad Amireh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-25 00:00:00.000000000 Z
11
+ date: 2020-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.7
19
+ version: 0.9.15
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.8.7
26
+ version: 0.9.15
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: yard-appendix
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -82,6 +82,7 @@ files:
82
82
  - spec/helpers/html_helper_spec.rb
83
83
  - spec/spec_helper.rb
84
84
  - spec/tags/argument_spec.rb
85
+ - spec/tags/internal_spec.rb
85
86
  - tasks/yard_api.rake
86
87
  - templates/api/appendix/html/setup.rb
87
88
  - templates/api/appendix/json/setup.rb
@@ -206,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
207
  version: '0'
207
208
  requirements: []
208
209
  rubyforge_project:
209
- rubygems_version: 2.7.6
210
+ rubygems_version: 2.7.6.2
210
211
  signing_key:
211
212
  specification_version: 4
212
213
  summary: A YARD plugin for documenting APIs in Rails projects.
@@ -1 +0,0 @@
1
- templates/api/fulldoc/html/css/../js/highlight/styles/mono-blue.css