Class: Rabbit::Parser::RD::RD2RabbitVisitor
- Inherits:
-
Visitor
- Object
- RD::RDVisitor
- Visitor
- Rabbit::Parser::RD::RD2RabbitVisitor
show all
- Extended by:
- Forwardable
- Includes:
- RD::MethodParse, Element, PauseSupport
- Defined in:
- lib/rabbit/parser/rd/rd2rabbit-lib.rb
Constant Summary
collapse
- SYSTEM_NAME =
"RD2RabbitLVisitor"
- SYSTEM_VERSION =
"0.0.2"
- VERSION =
::RD::Version.new_from_version_string(SYSTEM_NAME,
SYSTEM_VERSION)
- OUTPUT_SUFFIX =
""
- INCLUDE_SUFFIX =
["rabbit", "rb"]
- EXTENSIONS =
{
"refer" => Ext::Refer,
"inline_verbatim" => Ext::InlineVerbatim,
"block_verbatim" => Ext::BlockVerbatim,
}
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#apply_to_Code(element, content) ⇒ Object
-
#apply_to_DescList(element, items) ⇒ Object
-
#apply_to_DescListItem(element, term, description) ⇒ Object
-
#apply_to_DocumentElement(element, contents) ⇒ Object
-
#apply_to_Emphasis(element, content) ⇒ Object
-
#apply_to_EnumList(element, items) ⇒ Object
-
#apply_to_EnumListItem(element, content) ⇒ Object
-
#apply_to_Footnote(element, content) ⇒ Object
-
#apply_to_Foottext(element, content) ⇒ Object
-
#apply_to_Headline(element, title) ⇒ Object
-
#apply_to_Include(element) ⇒ Object
-
#apply_to_Index(element, content) ⇒ Object
-
#apply_to_ItemList(element, items) ⇒ Object
-
#apply_to_ItemListItem(element, content) ⇒ Object
-
#apply_to_Keyboard(element, content) ⇒ Object
-
#apply_to_List(element, items, klass) ⇒ Object
-
#apply_to_ListItem(element, contents, item) ⇒ Object
-
#apply_to_MethodList(element, items) ⇒ Object
-
#apply_to_MethodListItem(element, term, description) ⇒ Object
-
#apply_to_Reference_with_RDLabel(element, content) ⇒ Object
-
#apply_to_Reference_with_URL(element, content) ⇒ Object
-
#apply_to_String(str) ⇒ Object
-
#apply_to_StringElement(element) ⇒ Object
-
#apply_to_TextBlock(element, content) ⇒ Object
-
#apply_to_Var(element, content) ⇒ Object
-
#apply_to_Verb(element) ⇒ Object
-
#apply_to_Verbatim(element) ⇒ Object
-
#create_have_text_element(klass, content) ⇒ Object
-
#current_body ⇒ Object
-
#initialize(canvas, progress) ⇒ RD2RabbitVisitor
constructor
A new instance of RD2RabbitVisitor.
-
#visit(tree) ⇒ Object
#burn_out_pause_targets, #pause_targets, #register_pause, #unregister_pause
Methods inherited from Visitor
version
Constructor Details
Returns a new instance of RD2RabbitVisitor.
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 60
def initialize(canvas, progress)
@canvas = canvas
@progress = progress
@slides = []
@slide = nil
@slide_property_mode = false
@index = {}
init_extensions
super()
end
|
Instance Attribute Details
#canvas ⇒ Object
Returns the value of attribute canvas.
58
59
60
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 58
def canvas
@canvas
end
|
#progress ⇒ Object
Returns the value of attribute progress.
59
60
61
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 59
def progress
@progress
end
|
Instance Method Details
#apply_to_Code(element, content) ⇒ Object
246
247
248
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 246
def apply_to_Code(element, content)
Code.new(content)
end
|
#apply_to_DescList(element, items) ⇒ Object
175
176
177
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 175
def apply_to_DescList(element, items)
apply_to_List(element, items, DescriptionList)
end
|
#apply_to_DescListItem(element, term, description) ⇒ Object
#apply_to_DocumentElement(element, contents) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 79
def apply_to_DocumentElement(element, contents)
target = nil
mode = :ignore
contents.each do |content|
case content
when :no_element
next
when nil
mode = :ignore
when Slide
target = content.body
@canvas << content
mode = :display
when TitleSlide
target = content
@canvas << content
mode = :display
when SlidePropertySetter, NoteSetter
target = content
mode = :property
else
case mode
when :display
target << content
when :property
target.apply(content)
end
end
end
burn_out_pause_targets
end
|
#apply_to_Emphasis(element, content) ⇒ Object
242
243
244
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 242
def apply_to_Emphasis(element, content)
Emphasis.new(content)
end
|
#apply_to_EnumList(element, items) ⇒ Object
167
168
169
170
171
172
173
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 167
def apply_to_EnumList(element, items)
i = 1
apply_to_List(element, items, EnumList) do |list, item|
item.order = i
i += 1
end
end
|
#apply_to_EnumListItem(element, content) ⇒ Object
198
199
200
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 198
def apply_to_EnumListItem(element, content)
apply_to_ListItem(element, content, EnumListItem.new)
end
|
273
274
275
276
277
278
279
280
281
282
283
284
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 273
def (element, content)
if @slide.nil?
Text.new("")
else
num = (element)
unless num
raise ArgumentError, "[BUG?] #{element} is not registered."
end
(num, content)
Footnote.new(num)
end
end
|
286
287
288
289
290
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 286
def (element, content)
num = (element)
raise ArgumentError, "[BUG] #{element} isn't registered." unless num
FootText.new(num, content)
end
|
#apply_to_Headline(element, title) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 112
def apply_to_Headline(element, title)
anchor = get_anchor(element)
slide, @slide = @slide, nil
case element.level
when 1
if @slides.empty?
@slide = TitleSlide.new(Title.new(title))
else
@slide = Slide.new(HeadLine.new(title))
@slide << Body.new
end
@foot_texts << []
@slides << @slide
@slide
when 2
if /\Anote\z/i =~ title.first.text
NoteSetter.new(@slides.last)
else
SlidePropertySetter.new(@slides.last)
end
else
nil
end
end
|
#apply_to_Include(element) ⇒ Object
137
138
139
140
141
142
143
144
145
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 137
def apply_to_Include(element)
paths = element.tree.include_paths
fname = search_file(element.filename, paths, @include_suffix)
if fname
File.open(fname) do |f|
instance_eval(f.read, fname, 0)
end
end
end
|
#apply_to_Index(element, content) ⇒ Object
258
259
260
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 258
def apply_to_Index(element, content)
Index.new(content)
end
|
#apply_to_ItemList(element, items) ⇒ Object
163
164
165
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 163
def apply_to_ItemList(element, items)
apply_to_List(element, items, ItemList)
end
|
#apply_to_ItemListItem(element, content) ⇒ Object
194
195
196
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 194
def apply_to_ItemListItem(element, content)
apply_to_ListItem(element, content, ItemListItem.new)
end
|
#apply_to_Keyboard(element, content) ⇒ Object
254
255
256
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 254
def apply_to_Keyboard(element, content)
Keyboard.new(content)
end
|
#apply_to_List(element, items, klass) ⇒ Object
183
184
185
186
187
188
189
190
191
192
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 183
def apply_to_List(element, items, klass)
list = klass.new()
items.each do |item|
list << item
if block_given?
yield(list, item)
end
end
list
end
|
#apply_to_ListItem(element, contents, item) ⇒ Object
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 216
def apply_to_ListItem(element, contents, item)
contents.each do |content|
item << content
end
waited_paragraphs = item.elements.find_all do |element|
element.is_a?(Paragraph) and element.have_wait_tag?
end
unless waited_paragraphs.empty?
waited_paragraphs.each do |paragraph|
paragraph.default_visible = true
paragraph.clear_theme
unregister_pause(paragraph)
end
item.default_visible = false
item.clear_theme
register_pause(item)
end
item
end
|
#apply_to_MethodList(element, items) ⇒ Object
179
180
181
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 179
def apply_to_MethodList(element, items)
apply_to_List(element, items, MethodList)
end
|
#apply_to_MethodListItem(element, term, description) ⇒ Object
209
210
211
212
213
214
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 209
def apply_to_MethodListItem(element, term, description)
method_term = parse_method(term)
method_description = MethodDescription.new
apply_to_ListItem(element, description, method_description)
MethodListItem.new(method_term, method_description)
end
|
#apply_to_Reference_with_RDLabel(element, content) ⇒ Object
262
263
264
265
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 262
def apply_to_Reference_with_RDLabel(element, content)
source = content.collect{|elem| elem.text}
apply_to_extension("refer", element.label, source, content)
end
|
#apply_to_Reference_with_URL(element, content) ⇒ Object
267
268
269
270
271
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 267
def apply_to_Reference_with_URL(element, content)
ref = ReferText.new(content)
ref.to = element.label.url
ref
end
|
#apply_to_String(str) ⇒ Object
#apply_to_StringElement(element) ⇒ Object
237
238
239
240
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 237
def apply_to_StringElement(element)
content = element.content.gsub(/\n\s*/, '')
Text.new(apply_to_String(content))
end
|
#apply_to_TextBlock(element, content) ⇒ Object
147
148
149
150
151
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 147
def apply_to_TextBlock(element, content)
paragraph = Paragraph.new(content)
register_pause(paragraph) if paragraph.have_wait_tag?
paragraph
end
|
#apply_to_Var(element, content) ⇒ Object
250
251
252
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 250
def apply_to_Var(element, content)
Variable.new(content)
end
|
#apply_to_Verb(element) ⇒ Object
292
293
294
295
296
297
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 292
def apply_to_Verb(element)
source = apply_to_String(element.content)
content = element.content
apply_to_extension("inline_verbatim", element.to_label,
source, content)
end
|
#apply_to_Verbatim(element) ⇒ Object
153
154
155
156
157
158
159
160
161
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 153
def apply_to_Verbatim(element)
content = []
element.each_line do |line|
content << line
end
content_str = content.join("")
/\A#\s*([^\n]+)(?:\n)?(?m:(.*)?)\z/ =~ content_str
apply_to_extension("block_verbatim", $1, $2.to_s, content_str)
end
|
#create_have_text_element(klass, content) ⇒ Object
303
304
305
306
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 303
def create_have_text_element(klass, content)
raise "Why???" if content.size > 1
klass.new(content.collect{|x| x.text}.join(""))
end
|
#current_body ⇒ Object
308
309
310
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 308
def current_body
@slide.body
end
|
#visit(tree) ⇒ Object
73
74
75
76
77
|
# File 'lib/rabbit/parser/rd/rd2rabbit-lib.rb', line 73
def visit(tree)
prepare_labels(tree, "label-")
(tree)
super(tree)
end
|