Skip to content

Commit

Permalink
Pretty-print constants in classes and modules
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Nov 17, 2012
1 parent 534455b commit c188290
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
18 changes: 18 additions & 0 deletions lib/rdoc/constant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ def documented?
super or is_alias_for && is_alias_for.documented?
end

##
# Full constant name including namespace

def full_name
@full_name ||= "#{parent_name}::#{@name}"
end

def inspect # :nodoc:
"#<%s:0x%x %s::%s>" % [
self.class, object_id,
Expand All @@ -71,6 +78,17 @@ def path
"#{@parent.path}##{@name}"
end

def pretty_print q # :nodoc:
q.group 2, "[#{self.class.name} #{full_name}", "]" do
unless comment.empty? then
q.breakable
q.text "comment:"
q.breakable
q.pp @comment
end
end
end

##
# Sets the store for this class or module and its contained code objects.

Expand Down
4 changes: 2 additions & 2 deletions lib/rdoc/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,9 @@ def each_section # :yields: section, constants, attributes
return enum_for __method__ unless block_given?

constants = @constants.group_by do |constant| constant.section end
constants.default = []

attributes = @attributes.group_by do |attribute| attribute.section end

constants.default = []
attributes.default = []

sort_sections.each do |section|
Expand Down
11 changes: 8 additions & 3 deletions lib/rdoc/normal_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,25 @@ def pretty_print q # :nodoc:
q.breakable
q.seplist @includes do |inc| q.pp inc end

q.breakable
q.text "constants:"
q.breakable
q.seplist @constants do |const| q.pp const end

q.breakable
q.text "attributes:"
q.breakable
q.seplist @attributes do |inc| q.pp inc end
q.seplist @attributes do |attr| q.pp attr end

q.breakable
q.text "methods:"
q.breakable
q.seplist @method_list do |inc| q.pp inc end
q.seplist @method_list do |meth| q.pp meth end

q.breakable
q.text "aliases:"
q.breakable
q.seplist @aliases do |inc| q.pp inc end
q.seplist @aliases do |aliaz| q.pp aliaz end

q.breakable
q.text "comment:"
Expand Down
11 changes: 8 additions & 3 deletions lib/rdoc/normal_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,24 @@ def pretty_print q # :nodoc:
q.seplist @includes do |inc| q.pp inc end
q.breakable

q.breakable
q.text "constants:"
q.breakable
q.seplist @constants do |const| q.pp const end

q.text "attributes:"
q.breakable
q.seplist @attributes do |inc| q.pp inc end
q.seplist @attributes do |attr| q.pp attr end
q.breakable

q.text "methods:"
q.breakable
q.seplist @method_list do |inc| q.pp inc end
q.seplist @method_list do |meth| q.pp meth end
q.breakable

q.text "aliases:"
q.breakable
q.seplist @aliases do |inc| q.pp inc end
q.seplist @aliases do |aliaz| q.pp aliaz end
q.breakable

q.text "comment:"
Expand Down
4 changes: 4 additions & 0 deletions test/test_rdoc_constant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def setup
@const = @c1.constants.first
end

def test_full_name
assert_equal 'C1::CONST', @const.full_name
end

def test_path
assert_equal 'C1.html#CONST', @const.path
end
Expand Down

0 comments on commit c188290

Please sign in to comment.