Class: Clamsy::OpenDoc
- Inherits:
-
Object
- Object
- Clamsy::OpenDoc
- Defined in:
- lib/clamsy/template_open_doc.rb
Class Method Summary collapse
- .extract_picture_paths(content) ⇒ Object
- .per_content_entry(file, &blk) ⇒ Object
- .string_to_xml_doc(string) ⇒ Object
Instance Method Summary collapse
-
#initialize(file, workers, context) ⇒ OpenDoc
constructor
A new instance of OpenDoc.
- #transform ⇒ Object
Constructor Details
#initialize(file, workers, context) ⇒ OpenDoc
Returns a new instance of OpenDoc.
94 95 96 |
# File 'lib/clamsy/template_open_doc.rb', line 94 def initialize(file, workers, context) @file, @workers, @context = file, workers, context end |
Class Method Details
.extract_picture_paths(content) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/clamsy/template_open_doc.rb', line 85 def self.extract_picture_paths(content) doc = string_to_xml_doc(content) nodes = lambda {|path| doc.xpath(path) } nodes['//drawframe/@drawname'].inject({}) do |memo, node| path = nodes[%\//drawframe[@drawname="#{node.value}"]//drawimage/@xlinkhref\][0] memo.merge(path ? {:"#{node.value}" => path.value} : {}) end end |
.per_content_entry(file, &blk) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/clamsy/template_open_doc.rb', line 69 def self.per_content_entry(file, &blk) Zip::ZipFile.open(file) do |zip| zip.select {|entry| entry.file? && entry.to_s =~ /\.xml$/ }.each do |entry| class << entry ; attr_accessor :zip ; end entry.zip = zip yield(entry) end end end |
.string_to_xml_doc(string) ⇒ Object
79 80 81 82 83 |
# File 'lib/clamsy/template_open_doc.rb', line 79 def self.string_to_xml_doc(string) Nokogiri::XML(string.gsub(':','')) do |config| config. = Nokogiri::XML::ParseOptions::STRICT end end |
Instance Method Details
#transform ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/clamsy/template_open_doc.rb', line 98 def transform OpenDoc.per_content_entry(@file.path) do |@entry| @entry.zip.get_output_stream(@entry.to_s) do |@io| replace_texts ; replace_pictures end end @file end |