Skip to content

Commit

Permalink
Merge pull request ruby#502 from aycabta/each_section-returns-only-di…
Browse files Browse the repository at this point in the history
…splayed-items

Context#each_section yields only #display? items
  • Loading branch information
hsbt committed Aug 29, 2017
2 parents 17ae77a + 768285e commit 4a3374e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/rdoc/context.rb
Expand Up @@ -762,7 +762,7 @@ def each_section # :yields: section, constants, attributes
attributes.default = []

sort_sections.each do |section|
yield section, constants[section].sort, attributes[section].sort
yield section, constants[section].select(&:display?).sort, attributes[section].select(&:display?).sort
end
end

Expand Down
2 changes: 0 additions & 2 deletions lib/rdoc/generator/template/darkfish/class.rhtml
Expand Up @@ -26,8 +26,6 @@
</section>

<% klass.each_section do |section, constants, attributes| %>
<% constants = constants.select { |const| const.display? } %>
<% attributes = attributes.select { |attr| attr.display? } %>
<section id="<%= section.aref %>" class="documentation-section">
<% if section.title then %>
<header class="documentation-section-title">
Expand Down
26 changes: 26 additions & 0 deletions test/test_rdoc_context.rb
Expand Up @@ -481,6 +481,32 @@ def test_each_section
assert_equal expected_attrs, attrs
end

def test_each_section_only_display
sects = []
consts = []
attrs = []

@c7.each_section do |section, constants, attributes|
sects << section
consts << constants
attrs << attributes
end

assert_equal [nil], sects.map { |section| section.title }

expected_consts = [
@c7.constants.select(&:display?).sort
]

assert_equal expected_consts, consts

expected_attrs = [
@c7.attributes.select(&:display?).sort
]

assert_equal expected_attrs, attrs
end

def test_each_section_enumerator
assert_kind_of Enumerator, @c1.each_section
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_rdoc_store.rb
Expand Up @@ -162,7 +162,7 @@ def test_add_file_relative

def test_all_classes_and_modules
expected = %w[
C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 C6
C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 C6 C7
Child
M1 M1::M2
Parent
Expand Down Expand Up @@ -213,7 +213,7 @@ def test_class_path

def test_classes
expected = %w[
C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 C6
C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 C6 C7
Child
Parent
]
Expand Down
12 changes: 12 additions & 0 deletions test/xref_data.rb
Expand Up @@ -82,6 +82,18 @@ def prot5() end
def prot6() end
end
class C7
attr_reader :attr_reader
attr_reader :attr_reader_nodoc # :nodoc:
attr_writer :attr_writer
attr_writer :attr_writer_nodoc # :nodoc:
attr_accessor :attr_accessor
attr_accessor :attr_accessor_nodoc # :nodoc:
CONST = :const
CONST_NODOC = :const_nodoc # :nodoc:
end
module M1
def m
end
Expand Down
1 change: 1 addition & 0 deletions test/xref_test_case.rb
Expand Up @@ -52,6 +52,7 @@ def generator.file_dir() nil end
@c3_h1 = @xref_data.find_module_named 'C3::H1'
@c3_h2 = @xref_data.find_module_named 'C3::H2'
@c6 = @xref_data.find_module_named 'C6'
@c7 = @xref_data.find_module_named 'C7'

@m1 = @xref_data.find_module_named 'M1'
@m1_m = @m1.method_list.first
Expand Down

0 comments on commit 4a3374e

Please sign in to comment.