Skip to content

Commit

Permalink
Lists: Decimal: quick&dirty implementation of sequential numbering
Browse files Browse the repository at this point in the history
  • Loading branch information
vjt committed Sep 15, 2010
1 parent 4887baf commit e9ed212
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/rtf/node.rb
Expand Up @@ -595,12 +595,14 @@ def initialize(parent, template, kind, level=1)
super(parent, prefix, nil, true, false)
end

attr_reader :kind

def level
@level.level
end

def item
node = ListTextNode.new(parent, @level)
node = ListTextNode.new(self, @level)
yield node
self.store(node)
end
Expand All @@ -614,13 +616,19 @@ def list(kind=@kind)

class ListTextNode < CommandNode
def initialize(parent, level)
@level = level
@level = level
@parent = parent

prefix = "{\\listtext#{@level.marker.text_format}}"
number = siblings_count + 1 if parent.kind == :decimal
prefix = "{\\listtext#{@level.marker.text_format(number)}}"
suffix = '\\'

super(parent, prefix, suffix, false, false)
end

def siblings_count
parent.children.select {|n| n.kind_of?(self.class)}.size
end
end

# This class represents a table node within an RTF document. Table nodes are
Expand Down

0 comments on commit e9ed212

Please sign in to comment.