From b84aac60a2667440ce1b568db99db4ae01e6d395 Mon Sep 17 00:00:00 2001 From: Holger Arndt Date: Wed, 14 Mar 2018 14:19:49 +0100 Subject: [PATCH 1/4] Enable groups for constants (Resolves #610) --- templates/default/fulldoc/html/css/style.css | 8 ++--- templates/default/fulldoc/html/js/app.js | 36 +++++++++++++++++++ .../default/module/html/constant_summary.erb | 24 ++++++++----- templates/default/module/setup.rb | 15 +++++--- 4 files changed, 63 insertions(+), 20 deletions(-) diff --git a/templates/default/fulldoc/html/css/style.css b/templates/default/fulldoc/html/css/style.css index c9ec84a3f..b643b7854 100644 --- a/templates/default/fulldoc/html/css/style.css +++ b/templates/default/fulldoc/html/css/style.css @@ -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; } @@ -326,12 +327,7 @@ 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; } 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; } diff --git a/templates/default/fulldoc/html/js/app.js b/templates/default/fulldoc/html/js/app.js index b9f21202a..b20658c23 100644 --- a/templates/default/fulldoc/html/js/app.js +++ b/templates/default/fulldoc/html/js/app.js @@ -120,6 +120,41 @@ 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 = $('
'); + list.html(next.html()); + list.find('dt').each(function() { + $(this).addClass('summary_signature'); + $(this).text($(this).text().split('=')[0]); + }); + // Add the value of the constant as "Tooltip" to the summary object + list.find('pre.code').each(function() { + console.log($(this).parent()); + $(this).parent().prev().attr('title', $(this).text()); + }); + 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 = $('
    '); @@ -241,6 +276,7 @@ $(document).ready(function() { searchFrameButtons(); linkSummaries(); summaryToggle(); + constantSummaryToggle(); generateTOC(); mainFocus(); }); diff --git a/templates/default/module/html/constant_summary.erb b/templates/default/module/html/constant_summary.erb index 57ed3e927..46f7ef861 100644 --- a/templates/default/module/html/constant_summary.erb +++ b/templates/default/module/html/constant_summary.erb @@ -1,11 +1,17 @@ <% if constant_listing.size > 0 %> -

    Constant Summary

    -
    - <% constant_listing.each do |cnst| %> -
    <%= cnst.name %> = - <%= yieldall :object => cnst %> -
    -
    <%= format_constant cnst.value %>
    - <% end %> -
    + <% groups(constant_listing, "Constant") do |list, name| %> +

    + <%= name %> + collapse +

    + +
    + <% list.each do |cnst| %> +
    <%= cnst.name %> = + <%= yieldall :object => cnst %> +
    +
    <%= format_constant cnst.value %>
    + <% end %> +
    + <% end %> <% end %> diff --git a/templates/default/module/setup.rb b/templates/default/module/setup.rb index d93d17b89..95bf3a4bb 100644 --- a/templates/default/module/setup.rb +++ b/templates/default/module/setup.rb @@ -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) From 7aaadcfdfe56bc6c9c7f4bcd54524b3121384b02 Mon Sep 17 00:00:00 2001 From: Holger Arndt Date: Wed, 14 Mar 2018 14:33:54 +0100 Subject: [PATCH 2/4] Fix failing test --- spec/templates/examples/module001.html | 6 +++++- spec/templates/examples/module003.html | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/spec/templates/examples/module001.html b/spec/templates/examples/module001.html index 968058b72..8c8d72d7d 100644 --- a/spec/templates/examples/module001.html +++ b/spec/templates/examples/module001.html @@ -54,7 +54,11 @@

    Overview

    -

    Constant Summary

    +

    + Constant Summary + + collapse +

    diff --git a/spec/templates/examples/module003.html b/spec/templates/examples/module003.html index 7d20cc538..3b8adbfc5 100644 --- a/spec/templates/examples/module003.html +++ b/spec/templates/examples/module003.html @@ -28,7 +28,11 @@

    Module: A

    -

    Constant Summary

    +

    + Constant Summary + + collapse +

    From 725257cb83321f536be093d16a691914c93eb629 Mon Sep 17 00:00:00 2001 From: Holger Arndt Date: Wed, 14 Mar 2018 14:51:58 +0100 Subject: [PATCH 3/4] Add test for grouped constants --- spec/templates/examples/module005.html | 72 ++++++++++++++++++++++++++ spec/templates/module_spec.rb | 19 +++++++ 2 files changed, 91 insertions(+) create mode 100644 spec/templates/examples/module005.html diff --git a/spec/templates/examples/module005.html b/spec/templates/examples/module005.html new file mode 100644 index 000000000..bbd868613 --- /dev/null +++ b/spec/templates/examples/module005.html @@ -0,0 +1,72 @@ +

    Module: A + + + +

    +
    + + + + + + + + + + + +
    +
    Defined in:
    +
    (stdin)
    +
    + +
    + + + +

    + Foo + collapse +

    + +
    + +
    FOO = + +
    +
    1
    + +
    BAR = + +
    +
    2
    + +
    + +

    + Bar + collapse +

    + +
    + +
    BAZ = + +
    +
    3
    + +
    + +

    + Constant Summary + collapse +

    + +
    + +
    WORLD = + +
    +
    4
    + +
    \ No newline at end of file diff --git a/spec/templates/module_spec.rb b/spec/templates/module_spec.rb index 531e93a31..d80f49590 100644 --- a/spec/templates/module_spec.rb +++ b/spec/templates/module_spec.rb @@ -179,4 +179,23 @@ 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 + BAR = 2 + + # @group Bar + BAZ = 3 + + # @endgroup + + WORLD = 4 + end + eof + html_equals(Registry.at('A').format(html_options), :module005) + end end From 9944dd474a59dfb52a42b440d3daf398fe59a9af Mon Sep 17 00:00:00 2001 From: Holger Arndt Date: Thu, 15 Mar 2018 08:26:31 +0100 Subject: [PATCH 4/4] Color deprecated collapsed constants red and extend the tooltip --- spec/templates/examples/module005.html | 12 +++++++++++- spec/templates/module_spec.rb | 2 ++ templates/default/fulldoc/html/css/style.css | 1 + templates/default/fulldoc/html/js/app.js | 14 +++++++++++--- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/spec/templates/examples/module005.html b/spec/templates/examples/module005.html index bbd868613..eae58e369 100644 --- a/spec/templates/examples/module005.html +++ b/spec/templates/examples/module005.html @@ -36,8 +36,18 @@

    1
    -
    BAR = +
    BAR = +
    +
    +
    Deprecated.
    + +
    +
    +
    + + +
    2
    diff --git a/spec/templates/module_spec.rb b/spec/templates/module_spec.rb index d80f49590..416008249 100644 --- a/spec/templates/module_spec.rb +++ b/spec/templates/module_spec.rb @@ -186,6 +186,8 @@ def baz_abc; end module A # @group Foo FOO = 1 + + # @deprecated BAR = 2 # @group Bar diff --git a/templates/default/fulldoc/html/css/style.css b/templates/default/fulldoc/html/css/style.css index b643b7854..0bf7e2c73 100644 --- a/templates/default/fulldoc/html/css/style.css +++ b/templates/default/fulldoc/html/css/style.css @@ -329,6 +329,7 @@ ul.summary a, ul.summary a:visited { ul.summary li { margin-bottom: 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, diff --git a/templates/default/fulldoc/html/js/app.js b/templates/default/fulldoc/html/js/app.js index b20658c23..fecf69db3 100644 --- a/templates/default/fulldoc/html/js/app.js +++ b/templates/default/fulldoc/html/js/app.js @@ -135,13 +135,21 @@ function constantSummaryToggle() { var list = $('
    '); list.html(next.html()); list.find('dt').each(function() { - $(this).addClass('summary_signature'); - $(this).text($(this).text().split('=')[0]); + $(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()); - $(this).parent().prev().attr('title', $(this).text()); + 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);