Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable groups for constants (Resolves #610) #1056

Merged
merged 4 commits into from Apr 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion spec/templates/examples/module001.html
Expand Up @@ -54,7 +54,11 @@ <h2>Overview</h2><div class="docstring">

</p>

<h2>Constant Summary</h2>
<h2>
Constant Summary

<small><a href="#" class="constants_summary_toggle">collapse</a></small>
</h2>

<dl class="constants">

Expand Down
6 changes: 5 additions & 1 deletion spec/templates/examples/module003.html
Expand Up @@ -28,7 +28,11 @@ <h1>Module: A
</div>


<h2>Constant Summary</h2>
<h2>
Constant Summary

<small><a href="#" class="constants_summary_toggle">collapse</a></small>
</h2>

<dl class="constants">

Expand Down
82 changes: 82 additions & 0 deletions spec/templates/examples/module005.html
@@ -0,0 +1,82 @@
<h1>Module: A



</h1>
<div class="box_info">











<dl>
<dt>Defined in:</dt>
<dd>(stdin)</dd>
</dl>

</div>



<h2>
Foo
<small><a href="#" class="constants_summary_toggle">collapse</a></small>
</h2>

<dl class="constants">

<dt id="FOO-constant" class="">FOO =

</dt>
<dd><pre class="code">1</pre></dd>

<dt id="BAR-constant" class="deprecated">BAR =
<div class="docstring">
<div class="discussion">
<div class="note deprecated"><strong>Deprecated.</strong> <div class='inline'></div></div>


</div>
</div>
<div class="tags">


</div>
</dt>
<dd><pre class="code">2</pre></dd>

</dl>

<h2>
Bar
<small><a href="#" class="constants_summary_toggle">collapse</a></small>
</h2>

<dl class="constants">

<dt id="BAZ-constant" class="">BAZ =

</dt>
<dd><pre class="code">3</pre></dd>

</dl>

<h2>
Constant Summary
<small><a href="#" class="constants_summary_toggle">collapse</a></small>
</h2>

<dl class="constants">

<dt id="WORLD-constant" class="">WORLD =

</dt>
<dd><pre class="code">4</pre></dd>

</dl>
21 changes: 21 additions & 0 deletions spec/templates/module_spec.rb
Expand Up @@ -179,4 +179,25 @@ def baz_abc; end

html_equals(Registry.at('A').format(html_options(:embed_mixins => ['Foo', 'Bar', 'Baz::A*'])), :module004)
end

it "renders constant groups correctly in html" do
Registry.clear
YARD.parse_string <<-'eof'
module A
# @group Foo
FOO = 1

# @deprecated
BAR = 2

# @group Bar
BAZ = 3

# @endgroup

WORLD = 4
end
eof
html_equals(Registry.at('A').format(html_options), :module005)
end
end
9 changes: 3 additions & 6 deletions templates/default/fulldoc/html/css/style.css
Expand Up @@ -245,6 +245,7 @@ ul.toplevel { list-style: none; padding-left: 0; font-size: 1.1em; }

dl.constants { margin-left: 10px; }
dl.constants dt { font-weight: bold; font-size: 1.1em; margin-bottom: 5px; }
dl.constants.compact dt { display: inline-block; font-weight: normal }
dl.constants dd { width: 75%; white-space: pre; font-family: monospace; margin-bottom: 18px; }
dl.constants .docstring .note:first-child { margin-top: 5px; }

Expand Down Expand Up @@ -326,13 +327,9 @@ ul.summary a, ul.summary a:visited {
text-decoration: none; font-size: 1.1em;
}
ul.summary li { margin-bottom: 5px; }
.summary .summary_signature {
padding: 4px 8px;
background: #f8f8f8;
border: 1px solid #f0f0f0;
border-radius: 5px;
}
.summary_signature { padding: 4px 8px; background: #f8f8f8; border: 1px solid #f0f0f0; border-radius: 5px; }
.summary_signature:hover { background: #CFEBFF; border-color: #A4CCDA; cursor: pointer; }
.summary_signature.deprecated { background: #ffe5e5; border-color: #e9dada; }
ul.summary.compact li { display: inline-block; margin: 0px 5px 0px 0px; line-height: 2.6em;}
ul.summary.compact .summary_signature { padding: 5px 7px; padding-right: 4px; }
#content .summary_signature:hover a,
Expand Down
44 changes: 44 additions & 0 deletions templates/default/fulldoc/html/js/app.js
Expand Up @@ -120,6 +120,49 @@ function summaryToggle() {
} else { localStorage.summaryCollapsed = "expand"; }
}

function constantSummaryToggle() {
$('.constants_summary_toggle').click(function(e) {
e.preventDefault();
localStorage.summaryCollapsed = $(this).text();
$('.constants_summary_toggle').each(function() {
$(this).text($(this).text() == "collapse" ? "expand" : "collapse");
var next = $(this).parent().parent().nextAll('dl.constants').first();
if (next.hasClass('compact')) {
next.toggle();
next.nextAll('dl.constants').first().toggle();
}
else if (next.hasClass('constants')) {
var list = $('<dl class="constants compact" />');
list.html(next.html());
list.find('dt').each(function() {
$(this).addClass('summary_signature');
$(this).text( $(this).text().split('=')[0]);
if ($(this).has(".deprecated").length) {
$(this).addClass('deprecated');
};
});
// Add the value of the constant as "Tooltip" to the summary object
list.find('pre.code').each(function() {
console.log($(this).parent());
var dt_element = $(this).parent().prev();
var tooltip = $(this).text();
if (dt_element.hasClass("deprecated")) {
tooltip = 'Deprecated. ' + tooltip;
};
dt_element.attr('title', tooltip);
});
list.find('.docstring, .tags, dd').remove();
next.before(list);
next.toggle();
}
});
return false;
});
if (localStorage.summaryCollapsed == "collapse") {
$('.constants_summary_toggle').first().click();
} else { localStorage.summaryCollapsed = "expand"; }
}

function generateTOC() {
if ($('#filecontents').length === 0) return;
var _toc = $('<ol class="top"></ol>');
Expand Down Expand Up @@ -241,6 +284,7 @@ $(document).ready(function() {
searchFrameButtons();
linkSummaries();
summaryToggle();
constantSummaryToggle();
generateTOC();
mainFocus();
});
Expand Down
24 changes: 15 additions & 9 deletions templates/default/module/html/constant_summary.erb
@@ -1,11 +1,17 @@
<% if constant_listing.size > 0 %>
<h2>Constant Summary</h2>
<dl class="constants">
<% constant_listing.each do |cnst| %>
<dt id="<%= anchor_for(cnst) %>" class="<%= cnst.has_tag?(:deprecated) ? 'deprecated' : '' %>"><%= cnst.name %> =
<%= yieldall :object => cnst %>
</dt>
<dd><pre class="code"><%= format_constant cnst.value %></pre></dd>
<% end %>
</dl>
<% groups(constant_listing, "Constant") do |list, name| %>
<h2>
<%= name %>
<small><a href="#" class="constants_summary_toggle">collapse</a></small>
</h2>

<dl class="constants">
<% list.each do |cnst| %>
<dt id="<%= anchor_for(cnst) %>" class="<%= cnst.has_tag?(:deprecated) ? 'deprecated' : '' %>"><%= cnst.name %> =
<%= yieldall :object => cnst %>
</dt>
<dd><pre class="code"><%= format_constant cnst.value %></pre></dd>
<% end %>
</dl>
<% end %>
<% end %>
15 changes: 10 additions & 5 deletions templates/default/module/setup.rb
Expand Up @@ -131,17 +131,22 @@ def groups(list, type = "Method")
else
others = []
group_data = {}
list.each do |meth|
if meth.group
(group_data[meth.group] ||= []) << meth
list.each do |itm|
if itm.group
(group_data[itm.group] ||= []) << itm
else
others << meth
others << itm
end
end
group_data.each {|group, items| yield(items, group) unless items.empty? }
end

scopes(others) {|items, scope| yield(items, "#{scope.to_s.capitalize} #{type} Summary") }
return if others.empty?
if others.first.respond_to?(:scope)
scopes(others) {|items, scope| yield(items, "#{scope.to_s.capitalize} #{type} Summary") }
else
yield(others, "#{type} Summary")
end
end

def scopes(list)
Expand Down