yard 0.9.12 → 0.9.13

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yard might be problematic. Click here for more details.

@@ -33,6 +33,9 @@ RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}Constant
33
33
  expect(obj.constants[0].docstring).to eq 'A constant.'
34
34
  expect(obj.constants[0].name).to eq :CONSTANT
35
35
  expect(obj.constants[0].value).to eq "42"
36
+ expect(obj.constants[1].docstring).to eq 'Special constant (empty symbol)'
37
+ expect(obj.constants[1].name).to eq :EMPTY
38
+ expect(obj.constants[1].value).to eq ':""'
36
39
  end
37
40
 
38
41
  it "turns Const = Struct.new('Name', :sym) into class Const with attr :sym" do
@@ -21,6 +21,8 @@ MyEmptyStruct = Struct.new
21
21
  MyStructWithConstant = Struct.new do
22
22
  # A constant.
23
23
  CONSTANT = 42
24
+ # Special constant (empty symbol)
25
+ EMPTY = :''
24
26
  end
25
27
 
26
28
  # A crazy struct.
@@ -303,6 +303,19 @@ eof
303
303
  end
304
304
  end
305
305
 
306
+ it "properly tokenizes symbols" do
307
+ tokens = tokenize(<<-eof)
308
+ class X
309
+ Foo = :''
310
+ Fuu = :bar
311
+ Bar = :BAR
312
+ Baz = :"B+z"
313
+ end
314
+ eof
315
+ symbols = tokens.select {|t| t[0] == :symbol }.map {|t| t[1] }
316
+ expect(symbols).to eq %w(:'' :bar :BAR :"B+z")
317
+ end
318
+
306
319
  it "parses %w() array in constant declaration" do
307
320
  s = stmt(<<-eof)
308
321
  class Foo
@@ -54,7 +54,11 @@
54
54
 
55
55
  </p>
56
56
 
57
- <h2>Constant Summary</h2>
57
+ <h2>
58
+ Constant Summary
59
+
60
+ <small><a href="#" class="constants_summary_toggle">collapse</a></small>
61
+ </h2>
58
62
 
59
63
  <dl class="constants">
60
64
 
@@ -28,7 +28,11 @@
28
28
  </div>
29
29
 
30
30
 
31
- <h2>Constant Summary</h2>
31
+ <h2>
32
+ Constant Summary
33
+
34
+ <small><a href="#" class="constants_summary_toggle">collapse</a></small>
35
+ </h2>
32
36
 
33
37
  <dl class="constants">
34
38
 
@@ -0,0 +1,82 @@
1
+ <h1>Module: A
2
+
3
+
4
+
5
+ </h1>
6
+ <div class="box_info">
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+ <dl>
19
+ <dt>Defined in:</dt>
20
+ <dd>(stdin)</dd>
21
+ </dl>
22
+
23
+ </div>
24
+
25
+
26
+
27
+ <h2>
28
+ Foo
29
+ <small><a href="#" class="constants_summary_toggle">collapse</a></small>
30
+ </h2>
31
+
32
+ <dl class="constants">
33
+
34
+ <dt id="FOO-constant" class="">FOO =
35
+
36
+ </dt>
37
+ <dd><pre class="code">1</pre></dd>
38
+
39
+ <dt id="BAR-constant" class="deprecated">BAR =
40
+ <div class="docstring">
41
+ <div class="discussion">
42
+ <div class="note deprecated"><strong>Deprecated.</strong> <div class='inline'></div></div>
43
+
44
+
45
+ </div>
46
+ </div>
47
+ <div class="tags">
48
+
49
+
50
+ </div>
51
+ </dt>
52
+ <dd><pre class="code">2</pre></dd>
53
+
54
+ </dl>
55
+
56
+ <h2>
57
+ Bar
58
+ <small><a href="#" class="constants_summary_toggle">collapse</a></small>
59
+ </h2>
60
+
61
+ <dl class="constants">
62
+
63
+ <dt id="BAZ-constant" class="">BAZ =
64
+
65
+ </dt>
66
+ <dd><pre class="code">3</pre></dd>
67
+
68
+ </dl>
69
+
70
+ <h2>
71
+ Constant Summary
72
+ <small><a href="#" class="constants_summary_toggle">collapse</a></small>
73
+ </h2>
74
+
75
+ <dl class="constants">
76
+
77
+ <dt id="WORLD-constant" class="">WORLD =
78
+
79
+ </dt>
80
+ <dd><pre class="code">4</pre></dd>
81
+
82
+ </dl>
@@ -79,4 +79,29 @@ RSpec.describe YARD::Templates::Helpers::MethodHelper do
79
79
  expect(format_block(Registry.at('#foo'))).to eq "{|a, b, c| ... }"
80
80
  end
81
81
  end
82
+
83
+ describe "#format_constant" do
84
+ include YARD::Templates::Helpers::HtmlHelper
85
+
86
+ it "displays correctly constant values which are quoted symbols" do
87
+ YARD.parse_string %(
88
+ class TestFmtConst
89
+ Foo = :''
90
+ Bar = :BAR
91
+ Baz = :'B+z'
92
+ end
93
+ )
94
+ # html_syntax_highlight will be called by format_constant for
95
+ # Foo, Bar and Baz and in turn will enquire for options.highlight
96
+ expect(self).to receive(:options).exactly(3).times.and_return(
97
+ Options.new.update(:highlight => false)
98
+ )
99
+ foo, bar, baz = %w(Foo Bar Baz).map do |c|
100
+ Registry.at("TestFmtConst::#{c}").value
101
+ end
102
+ expect(format_constant(foo)).to eq ":&quot;&quot;"
103
+ expect(format_constant(bar)).to eq ':BAR'
104
+ expect(format_constant(baz)).to eq ":&quot;B+z&quot;"
105
+ end
106
+ end
82
107
  end
@@ -179,4 +179,25 @@ RSpec.describe YARD::Templates::Engine.template(:default, :module) do
179
179
 
180
180
  html_equals(Registry.at('A').format(html_options(:embed_mixins => ['Foo', 'Bar', 'Baz::A*'])), :module004)
181
181
  end
182
+
183
+ it "renders constant groups correctly in html" do
184
+ Registry.clear
185
+ YARD.parse_string <<-'eof'
186
+ module A
187
+ # @group Foo
188
+ FOO = 1
189
+
190
+ # @deprecated
191
+ BAR = 2
192
+
193
+ # @group Bar
194
+ BAZ = 3
195
+
196
+ # @endgroup
197
+
198
+ WORLD = 4
199
+ end
200
+ eof
201
+ html_equals(Registry.at('A').format(html_options), :module005)
202
+ end
182
203
  end
@@ -245,6 +245,7 @@ ul.toplevel { list-style: none; padding-left: 0; font-size: 1.1em; }
245
245
 
246
246
  dl.constants { margin-left: 10px; }
247
247
  dl.constants dt { font-weight: bold; font-size: 1.1em; margin-bottom: 5px; }
248
+ dl.constants.compact dt { display: inline-block; font-weight: normal }
248
249
  dl.constants dd { width: 75%; white-space: pre; font-family: monospace; margin-bottom: 18px; }
249
250
  dl.constants .docstring .note:first-child { margin-top: 5px; }
250
251
 
@@ -326,13 +327,9 @@ ul.summary a, ul.summary a:visited {
326
327
  text-decoration: none; font-size: 1.1em;
327
328
  }
328
329
  ul.summary li { margin-bottom: 5px; }
329
- .summary .summary_signature {
330
- padding: 4px 8px;
331
- background: #f8f8f8;
332
- border: 1px solid #f0f0f0;
333
- border-radius: 5px;
334
- }
330
+ .summary_signature { padding: 4px 8px; background: #f8f8f8; border: 1px solid #f0f0f0; border-radius: 5px; }
335
331
  .summary_signature:hover { background: #CFEBFF; border-color: #A4CCDA; cursor: pointer; }
332
+ .summary_signature.deprecated { background: #ffe5e5; border-color: #e9dada; }
336
333
  ul.summary.compact li { display: inline-block; margin: 0px 5px 0px 0px; line-height: 2.6em;}
337
334
  ul.summary.compact .summary_signature { padding: 5px 7px; padding-right: 4px; }
338
335
  #content .summary_signature:hover a,
@@ -485,7 +482,7 @@ pre.code .rubyid_nth_ref { color: #6D79DE; }
485
482
  pre.code .regexp, .dregexp { color: #036A07; }
486
483
  pre.code a { border-bottom: 1px dotted #bbf; }
487
484
  /* inline code */
488
- p > code {
485
+ *:not(pre) > code {
489
486
  padding: 1px 3px 1px 3px;
490
487
  border: 1px solid #E1E1E8;
491
488
  background: #F7F7F9;
@@ -120,6 +120,49 @@ function summaryToggle() {
120
120
  } else { localStorage.summaryCollapsed = "expand"; }
121
121
  }
122
122
 
123
+ function constantSummaryToggle() {
124
+ $('.constants_summary_toggle').click(function(e) {
125
+ e.preventDefault();
126
+ localStorage.summaryCollapsed = $(this).text();
127
+ $('.constants_summary_toggle').each(function() {
128
+ $(this).text($(this).text() == "collapse" ? "expand" : "collapse");
129
+ var next = $(this).parent().parent().nextAll('dl.constants').first();
130
+ if (next.hasClass('compact')) {
131
+ next.toggle();
132
+ next.nextAll('dl.constants').first().toggle();
133
+ }
134
+ else if (next.hasClass('constants')) {
135
+ var list = $('<dl class="constants compact" />');
136
+ list.html(next.html());
137
+ list.find('dt').each(function() {
138
+ $(this).addClass('summary_signature');
139
+ $(this).text( $(this).text().split('=')[0]);
140
+ if ($(this).has(".deprecated").length) {
141
+ $(this).addClass('deprecated');
142
+ };
143
+ });
144
+ // Add the value of the constant as "Tooltip" to the summary object
145
+ list.find('pre.code').each(function() {
146
+ console.log($(this).parent());
147
+ var dt_element = $(this).parent().prev();
148
+ var tooltip = $(this).text();
149
+ if (dt_element.hasClass("deprecated")) {
150
+ tooltip = 'Deprecated. ' + tooltip;
151
+ };
152
+ dt_element.attr('title', tooltip);
153
+ });
154
+ list.find('.docstring, .tags, dd').remove();
155
+ next.before(list);
156
+ next.toggle();
157
+ }
158
+ });
159
+ return false;
160
+ });
161
+ if (localStorage.summaryCollapsed == "collapse") {
162
+ $('.constants_summary_toggle').first().click();
163
+ } else { localStorage.summaryCollapsed = "expand"; }
164
+ }
165
+
123
166
  function generateTOC() {
124
167
  if ($('#filecontents').length === 0) return;
125
168
  var _toc = $('<ol class="top"></ol>');
@@ -241,6 +284,7 @@ $(document).ready(function() {
241
284
  searchFrameButtons();
242
285
  linkSummaries();
243
286
  summaryToggle();
287
+ constantSummaryToggle();
244
288
  generateTOC();
245
289
  mainFocus();
246
290
  });
@@ -1,11 +1,17 @@
1
1
  <% if constant_listing.size > 0 %>
2
- <h2>Constant Summary</h2>
3
- <dl class="constants">
4
- <% constant_listing.each do |cnst| %>
5
- <dt id="<%= anchor_for(cnst) %>" class="<%= cnst.has_tag?(:deprecated) ? 'deprecated' : '' %>"><%= cnst.name %> =
6
- <%= yieldall :object => cnst %>
7
- </dt>
8
- <dd><pre class="code"><%= format_constant cnst.value %></pre></dd>
9
- <% end %>
10
- </dl>
2
+ <% groups(constant_listing, "Constant") do |list, name| %>
3
+ <h2>
4
+ <%= name %>
5
+ <small><a href="#" class="constants_summary_toggle">collapse</a></small>
6
+ </h2>
7
+
8
+ <dl class="constants">
9
+ <% list.each do |cnst| %>
10
+ <dt id="<%= anchor_for(cnst) %>" class="<%= cnst.has_tag?(:deprecated) ? 'deprecated' : '' %>"><%= cnst.name %> =
11
+ <%= yieldall :object => cnst %>
12
+ </dt>
13
+ <dd><pre class="code"><%= format_constant cnst.value %></pre></dd>
14
+ <% end %>
15
+ </dl>
16
+ <% end %>
11
17
  <% end %>
@@ -131,17 +131,22 @@ def groups(list, type = "Method")
131
131
  else
132
132
  others = []
133
133
  group_data = {}
134
- list.each do |meth|
135
- if meth.group
136
- (group_data[meth.group] ||= []) << meth
134
+ list.each do |itm|
135
+ if itm.group
136
+ (group_data[itm.group] ||= []) << itm
137
137
  else
138
- others << meth
138
+ others << itm
139
139
  end
140
140
  end
141
141
  group_data.each {|group, items| yield(items, group) unless items.empty? }
142
142
  end
143
143
 
144
- scopes(others) {|items, scope| yield(items, "#{scope.to_s.capitalize} #{type} Summary") }
144
+ return if others.empty?
145
+ if others.first.respond_to?(:scope)
146
+ scopes(others) {|items, scope| yield(items, "#{scope.to_s.capitalize} #{type} Summary") }
147
+ else
148
+ yield(others, "#{type} Summary")
149
+ end
145
150
  end
146
151
 
147
152
  def scopes(list)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.12
4
+ version: 0.9.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loren Segal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-26 00:00:00.000000000 Z
11
+ date: 2018-05-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  YARD is a documentation generation tool for the Ruby programming language.
@@ -454,6 +454,7 @@ files:
454
454
  - spec/templates/examples/module002.html
455
455
  - spec/templates/examples/module003.html
456
456
  - spec/templates/examples/module004.html
457
+ - spec/templates/examples/module005.html
457
458
  - spec/templates/examples/tag001.txt
458
459
  - spec/templates/helpers/base_helper_spec.rb
459
460
  - spec/templates/helpers/html_helper_spec.rb