Class: Sablon::DOM::Numbering

Inherits:
FileHandler show all
Defined in:
lib/sablon/document_object_model/numbering.rb

Overview

Manages the creation of new list definitions

Defined Under Namespace

Classes: Definition

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_node) ⇒ Numbering

Sets up the class to add new list definitions to the number.xml file



22
23
24
25
26
27
28
29
30
31
# File 'lib/sablon/document_object_model/numbering.rb', line 22

def initialize(xml_node)
  super
  #
  @numbering = xml_node.root
  #
  @max_numid = max_attribute_value('//w:num', 'w:numId')
  #
  selector = '//w:abstractNum'
  @max_abstract_id = max_attribute_value(selector, 'w:abstractNumId')
end

Class Method Details

.extend_model(model_klass, &block) ⇒ Object

extends the Model class using instance eval with a block argument



10
11
12
13
14
15
16
17
18
# File 'lib/sablon/document_object_model/numbering.rb', line 10

def self.extend_model(model_klass, &block)
  super do
    #
    # adds a list definition to the numbering.xml file
    define_method(:add_list_definition) do |style|
      @dom['word/numbering.xml'].add_list_definition(style)
    end
  end
end

Instance Method Details

#add_list_definition(style) ⇒ Object

adds a new relationship and returns the corresponding rId for it



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sablon/document_object_model/numbering.rb', line 34

def add_list_definition(style)
  definition = create_definition(style)
  #
  # update numbering file with new definitions
  node = @numbering.xpath('//w:abstractNum').last
  node.add_next_sibling(abstract_tag(definition))
  #
  node = @numbering.xpath('//w:num').last
  node.add_next_sibling(definition_tag(definition))
  #
  definition
end