Sha256: c537db7f70ae6902a9d75705237133a1505ce43c4d812837e9b4cb1b4429d42a
Contents?: true
Size: 1.32 KB
Versions: 8
Compression:
Stored size: 1.32 KB
Contents
module Sablon module Processor class Numbering LIST_DEFINITION = <<-XML.gsub(/^\s+/, '').tr("\n", '') <w:num w:numId="%s"> <w:abstractNumId w:val="%s" /> </w:num> XML def self.process(doc) processor = new(doc) processor.manipulate doc end def initialize(doc) @doc = doc end def manipulate Sablon::Numbering.instance.definitions.each do |definition| abstract_num_ref = find_definition(definition.style) abstract_num_copy = abstract_num_ref.dup abstract_num_copy['w:abstractNumId'] = definition.numid abstract_num_copy.xpath('./w:nsid').each(&:remove) container.prepend_child abstract_num_copy container.add_child(LIST_DEFINITION % [definition.numid, abstract_num_copy['w:abstractNumId']]) end @doc end private def container @container ||= @doc.xpath('//w:numbering').first end def find_definition(style) abstract_num = @doc.xpath("//w:abstractNum[descendant-or-self::*[w:pStyle[@w:val='#{style}']]]").first if abstract_num abstract_num else raise ArgumentError, "Could not find w:abstractNum definition for style: #{style.inspect}" end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems