Class: RDoc::RI::HtmlFormatter

Inherits:
AttributeFormatter show all
Defined in:
lib/rdoc/ri/formatter.rb

Overview

This formatter uses HTML.

Constant Summary

Constants inherited from AttributeFormatter

AttributeFormatter::BOLD, AttributeFormatter::CODE, AttributeFormatter::ITALIC

Constants inherited from Formatter

Formatter::FORMATTERS

Instance Attribute Summary

Attributes inherited from Formatter

#indent, #output

Instance Method Summary collapse

Methods inherited from AttributeFormatter

#wrap

Methods inherited from Formatter

#conv_html, #conv_markup, #display_flow, #display_flow_item, for, #initialize, list, #raw_print_line, #strip_attributes, #wrap

Constructor Details

This class inherits a constructor from RDoc::RI::Formatter

Instance Method Details

#blanklineObject



470
471
472
# File 'lib/rdoc/ri/formatter.rb', line 470

def blankline()
  @output.puts("<p>")
end

#bold_print(txt) ⇒ Object



466
467
468
# File 'lib/rdoc/ri/formatter.rb', line 466

def bold_print(txt)
  tag("b") { txt }
end

#break_to_newlineObject



474
475
476
# File 'lib/rdoc/ri/formatter.rb', line 474

def break_to_newline
  @output.puts("<br>")
end

#display_heading(text, level, indent) ⇒ Object



478
479
480
481
482
# File 'lib/rdoc/ri/formatter.rb', line 478

def display_heading(text, level, indent)
  level = 4 if level > 4
  tag("h#{level}") { text }
  @output.puts
end

#display_list(list) ⇒ Object



484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/rdoc/ri/formatter.rb', line 484

def display_list(list)
  case list.type
  when :BULLET then
    list_type = "ul"
    prefixer = proc { |ignored| "<li>" }

  when :NUMBER, :UPPERALPHA, :LOWERALPHA then
    list_type = "ol"
    prefixer = proc { |ignored| "<li>" }

  when :LABELED then
    list_type = "dl"
    prefixer = proc do |li|
      "<dt><b>" + escape(li.label) + "</b><dd>"
    end

  when :NOTE then
    list_type = "table"
    prefixer = proc do |li|
      %{<tr valign="top"><td>#{li.label.gsub(/ /, '&nbsp;')}</td><td>}
    end
  else
    fail "unknown list type"
  end

  @output.print "<#{list_type}>"
  list.contents.each do |item|
    if item.kind_of? RDoc::Markup::Flow::LI
      prefix = prefixer.call(item)
      @output.print prefix
      display_flow_item(item, prefix)
    else
      display_flow_item(item)
    end
  end
  @output.print "</#{list_type}>"
end

#display_verbatim_flow_item(item, prefix = @indent) ⇒ Object



522
523
524
525
526
527
528
# File 'lib/rdoc/ri/formatter.rb', line 522

def display_verbatim_flow_item(item, prefix=@indent)
  @output.print("<pre>")
  item.body.split(/\n/).each do |line|
    @output.puts conv_html(line)
  end
  @output.puts("</pre>")
end

#draw_line(label = nil) ⇒ Object



459
460
461
462
463
464
# File 'lib/rdoc/ri/formatter.rb', line 459

def draw_line(label=nil)
  if label != nil
    bold_print(label)
  end
  @output.puts("<hr>")
end

#write_attribute_text(prefix, line) ⇒ Object



446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/rdoc/ri/formatter.rb', line 446

def write_attribute_text(prefix, line)
  curr_attr = 0
  line.each do |achar|
    attr = achar.attr
    if achar.attr != curr_attr
      update_attributes(curr_attr, achar.attr)
      curr_attr = achar.attr
    end
    @output.print(escape(achar.char))
  end
  update_attributes(curr_attr, 0) unless curr_attr.zero?
end