Skip to content

Commit

Permalink
Enable groups for constants (Resolves #610)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kjarrigan committed Jan 12, 2017
1 parent ea6ed94 commit cdc8678
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
7 changes: 7 additions & 0 deletions lib/yard/code_objects/constant_object.rb
Expand Up @@ -12,5 +12,12 @@ class ConstantObject < Base
def value=(value)
@value = format_source(value)
end

# The scope of the constants is always +:class+
#
# @return [Symbol] +:class+
def scope
:class
end
end
end
33 changes: 33 additions & 0 deletions templates/default/fulldoc/html/js/app.js
Expand Up @@ -120,6 +120,38 @@ function summaryToggle() {
} else { localStorage.summaryCollapsed = "expand"; }
}

function summaryToggleConst() {
$('.summary_const_toggle').click(function(e) {
e.preventDefault();
localStorage.summaryCollapsed = $(this).text();
$('.summary_const_toggle').each(function() {
$(this).text($(this).text() == "collapse" ? "expand" : "collapse");
var next = $(this).parent().parent().nextAll('dl.summary').first();
if (next.hasClass('compact')) {
next.toggle();
next.nextAll('dl.summary').first().toggle();
}
else if (next.hasClass('summary')) {
var list = $('<dl class="constants summary compact" />');
list.html(next.html());
list.find('.docstring').remove();
list.find('.tags').remove();
list.find('dd').remove();
list.find('a').each(function() {
$(this).html($(this).find('strong').html());
$(this).parent().html($(this)[0].outerHTML);
});
next.before(list);
next.toggle();
}
});
return false;
});
if (localStorage.summaryCollapsed == "collapse") {
$('.summary_const_toggle').first().click();
} else { localStorage.summaryCollapsed = "expand"; }
}

function generateTOC() {
if ($('#filecontents').length === 0) return;
var _toc = $('<ol class="top"></ol>');
Expand Down Expand Up @@ -236,6 +268,7 @@ $(document).ready(function() {
searchFrameButtons();
linkSummaries();
summaryToggle();
summaryToggleConst();
generateTOC();
mainFocus();
});
Expand Down
24 changes: 16 additions & 8 deletions templates/default/module/html/constant_summary.erb
@@ -1,11 +1,19 @@
<% 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="summary_const_toggle">collapse</a></small>
</h2>

<dl class="constants summary">
<% 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 %>

0 comments on commit cdc8678

Please sign in to comment.