Class: Ruber::RI::MethodFormatter

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

Instance Method Summary (collapse)

Constructor Details

- (MethodFormatter) initialize(method, store, store_type)

A new instance of MethodFormatter



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

def initialize method, store, store_type
  @store = RDoc::RI::Store.new store, store_type
  cls= method.split(/(?:::)|#/, 2)[0]
  @method = @store.load_method cls, method
end

Instance Method Details

- (Object) format_aliases (private)



70
71
72
73
74
75
76
77
78
79
# File 'plugins/ruberri/method_formatter.rb', line 70

def format_aliases
  return if @method.aliases.empty?
  res = [RDoc::Markup::Heading.new(1, 'Also known as')]
  items = @method.aliases.map do |a|
    RDoc::Markup::ListItem.new nil, RDoc::Markup::Paragraph.new(a)
  end
  list = RDoc::Markup::List.new :BULLET, *items
  res << list
  res
end

- (Object) format_arglists (private)



60
61
62
63
64
65
66
67
68
# File 'plugins/ruberri/method_formatter.rb', line 60

def format_arglists
  return unless @method.arglists
  res = []
  arglists = @method.arglists.chomp.split("\n")
  arglists.each do |l|
    res << RDoc::Markup::Verbatim.new(l)
  end
  res
end

- (Object) to_html



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'plugins/ruberri/method_formatter.rb', line 38

def to_html
  title = "#{@method.full_name}"
  title << " (from #{@store.friendly_path})" unless @store.friendly_path =~ /ruby core/
  parts = [RDoc::Markup::Heading.new(1, title)]
  parts << format_aliases
  parts << format_arglists
  parts << @method.comment
  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