Class: RDocF95::Markup::ToFlow

Inherits:
Formatter show all
Defined in:
lib/rdoc-f95/markup/to_flow.rb

Defined Under Namespace

Classes: InlineTag

Constant Summary collapse

LIST_TYPE_TO_HTML =
{
  :BULLET     =>  [ "<ul>", "</ul>" ],
  :NUMBER     =>  [ "<ol>", "</ol>" ],
  :UPPERALPHA =>  [ "<ol>", "</ol>" ],
  :LOWERALPHA =>  [ "<ol>", "</ol>" ],
  :LABELED    =>  [ "<dl>", "</dl>" ],
  :NOTE       =>  [ "<table>", "</table>" ],
}

Instance Method Summary collapse

Methods inherited from Formatter

#convert

Constructor Details

#initializeToFlow

Returns a new instance of ToFlow.



38
39
40
41
42
# File 'lib/rdoc-f95/markup/to_flow.rb', line 38

def initialize
  super

  init_tags
end

Instance Method Details

#accept_blank_line(am, fragment) ⇒ Object



113
114
115
# File 'lib/rdoc-f95/markup/to_flow.rb', line 113

def accept_blank_line(am, fragment)
  # @res << annotate("<p />") << "\n"
end

#accept_heading(am, fragment) ⇒ Object



117
118
119
# File 'lib/rdoc-f95/markup/to_flow.rb', line 117

def accept_heading(am, fragment)
  @res << Flow::H.new(fragment.head_level, convert_flow(am.flow(fragment.txt)))
end

#accept_list_end(am, fragment) ⇒ Object



105
106
107
# File 'lib/rdoc-f95/markup/to_flow.rb', line 105

def accept_list_end(am, fragment)
  @res = @list_stack.pop
end

#accept_list_item(am, fragment) ⇒ Object



109
110
111
# File 'lib/rdoc-f95/markup/to_flow.rb', line 109

def accept_list_item(am, fragment)
  @res << Flow::LI.new(fragment.param, convert_flow(am.flow(fragment.txt)))
end

#accept_list_start(am, fragment) ⇒ Object



98
99
100
101
102
103
# File 'lib/rdoc-f95/markup/to_flow.rb', line 98

def accept_list_start(am, fragment)
  @list_stack.push(@res)
  list = Flow::LIST.new(fragment.type)
  @res << list
  @res = list
end

#accept_paragraph(am, fragment) ⇒ Object



84
85
86
# File 'lib/rdoc-f95/markup/to_flow.rb', line 84

def accept_paragraph(am, fragment)
  @res << Flow::P.new((convert_flow(am.flow(fragment.txt))))
end

#accept_rule(am, fragment) ⇒ Object



92
93
94
95
96
# File 'lib/rdoc-f95/markup/to_flow.rb', line 92

def accept_rule(am, fragment)
  size = fragment.param
  size = 10 if size > 10
  @res << Flow::RULE.new(size)
end

#accept_verbatim(am, fragment) ⇒ Object



88
89
90
# File 'lib/rdoc-f95/markup/to_flow.rb', line 88

def accept_verbatim(am, fragment)
  @res << Flow::VERB.new((convert_flow(am.flow(fragment.txt))))
end

#add_tag(name, start, stop) ⇒ Object

Add a new set of HTML tags for an attribute. We allow separate start and end tags for flexibility



59
60
61
# File 'lib/rdoc-f95/markup/to_flow.rb', line 59

def add_tag(name, start, stop)
  @attr_tags << InlineTag.new(RDocF95::Markup::Attribute.bitmap_for(name), start, stop)
end

#annotate(tag) ⇒ Object

Given an HTML tag, decorate it with class information and the like if required. This is a no-op in the base class, but is overridden in HTML output classes that implement style sheets



68
69
70
# File 'lib/rdoc-f95/markup/to_flow.rb', line 68

def annotate(tag)
  tag
end

#end_acceptingObject



80
81
82
# File 'lib/rdoc-f95/markup/to_flow.rb', line 80

def end_accepting
  @res
end

#init_tagsObject

Set up the standard mapping of attributes to HTML tags



47
48
49
50
51
52
53
# File 'lib/rdoc-f95/markup/to_flow.rb', line 47

def init_tags
  @attr_tags = [
    InlineTag.new(RDocF95::Markup::Attribute.bitmap_for(:BOLD), "<b>", "</b>"),
    InlineTag.new(RDocF95::Markup::Attribute.bitmap_for(:TT),   "<tt>", "</tt>"),
    InlineTag.new(RDocF95::Markup::Attribute.bitmap_for(:EM),   "<em>", "</em>"),
  ]
end

#start_acceptingObject

Here’s the client side of the visitor pattern



75
76
77
78
# File 'lib/rdoc-f95/markup/to_flow.rb', line 75

def start_accepting
  @res = []
  @list_stack = []
end