Class: Rabbit::Parser::Wiki::RabbitOutput

Inherits:
Object
  • Object
show all
Includes:
Element, PauseSupport
Defined in:
lib/rabbit/parser/wiki/output.rb

Defined Under Namespace

Classes: BlockPlugin, InlinePlugin

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PauseSupport

#burn_out_pause_targets, #pause_targets, #register_pause, #unregister_pause

Constructor Details

#initialize(canvas) ⇒ RabbitOutput

Returns a new instance of RabbitOutput.



39
40
41
# File 'lib/rabbit/parser/wiki/output.rb', line 39

def initialize(canvas)
  @canvas = canvas
end

Instance Attribute Details

#canvasObject (readonly)

Returns the value of attribute canvas.



38
39
40
# File 'lib/rabbit/parser/wiki/output.rb', line 38

def canvas
  @canvas
end

Instance Method Details

#block_plugin(src) ⇒ Object



309
310
311
312
313
314
315
# File 'lib/rabbit/parser/wiki/output.rb', line 309

def block_plugin(src)
  return unless @parent

  result = evaluate_block_plugin(src)
  return if result == :no_element
  @parent << (result || text("{{#{src}}}"))
end

#block_preformatted(contents, info) ⇒ Object



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/rabbit/parser/wiki/output.rb', line 278

def block_preformatted(contents, info)
  return unless @parent

  lang = info ? info.downcase : nil
  result = nil

  if lang
    result = Ext::CodeRay.highlight(lang, contents, @canvas.logger)
  end

  if result
    @parent << result
  else
    preformatted(text(contents))
  end
end

#blockquote_closeObject



272
273
274
275
276
# File 'lib/rabbit/parser/wiki/output.rb', line 272

def blockquote_close
  return unless @parent

  @parent = @parent.parent
end

#blockquote_openObject



264
265
266
267
268
269
270
# File 'lib/rabbit/parser/wiki/output.rb', line 264

def blockquote_open
  return unless @parent

  block_quote = BlockQuote.new
  @parent << block_quote
  @parent = block_quote
end

#container(_for = nil) ⇒ Object



66
67
68
# File 'lib/rabbit/parser/wiki/output.rb', line 66

def container(_for=nil)
  []
end

#current_bodyObject



70
71
72
# File 'lib/rabbit/parser/wiki/output.rb', line 70

def current_body
  @slides.last.body
end

#del(item) ⇒ Object



341
342
343
# File 'lib/rabbit/parser/wiki/output.rb', line 341

def del(item)
  DeletedText.new(item)
end

#dlist_closeObject



186
187
188
189
190
191
192
# File 'lib/rabbit/parser/wiki/output.rb', line 186

def dlist_close
  return unless @parent

  list = @parent
  @parent = list.parent
  @parent << list
end

#dlist_item(dt, dd) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/rabbit/parser/wiki/output.rb', line 194

def dlist_item(dt, dd)
  if @slide_property_mode and @target_slide
    name = dt.collect {|element| element.text}.join
    value = dd.collect {|element| element.text}.join
    @target_slide[Parser.normalize_property_name(name)] = value.strip
  else
    return unless @parent

    desc_term = DescriptionTerm.new(Paragraph.new(dt.flatten))
    desc_content = DescriptionContent.new(Paragraph.new(dd.flatten))
    @parent << DescriptionListItem.new(desc_term, desc_content)
  end
end

#dlist_openObject



178
179
180
181
182
183
184
# File 'lib/rabbit/parser/wiki/output.rb', line 178

def dlist_open
  return unless @parent

  list = DescriptionList.new
  list.parent = @parent
  @parent = list
end

#em(item) ⇒ Object



337
338
339
# File 'lib/rabbit/parser/wiki/output.rb', line 337

def em(item)
  Emphasis.new(item)
end

#finishObject



59
60
61
62
63
64
# File 'lib/rabbit/parser/wiki/output.rb', line 59

def finish
  @slides.each do |slide|
    @canvas << slide
  end
  burn_out_pause_targets
end

#headline(level, title) ⇒ Object

Procedures



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/rabbit/parser/wiki/output.rb', line 78

def headline(level, title)
  @slide_property_mode = false
  case level
  when 1
    slide = nil
    if @slides.empty?
      @title_slide = true
      slide = TitleSlide.new(Title.new(title))
      @parent = slide
    else
      @title_slide = false
      slide = Element::Slide.new(HeadLine.new(title))
      body = Body.new
      slide << body
      @parent = body
    end
    @foot_texts << []
    @slides << slide
  when 2
    @slide_property_mode = true
    @parent, @target_slide = nil, @slides.last
  else
    @parent = nil
  end
end

#hruleObject



104
105
106
# File 'lib/rabbit/parser/wiki/output.rb', line 104

def hrule
  @canvas.logger.warn(_("horizontal rule is unsupported")) if @parent
end

Functions



322
323
324
325
326
# File 'lib/rabbit/parser/wiki/output.rb', line 322

def hyperlink(uri, title)
  ref = ReferText.new(title)
  ref.to = uri
  ref
end

inline image is not supported yet…



329
330
331
# File 'lib/rabbit/parser/wiki/output.rb', line 329

def image_hyperlink(uri, alt=nil)
  Ext::Image.make_image(@canvas, uri, "caption" => alt) || Text.new(uri)
end

#inline_plugin(src) ⇒ Object



349
350
351
# File 'lib/rabbit/parser/wiki/output.rb', line 349

def inline_plugin(src)
  evaluate_inline_plugin(src) || text("{{#{src}}}")
end

#list_beginObject



108
109
# File 'lib/rabbit/parser/wiki/output.rb', line 108

def list_begin
end

#list_close(type) ⇒ Object



136
137
138
139
140
141
142
143
# File 'lib/rabbit/parser/wiki/output.rb', line 136

def list_close(type)
  @enum_order_stack.pop if type == "ol"
  @list_type_stack.pop
  return unless @parent

  @parent = @parent.parent
  @parent = @parent.parent unless @list_type_stack.empty?
end

#list_endObject



111
112
# File 'lib/rabbit/parser/wiki/output.rb', line 111

def list_end
end

#list_open(type) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/rabbit/parser/wiki/output.rb', line 114

def list_open(type)
  @enum_order_stack << 1 if type == "ol"
  @list_type_stack << type
  return unless @parent

  case type
  when "ul"
    list = ItemList.new
  when "ol"
    list = EnumList.new
  else
    unsupported_list_type(type)
  end

  if @list_type_stack.size > 1
    @parent.elements.last << list
  else
    @parent << list
  end
  @parent = list
end

#listitem(item) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/rabbit/parser/wiki/output.rb', line 151

def listitem(item)
  return unless @parent

  list_item = nil
  item = item.flatten
  paragraph = Paragraph.new(item)
  type = @list_type_stack.last
  case type
  when "ul"
    list_item = ItemListItem.new(paragraph)
    @parent << list_item
  when "ol"
    list_item = EnumListItem.new(paragraph)
    list_item.order = @enum_order_stack.last
    @enum_order_stack[-1] += 1
    @parent << list_item
  else
    unsupported_list_type
  end

  return unless paragraph.have_wait_tag?

  paragraph.default_visible = true
  paragraph.clear_theme
  register_pause(list_item)
end

#listitem_closeObject



148
149
# File 'lib/rabbit/parser/wiki/output.rb', line 148

def listitem_close
end

#listitem_openObject



145
146
# File 'lib/rabbit/parser/wiki/output.rb', line 145

def listitem_open
end

#paragraph(contents) ⇒ Object



301
302
303
304
305
306
307
# File 'lib/rabbit/parser/wiki/output.rb', line 301

def paragraph(contents)
  return unless @parent

  paragraph = Paragraph.new(contents.flatten)
  register_pause(paragraph) if paragraph.have_wait_tag?
  @parent << paragraph
end

#preformatted(contents) ⇒ Object



295
296
297
298
299
# File 'lib/rabbit/parser/wiki/output.rb', line 295

def preformatted(contents)
  return unless @parent

  @parent << PreformattedBlock.new(PreformattedText.new(contents))
end

#resetObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rabbit/parser/wiki/output.rb', line 43

def reset
  @title_slide = false

  @slides = []
  @parent = nil
  @index = {}

  @slide_property_mode = false
  @target_slide = nil

  @enum_order_stack = []
  @list_type_stack = []

  @foot_texts = []
end

#strong(item) ⇒ Object



333
334
335
# File 'lib/rabbit/parser/wiki/output.rb', line 333

def strong(item)
  Emphasis.new(Emphasis.new(item))
end

#table_closeObject



222
223
224
225
226
227
228
229
# File 'lib/rabbit/parser/wiki/output.rb', line 222

def table_close
  return unless @parent

  @table << @table_head if @have_table_header
  @table << @table_body if @have_table_body

  @parent = @table.parent
end

#table_data(item, rs, cs) ⇒ Object



256
257
258
259
260
261
262
# File 'lib/rabbit/parser/wiki/output.rb', line 256

def table_data(item, rs, cs)
  return unless @parent

  @have_table_body = true
  @table_body << @parent if @parent.parent.nil?
  @parent << TableCell.new(item)
end

#table_head(item, rs, cs) ⇒ Object



244
245
246
247
248
249
250
251
252
253
254
# File 'lib/rabbit/parser/wiki/output.rb', line 244

def table_head(item, rs, cs)
  return unless @parent

  @have_table_header = true
  @table_head << @parent if @parent.parent.nil?
  header = TableHeader.new(item)
  def header.default_align
    Pango::Layout::ALIGN_CENTER
  end
  @parent << header
end

#table_openObject



208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/rabbit/parser/wiki/output.rb', line 208

def table_open
  return unless @parent

  @table = Table.new
  @parent << @table
  @parent = @table

  @table_head = TableHead.new
  @table_body = TableBody.new

  @have_table_header = false
  @have_table_body = false
end

#table_record_closeObject



238
239
240
241
242
# File 'lib/rabbit/parser/wiki/output.rb', line 238

def table_record_close
  return unless @parent

  @parent = @parent.parent
end

#table_record_openObject



231
232
233
234
235
236
# File 'lib/rabbit/parser/wiki/output.rb', line 231

def table_record_open
  return unless @parent

  @parent = TableRow.new
  @table_record_type = nil
end

#text(str) ⇒ Object



345
346
347
# File 'lib/rabbit/parser/wiki/output.rb', line 345

def text(str)
  Text.new(Ext::Escape.escape_meta_character(str))
end