yard-api 0.1.8 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f85c9b29ec43288a01d9a3a1da6dc98efe4edba
4
- data.tar.gz: 71062272d43be57a50ef1044588f15e4ec79a290
3
+ metadata.gz: 2f894b7c9e0efdee454a068de0105e061b713784
4
+ data.tar.gz: a5eb169d8372bcea684866395a2a4ecddda65385
5
5
  SHA512:
6
- metadata.gz: f67b6fcd65e95be498ccfed4847222d5cae3365c2e75f3c648fc6b6ad5b4aeebace9bf951d72b77379f81f506b6c578e138c2521719a7225aa86dfac678a5094
7
- data.tar.gz: 6cb625748831b6d18fb3cc631750ba2eed5f0f6436aeeb5071e98644cc7e54190609b52e8026dd74966da870ebad6abe72d2e2dfe6bcda13da4cb8c0cf21b9a0
6
+ metadata.gz: 297b3d21420a0a60052d77f4d2748ed252e32298e78b3e87d2b7f13f6229efe389483b52bc4f309399b87eb5b816befe0f91c7be4fa479aa81f383890b453479
7
+ data.tar.gz: fea346e1cee3d55253920f2fba306f797a5a86c41e74418e42958ace2d96dd2269499808df1f345080716f002ee4afd8816c93686cec1b9235e1d1459e9d7cc0
data/README.md CHANGED
@@ -8,6 +8,22 @@ TODO
8
8
 
9
9
  TODO
10
10
 
11
+ ### Compatibility options
12
+
13
+ #### `@argument` tags with names specified before types
14
+
15
+ For tags that have a type and a name such as the YARD `@attr` tag, or the yard-api `@argument` tag, the "correct" syntax is to specify the types *before* the name. For example:
16
+
17
+ ```ruby
18
+ # @argument [String] name
19
+ # This is compliant with YARD syntax.
20
+ #
21
+ # @argument name [String]
22
+ # This is not compliant with YARD syntax.
23
+ ```
24
+
25
+ If your project already uses the (incorrect) second syntax and you would like to keep things that way, then you can use the compatibility option `leading_argument_name_fix` to have yard-api correctify this and understand both flavors.
26
+
11
27
  ## Configuration
12
28
 
13
29
  `yard-api` will look for a file in `config/yard_api.yml` in the Rails root for customizations. Configuration fields not specified in that file will be filled with the default values found in [config/yard_api.yml](https://github.com/amireh/yard-api/blob/master/config/yard_api.yml).
@@ -20,6 +36,10 @@ Read that file to view all the available options.
20
36
 
21
37
  ## Changelog
22
38
 
39
+ **0.1.7**
40
+
41
+ - new compatibility option `leading_argument_name_fix`
42
+
23
43
  **15/9/2014**
24
44
 
25
45
  - `@argument` tags can now be formatted in a table by setting the `tabular_arguments` option to true
data/config/yard_api.yml CHANGED
@@ -83,4 +83,18 @@ sidebar_width: 240
83
83
  content_width: "fluid"
84
84
 
85
85
  # Whitespace between the Sidebar and the content, in pixels.
86
- spacer: 20
86
+ spacer: 20
87
+
88
+ # Compatibility option.
89
+ #
90
+ # If your project (mis)uses the @argument tag to specify the name before the
91
+ # types, e.g `@argument name [String]`, then turn this on and yard-api will
92
+ # make these docstrings compliant with YARD's @attr tag (or any tag with a name
93
+ # and a type, really) which is what @argument uses as its back-end tag.
94
+ #
95
+ # The "right" thing to do is to use the correct YARD syntax:
96
+ #
97
+ # @argument [Type specifier] name_specifier
98
+ #
99
+ # But that may not be viable in very large, existing projects.
100
+ leading_argument_name_fix: false
@@ -26,6 +26,8 @@ module YARD::APIPlugin
26
26
  default_attr :content_width, 'fluid'
27
27
  default_attr :spacer, 20
28
28
 
29
+ default_attr :leading_argument_name_fix, false
30
+
29
31
  attr_accessor :readme
30
32
  end
31
33
  end
@@ -4,6 +4,7 @@ module YARD::APIPlugin::Tags
4
4
  class ArgumentTag < YARD::Tags::Tag
5
5
  attr_reader :accepted_values, :is_required
6
6
 
7
+ RE_NAME = /^([\S]+)/
7
8
  RE_ARRAY_LITERAL = /\[[^\]]+\]/
8
9
  RE_ARRAY_TYPE = /^#{RE_ARRAY_LITERAL}$/
9
10
  RE_ACCEPTED_VALUES_PREFIXES = /
@@ -16,8 +17,26 @@ module YARD::APIPlugin::Tags
16
17
  /mx
17
18
 
18
19
  def initialize(name, buf)
20
+ name = nil
21
+
22
+ # If the name specifier is written before the types and contains brackets,
23
+ # YARD will not properly parse the attributes (it doesn't even say that it
24
+ # supports this syntax so), something like this:
25
+ #
26
+ # @argument shirt[size] [String]
27
+ #
28
+ # We convert the name to use underscores instead and YARD does its magic!
29
+ # Once the tag is parsed, we'll use the original name.
30
+ #
31
+ # @since 0.1.7
32
+ if buf[0] != '[' && YARD::APIPlugin.options.leading_argument_name_fix
33
+ arg_name = buf.match(RE_NAME).captures.first
34
+ buf.sub!(arg_name, arg_name.gsub(/\W/, '_'))
35
+ name = arg_name
36
+ end
37
+
19
38
  YARD::Tags::Library.instance.tag_create(:attr, buf).tap do |tag|
20
- super(:argument, tag.text, tag.types, tag.name)
39
+ super(:argument, tag.text, tag.types, name || tag.name)
21
40
 
22
41
  @is_required = parse_is_required(@types)
23
42
  @accepted_values = parse_accepted_values(@types, @text)
@@ -1,5 +1,5 @@
1
1
  module YARD
2
2
  module APIPlugin
3
- VERSION = "0.1.8"
3
+ VERSION = "0.1.10"
4
4
  end
5
5
  end
@@ -16,6 +16,7 @@ describe YARD::APIPlugin::Tags::ArgumentTag do
16
16
  end
17
17
 
18
18
  it 'should work like an @attr tag' do
19
+ ENV['DO'] = '1'
19
20
  populate <<-'eof'
20
21
  # @argument [String] name
21
22
  # Your full name.
@@ -30,6 +31,46 @@ describe YARD::APIPlugin::Tags::ArgumentTag do
30
31
  expect(tag.types).to eq ['String']
31
32
  end
32
33
 
34
+ describe 'option: leading_argument_name_fix' do
35
+ it 'should work with type and name specifiers swapped "@argument name [String]"' do
36
+ set_option(:leading_argument_name_fix, true)
37
+
38
+ populate <<-'eof'
39
+ # @argument name [String]
40
+ # Your full name.
41
+ #
42
+ # @argument shirt_size [String, ["S", "M", "L"]]
43
+ # Size of the shirt you wear.
44
+ #
45
+ # @argument shirt[size] [String, ["S", "M", "L"]]
46
+ # Size of the shirt you wear.
47
+ #
48
+ def signup
49
+ end
50
+ eof
51
+
52
+ find_tag(:signup, :argument, 0).tap do |tag|
53
+ expect(tag.name).to eq 'name'
54
+ expect(tag.text).to eq 'Your full name.'
55
+ expect(tag.types).to eq ['String']
56
+ end
57
+
58
+ find_tag(:signup, :argument, 1).tap do |tag|
59
+ expect(tag.name).to eq 'shirt_size'
60
+ expect(tag.text).to eq 'Size of the shirt you wear.'
61
+ expect(tag.types).to eq ['String']
62
+ expect(tag.accepted_values).to eq %w[ S M L ]
63
+ end
64
+
65
+ find_tag(:signup, :argument, 2).tap do |tag|
66
+ expect(tag.name).to eq 'shirt[size]'
67
+ expect(tag.text).to eq 'Size of the shirt you wear.'
68
+ expect(tag.types).to eq ['String']
69
+ expect(tag.accepted_values).to eq %w[ S M L ]
70
+ end
71
+ end
72
+ end
73
+
33
74
  describe '#is_required' do
34
75
  it 'should default to whatever Options.strict_arguments is set to' do
35
76
  set_option(:strict_arguments, false)
@@ -124,6 +165,5 @@ describe YARD::APIPlugin::Tags::ArgumentTag do
124
165
 
125
166
  expect(find_tag(:order_shirt, :argument).accepted_values).to eq(%w[S M L XL])
126
167
  end
127
-
128
168
  end
129
169
  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.1.8
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmad Amireh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-15 00:00:00.000000000 Z
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -97,6 +97,7 @@ files:
97
97
  - templates/api/docstring/html/text.erb
98
98
  - templates/api/fulldoc/html/css/common.css
99
99
  - templates/api/fulldoc/html/css/highlight.css
100
+ - templates/api/fulldoc/html/js/highlight.zip
100
101
  - templates/api/fulldoc/html/js/highlight/CHANGES.md
101
102
  - templates/api/fulldoc/html/js/highlight/LICENSE
102
103
  - templates/api/fulldoc/html/js/highlight/README.md