yard-heuristics 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,6 +25,7 @@ module YARDHeuristics
25
25
  :/ => :type,
26
26
  :each => %w'self',
27
27
  :each_with_index => %w'self',
28
+ :hash => %w'Integer',
28
29
  :inspect => %w'String',
29
30
  :length => %w'Integer',
30
31
  :size => %w'Integer',
@@ -53,6 +54,7 @@ end
53
54
  YARD::DocstringParser.after_parse do |parser|
54
55
  next unless YARD::CodeObjects::MethodObject === parser.object
55
56
  next if parser.text.empty? and parser.tags.empty?
57
+ next if parser.raw_text =~ /\A\(see.*\)\z/
56
58
  name = parser.object.namespace ?
57
59
  (parser.object.namespace.namespace ?
58
60
  parser.object.namespace.relative_path(parser.object.namespace) :
@@ -99,3 +101,22 @@ YARD::DocstringParser.after_parse do |parser|
99
101
  end
100
102
  end
101
103
  end
104
+
105
+ module YARD::Templates::Helpers::HtmlHelper
106
+ alias yardheuristics_saved_htmlify htmlify
107
+ def htmlify(text, markup = options.markup)
108
+ yardheuristics_saved_htmlify(text, markup).gsub(/\b([[:upper:]]+)(th)?\b/){
109
+ if $`.end_with?('$') or not YARD::CodeObjects::MethodObject === object
110
+ $&
111
+ else
112
+ parameter = $1.downcase
113
+ ((object.parameters.assoc(parameter) ||
114
+ object.parameters.assoc('*' + parameter) ||
115
+ object.parameters.assoc('&' + parameter) ||
116
+ object.tags.find{ |e| e.tag_name == 'yieldparam' and e.name == parameter }) ?
117
+ '<em class="parameter">%s</em>' % parameter :
118
+ $1) + $2.to_s
119
+ end
120
+ }
121
+ end
122
+ end
@@ -3,7 +3,7 @@
3
3
  require 'inventory-1.0'
4
4
 
5
5
  module YARDHeuristics
6
- Version = Inventory.new(1, 0, 1){
6
+ Version = Inventory.new(1, 1, 0){
7
7
  def dependencies
8
8
  super + Inventory::Dependencies.new{
9
9
  development 'inventory-rake', 1, 3, 0
@@ -107,4 +107,114 @@ end
107
107
  EOS
108
108
  YARD::Registry.at('#a').docstring.tags(:param).last.types
109
109
  end
110
+
111
+ expect [%w'self'] do
112
+ YARD::Registry.clear
113
+ YARD::Parser::SourceParser.parse_string(<<EOS)
114
+ # @return [self]
115
+ def b(&block)
116
+ end
117
+ # (see #b)
118
+ def <<(&block)
119
+ end
120
+ EOS
121
+ YARD::Registry.at('#<<').docstring.tags(:return).map{ |e| e.types }
122
+ end
123
+
124
+ expect 'Emphasizes <em class="parameter">parameter</em>.' do
125
+ YARD::Registry.clear
126
+ YARD::Parser::SourceParser.parse_string(<<EOS)
127
+ # Emphasizes PARAMETER.
128
+ def a(parameter)
129
+ end
130
+ EOS
131
+ Module.new{
132
+ class << self
133
+ include YARD::Templates::Helpers::HtmlHelper
134
+ def options
135
+ YARD::Templates::TemplateOptions.new{ |o|
136
+ o.reset_defaults
137
+ }
138
+ end
139
+ def object
140
+ YARD::Registry.at('#a')
141
+ end
142
+ end
143
+ }.instance_eval{
144
+ htmlify(YARD::Registry.at('#a').docstring)
145
+ }
146
+ end
147
+
148
+ expect 'The <em class="parameter">index</em>th element.' do
149
+ YARD::Registry.clear
150
+ YARD::Parser::SourceParser.parse_string(<<EOS)
151
+ # The INDEXth element.
152
+ def a(index)
153
+ end
154
+ EOS
155
+ Module.new{
156
+ class << self
157
+ include YARD::Templates::Helpers::HtmlHelper
158
+ def options
159
+ YARD::Templates::TemplateOptions.new{ |o|
160
+ o.reset_defaults
161
+ }
162
+ end
163
+ def object
164
+ YARD::Registry.at('#a')
165
+ end
166
+ end
167
+ }.instance_eval{
168
+ htmlify(YARD::Registry.at('#a').docstring)
169
+ }
170
+ end
171
+
172
+ expect 'The value of $VERBOSE.' do
173
+ YARD::Registry.clear
174
+ YARD::Parser::SourceParser.parse_string(<<EOS)
175
+ # The value of $VERBOSE.
176
+ def a(verbose)
177
+ end
178
+ EOS
179
+ Module.new{
180
+ class << self
181
+ include YARD::Templates::Helpers::HtmlHelper
182
+ def options
183
+ YARD::Templates::TemplateOptions.new{ |o|
184
+ o.reset_defaults
185
+ }
186
+ end
187
+ def object
188
+ YARD::Registry.at('#a')
189
+ end
190
+ end
191
+ }.instance_eval{
192
+ htmlify(YARD::Registry.at('#a').docstring)
193
+ }
194
+ end
195
+
196
+ expect 'Yields the <em class="parameter">exception</em>.' do
197
+ YARD::Registry.clear
198
+ YARD::Parser::SourceParser.parse_string(<<EOS)
199
+ # Yields the EXCEPTION.
200
+ # @yieldparam [Exception] exception
201
+ def a
202
+ end
203
+ EOS
204
+ Module.new{
205
+ class << self
206
+ include YARD::Templates::Helpers::HtmlHelper
207
+ def options
208
+ YARD::Templates::TemplateOptions.new{ |o|
209
+ o.reset_defaults
210
+ }
211
+ end
212
+ def object
213
+ YARD::Registry.at('#a')
214
+ end
215
+ end
216
+ }.instance_eval{
217
+ htmlify(YARD::Registry.at('#a').docstring)
218
+ }
219
+ end
110
220
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-heuristics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-03 00:00:00.000000000 Z
12
+ date: 2012-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: inventory
16
- requirement: &15064488 !ruby/object:Gem::Requirement
16
+ requirement: &15442740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *15064488
24
+ version_requirements: *15442740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: inventory-rake
27
- requirement: &15063012 !ruby/object:Gem::Requirement
27
+ requirement: &15441408 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.3'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *15063012
35
+ version_requirements: *15441408
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: lookout
38
- requirement: &15061752 !ruby/object:Gem::Requirement
38
+ requirement: &15440268 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *15061752
46
+ version_requirements: *15440268
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: lookout-rake
49
- requirement: &15061260 !ruby/object:Gem::Requirement
49
+ requirement: &15438504 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '3.0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *15061260
57
+ version_requirements: *15438504
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: yard
60
- requirement: &15091644 !ruby/object:Gem::Requirement
60
+ requirement: &15436296 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 0.8.0
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *15091644
68
+ version_requirements: *15436296
69
69
  description: ! " YARD-Heuristics\n\n YARD-Heuristics
70
70
  heuristically determines types of parameters and return\n values to YARD.\n"
71
71
  email: now@bitwi.se