Class: SM::ToFlow

Inherits:
Object
  • Object
show all
Defined in:
lib/rdoc/markup/simple_markup/to_flow.rb

Defined Under Namespace

Classes: InlineTag

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initializeToFlow

Returns a new instance of ToFlow.



37
38
39
# File 'lib/rdoc/markup/simple_markup/to_flow.rb', line 37

def initialize
  init_tags
end

Instance Method Details

#accept_blank_line(am, fragment) ⇒ Object



111
112
113
# File 'lib/rdoc/markup/simple_markup/to_flow.rb', line 111

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

#accept_heading(am, fragment) ⇒ Object



115
116
117
# File 'lib/rdoc/markup/simple_markup/to_flow.rb', line 115

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



103
104
105
# File 'lib/rdoc/markup/simple_markup/to_flow.rb', line 103

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

#accept_list_item(am, fragment) ⇒ Object



107
108
109
# File 'lib/rdoc/markup/simple_markup/to_flow.rb', line 107

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



96
97
98
99
100
101
# File 'lib/rdoc/markup/simple_markup/to_flow.rb', line 96

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



82
83
84
# File 'lib/rdoc/markup/simple_markup/to_flow.rb', line 82

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

#accept_rule(am, fragment) ⇒ Object



90
91
92
93
94
# File 'lib/rdoc/markup/simple_markup/to_flow.rb', line 90

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

#accept_verbatim(am, fragment) ⇒ Object



86
87
88
# File 'lib/rdoc/markup/simple_markup/to_flow.rb', line 86

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



56
57
58
# File 'lib/rdoc/markup/simple_markup/to_flow.rb', line 56

def add_tag(name, start, stop)
  @attr_tags << InlineTag.new(SM::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



66
67
68
# File 'lib/rdoc/markup/simple_markup/to_flow.rb', line 66

def annotate(tag)
  tag
end

#end_acceptingObject



78
79
80
# File 'lib/rdoc/markup/simple_markup/to_flow.rb', line 78

def end_accepting
  @res
end

#init_tagsObject

Set up the standard mapping of attributes to HTML tags



44
45
46
47
48
49
50
# File 'lib/rdoc/markup/simple_markup/to_flow.rb', line 44

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

#start_acceptingObject

Here's the client side of the visitor pattern



73
74
75
76
# File 'lib/rdoc/markup/simple_markup/to_flow.rb', line 73

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