Class: RI::HtmlFormatter

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

Overview

This formatter uses HTML.

Constant Summary collapse

ATTR_MAP =
{
  BOLD   => "b>",
  ITALIC => "i>",
  CODE   => "tt>"
}

Constants inherited from AttributeFormatter

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

Constants inherited from TextFormatter

TextFormatter::FORMATTERS

Instance Attribute Summary

Attributes inherited from TextFormatter

#indent

Instance Method Summary collapse

Methods inherited from AttributeFormatter

#wrap

Methods inherited from TextFormatter

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

Constructor Details

#initialize(*args) ⇒ HtmlFormatter

Returns a new instance of HtmlFormatter.



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

def initialize(*args)
  super
end

Instance Method Details

#blanklineObject



498
499
500
# File 'lib/rdoc/ri/ri_formatter.rb', line 498

def blankline()
  puts("<p>")
end

#bold_print(txt) ⇒ Object



494
495
496
# File 'lib/rdoc/ri/ri_formatter.rb', line 494

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

#break_to_newlineObject



502
503
504
# File 'lib/rdoc/ri/ri_formatter.rb', line 502

def break_to_newline
  puts("<br>")
end

#display_heading(text, level, indent) ⇒ Object



506
507
508
509
510
# File 'lib/rdoc/ri/ri_formatter.rb', line 506

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

#display_list(list) ⇒ Object

####################################################################



514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/rdoc/ri/ri_formatter.rb', line 514

def display_list(list)

  case list.type
  when SM::ListBase::BULLET 
    list_type = "ul"
    prefixer = proc { |ignored| "<li>" }

  when SM::ListBase::NUMBER,
  SM::ListBase::UPPERALPHA,
  SM::ListBase::LOWERALPHA
    list_type = "ol"
    prefixer = proc { |ignored| "<li>" }
    
  when SM::ListBase::LABELED
    list_type = "dl"
    prefixer = proc do |li|
      "<dt><b>" + escape(li.label) + "</b><dd>"
    end

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

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

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



555
556
557
558
559
# File 'lib/rdoc/ri/ri_formatter.rb', line 555

def display_verbatim_flow_item(item, prefix=@indent)
    print("<pre>")
    puts item.body
    puts("</pre>")
end

#draw_line(label = nil) ⇒ Object



487
488
489
490
491
492
# File 'lib/rdoc/ri/ri_formatter.rb', line 487

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

#write_attribute_text(prefix, line) ⇒ Object



474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/rdoc/ri/ri_formatter.rb', line 474

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
    print(escape(achar.char))
  end
  update_attributes(curr_attr, 0) unless curr_attr.zero?
end