Class: Ruber::RI::ClassFormatter

Inherits:
Object
  • Object
show all
Defined in:
plugins/ruberri/class_formatter.rb

Instance Method Summary (collapse)

Constructor Details

- (ClassFormatter) initialize(cls, store, store_type)

A new instance of ClassFormatter



32
33
34
35
# File 'plugins/ruberri/class_formatter.rb', line 32

def initialize cls, store, store_type
  @store = RDoc::RI::Store.new store, store_type
  @cls = @store.load_class cls
end

Instance Method Details

- (Object) format_class_methods (private)



78
79
80
81
82
83
84
85
86
87
88
89
# File 'plugins/ruberri/class_formatter.rb', line 78

def format_class_methods
  methods = @cls.method_list.reject{|m| m.full_name.include? '#'}
  unless methods.empty?
    res = []
    res << RDoc::Markup::Heading.new(2, "Class methods")
    method_list = methods.map do |m|
      RDoc::Markup::ListItem.new nil, RDoc::Markup::Verbatim.new(m.name)
    end
    res << RDoc::Markup::List.new(:BULLET, *method_list)
    res
  end
end

- (Object) format_constants (private)



104
105
106
107
108
109
110
111
112
113
114
115
# File 'plugins/ruberri/class_formatter.rb', line 104

def format_constants
  return if @cls.constants.empty?
  res = []
  res << RDoc::Markup::Heading.new(2, "Constants defined in this #{@cls.type}")
  last = @cls.constants.count - 1
  @cls.constants.each_with_index do |c, i|
    res << RDoc::Markup::Heading.new(3, "<tt>#{c.name}</tt>")
    res << c.comment
    
  end
  res
end

- (Object) format_included (private)



66
67
68
69
70
71
72
73
74
75
76
# File 'plugins/ruberri/class_formatter.rb', line 66

def format_included
  included = @cls.includes
  unless included.empty?
    res = []
    res << RDoc::Markup::Heading.new(2, "Included modules")
    list = RDoc::Markup::List.new :BULLET
    @cls.includes.each{|i| list << RDoc::Markup::ListItem.new(nil, RDoc::Markup::Paragraph.new(i.module.to_s) )}
    res << list
    res
  end
end

- (Object) format_instance_methods (private)



91
92
93
94
95
96
97
98
99
100
101
102
# File 'plugins/ruberri/class_formatter.rb', line 91

def format_instance_methods
  methods = @cls.method_list.select{|m| m.full_name.include? '#'}
  unless methods.empty?
    res = []
    res << RDoc::Markup::Heading.new(2, "Instance methods")
    method_list = methods.map do |m| 
      RDoc::Markup::ListItem.new nil, RDoc::Markup::Verbatim.new(m.name)
    end
    res << RDoc::Markup::List.new(:BULLET, *method_list)
    res
  end
end

- (Object) to_html



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'plugins/ruberri/class_formatter.rb', line 37

def to_html
  superclass = @cls.superclass if @cls.type == :class
  if superclass and superclass != 'Object'
    superclass = " < #{superclass}"
  elsif superclass == 'Object' then superclass = ''
  end
  title = "#{@cls.type.capitalize} #{@cls.full_name}#{superclass}"
  title << " (from #{@store.friendly_path})" unless @store.friendly_path =~ /ruby core/
  parts = [RDoc::Markup::Heading.new(1, title)]
  parts << format_included
  parts << @cls.comment
  parts << format_constants
  parts << format_class_methods
  parts << format_instance_methods
  parts.compact!
  doc = RDoc::Markup::Document.new
  last = parts.count - 1
  parts.each_with_index do |prt, i|
    if prt.is_a? Array then prt.each{|x| doc << x}
    else doc << prt
    end
    doc << RDoc::Markup::Rule.new(1) unless i == last
  end
  formatter = RDoc::Markup::ToHtml.new
  doc.accept formatter
end