Class: RRTF::ListLevelNode

Inherits:
CommandNode show all
Defined in:
lib/rrtf/node/list_level_node.rb

Overview

This class represents a list level, and carries out indenting information and the bullet or number that is prepended to each ListTextNode.

The class overrides the list method to implement nesting, and provides the item method to add a new list item, the ListTextNode.

Instance Attribute Summary collapse

Attributes inherited from CommandNode

#prefix, #split, #suffix, #wrap

Attributes inherited from ContainerNode

#children

Attributes inherited from Node

#parent

Instance Method Summary collapse

Methods inherited from CommandNode

#<<, #apply, #footnote, #geometry, #image, #line_break, #link, #paragraph, #table, #to_rtf

Methods inherited from ContainerNode

#[], #each, #first, #last, #size, #store, #to_rtf

Methods inherited from Node

#is_root?, #next_node, #previous_node, #root

Constructor Details

#initialize(parent, template, kind, level = 1) ⇒ ListLevelNode

Returns a new instance of ListLevelNode



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rrtf/node/list_level_node.rb', line 8

def initialize(parent, template, kind, level=1)
  @template = template
  @kind     = kind
  @level    = template.level_for(level, kind)

  prefix  = '\pard'
  prefix << @level.tabs.map {|tw| "\\tx#{tw}"}.join
  prefix << "\\li#{@level.indent}\\fi-#{@level.indent}"
  prefix << "\\ql\\qlnatural\\pardirnatural\n"
  prefix << "\\ls#{@template.id}\\ilvl#{@level.level-1}\\cf0"

  super(parent, prefix, nil, true, false)
end

Instance Attribute Details

#kindObject (readonly)

Returns the kind of this level, either :bullets or :decimal



23
24
25
# File 'lib/rrtf/node/list_level_node.rb', line 23

def kind
  @kind
end

Instance Method Details

#item {|node| ... } ⇒ Object

Creates a new ListTextNode and yields it to the calling block

Yields:

  • (node)


31
32
33
34
35
# File 'lib/rrtf/node/list_level_node.rb', line 31

def item
  node = ListTextNode.new(self, @level)
  yield node
  self.store(node)
end

#levelObject

Returns the indenting level of this list, from 1 to 9



26
27
28
# File 'lib/rrtf/node/list_level_node.rb', line 26

def level
  @level.level
end

#list(kind = @kind) {|node| ... } ⇒ Object

Creates a new ListLevelNode to implement nested lists

Yields:

  • (node)


38
39
40
41
42
# File 'lib/rrtf/node/list_level_node.rb', line 38

def list(kind=@kind)
  node = ListLevelNode.new(self, @template, kind, @level.level+1)
  yield node
  self.store(node)
end