class Sablon::DOM::Model
Object to represent an entire template and it's XML contents
Attributes
current_entry[RW]
zip_contents[R]
Public Class Methods
new(zip_io_stream)
click to toggle source
setup the DOM
by reading and storing all XML files in the template in memory
# File lib/sablon/document_object_model/model.rb, line 43 def initialize(zip_io_stream) @current_entry = nil @zip_contents = {} zip_io_stream.each do |entry| next unless entry.file? content = entry.get_input_stream.read @zip_contents[entry.name] = wrap_entry(entry.name, content) end # @dom = build_dom(@zip_contents) end
Public Instance Methods
[](entry_name)
click to toggle source
Returns the corresponding DOM
handled file
# File lib/sablon/document_object_model/model.rb, line 56 def [](entry_name) @dom[entry_name] end
Private Instance Methods
build_dom(entries)
click to toggle source
constructs the dom model using helper clases defined under this namespace.
# File lib/sablon/document_object_model/model.rb, line 73 def build_dom(entries) key_values = entries.map do |entry_name, content| [entry_name, Sablon::DOM.wrap_with_handler(entry_name, content)] end # Hash[key_values] end
create_entry_if_not_exist(name, init_content = '')
click to toggle source
# File lib/sablon/document_object_model/model.rb, line 81 def create_entry_if_not_exist(name, init_content = '') return unless @zip_contents[name].nil? # # create the entry and add it to the dom @zip_contents[name] = wrap_entry(name, init_content) @dom[name] = Sablon::DOM.wrap_with_handler(name, @zip_contents[name]) end
wrap_entry(entry_name, content)
click to toggle source
Determines how the content in the zip file entry should be wrapped
# File lib/sablon/document_object_model/model.rb, line 63 def wrap_entry(entry_name, content) if entry_name =~ /\.(?:xml|rels)$/ Nokogiri::XML(content) else content end end