Class RDoc::Markup::ToFlow
In: markup/to_flow.rb
Parent: RDoc::Markup::Formatter

Methods

Public Class methods

[Source]

    # File markup/to_flow.rb, line 38
38:     def initialize
39:       super
40: 
41:       init_tags
42:     end

Public Instance methods

[Source]

     # File markup/to_flow.rb, line 113
113:     def accept_blank_line(am, fragment)
114:       # @res << annotate("<p />") << "\n"
115:     end

[Source]

     # File markup/to_flow.rb, line 117
117:     def accept_heading(am, fragment)
118:       @res << Flow::H.new(fragment.head_level, convert_flow(am.flow(fragment.txt)))
119:     end

[Source]

     # File markup/to_flow.rb, line 105
105:     def accept_list_end(am, fragment)
106:       @res = @list_stack.pop
107:     end

[Source]

     # File markup/to_flow.rb, line 109
109:     def accept_list_item(am, fragment)
110:       @res << Flow::LI.new(fragment.param, convert_flow(am.flow(fragment.txt)))
111:     end

[Source]

     # File markup/to_flow.rb, line 98
 98:     def accept_list_start(am, fragment)
 99:       @list_stack.push(@res)
100:       list = Flow::LIST.new(fragment.type)
101:       @res << list
102:       @res = list
103:     end

[Source]

    # File markup/to_flow.rb, line 84
84:     def accept_paragraph(am, fragment)
85:       @res << Flow::P.new((convert_flow(am.flow(fragment.txt))))
86:     end

[Source]

    # File markup/to_flow.rb, line 92
92:     def accept_rule(am, fragment)
93:       size = fragment.param
94:       size = 10 if size > 10
95:       @res << Flow::RULE.new(size)
96:     end

[Source]

    # File markup/to_flow.rb, line 88
88:     def accept_verbatim(am, fragment)
89:       @res << Flow::VERB.new((convert_flow(am.flow(fragment.txt))))
90:     end

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

[Source]

    # File markup/to_flow.rb, line 59
59:     def add_tag(name, start, stop)
60:       @attr_tags << InlineTag.new(RDoc::Markup::Attribute.bitmap_for(name), start, stop)
61:     end

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

[Source]

    # File markup/to_flow.rb, line 68
68:     def annotate(tag)
69:       tag
70:     end

[Source]

     # File markup/to_flow.rb, line 145
145:     def convert_flow(flow)
146:       res = ""
147:       flow.each do |item|
148:         case item
149:         when String
150:           res << convert_string(item)
151:         when AttrChanger
152:           off_tags(res, item)
153:           on_tags(res,  item)
154:         when Special
155:           res << convert_special(item)
156:         else
157:           raise "Unknown flow element: #{item.inspect}"
158:         end
159:       end
160:       res
161:     end

[Source]

     # File markup/to_flow.rb, line 167
167:     def convert_special(special)
168:       handled = false
169:       Attribute.each_name_of(special.type) do |name|
170:         method_name = "handle_special_#{name}"
171:         if self.respond_to? method_name
172:           special.text = send(method_name, special)
173:           handled = true
174:         end
175:       end
176: 
177:       raise "Unhandled special: #{special}" unless handled
178: 
179:       special.text
180:     end

[Source]

     # File markup/to_flow.rb, line 163
163:     def convert_string(item)
164:       CGI.escapeHTML(item)
165:     end

[Source]

    # File markup/to_flow.rb, line 80
80:     def end_accepting
81:       @res
82:     end

Set up the standard mapping of attributes to HTML tags

[Source]

    # File markup/to_flow.rb, line 47
47:     def init_tags
48:       @attr_tags = [
49:         InlineTag.new(RDoc::Markup::Attribute.bitmap_for(:BOLD), "<b>", "</b>"),
50:         InlineTag.new(RDoc::Markup::Attribute.bitmap_for(:TT),   "<tt>", "</tt>"),
51:         InlineTag.new(RDoc::Markup::Attribute.bitmap_for(:EM),   "<em>", "</em>"),
52:       ]
53:     end

[Source]

     # File markup/to_flow.rb, line 134
134:     def off_tags(res, item)
135:       attr_mask = item.turn_off
136:       return if attr_mask.zero?
137: 
138:       @attr_tags.reverse_each do |tag|
139:         if attr_mask & tag.bit != 0
140:           res << annotate(tag.off)
141:         end
142:       end
143:     end

[Source]

     # File markup/to_flow.rb, line 123
123:     def on_tags(res, item)
124:       attr_mask = item.turn_on
125:       return if attr_mask.zero?
126: 
127:       @attr_tags.each do |tag|
128:         if attr_mask & tag.bit != 0
129:           res << annotate(tag.on)
130:         end
131:       end
132:     end

Here‘s the client side of the visitor pattern

[Source]

    # File markup/to_flow.rb, line 75
75:     def start_accepting
76:       @res = []
77:       @list_stack = []
78:     end

[Validate]