Class: Sablon::DOM::ContentTypes

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

Overview

Adds new content types to the document

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FileHandler

#max_attribute_value

Constructor Details

#initialize(xml_node) ⇒ ContentTypes

Sets up the class instance to handle new relationships for a document. I only care about tags that have an integer component



19
20
21
22
23
# File 'lib/sablon/document_object_model/content_types.rb', line 19

def initialize(xml_node)
  super
  #
  @types = xml_node.root
end

Class Method Details

.extend_model(model_klass) ⇒ Object

extends the Model class so it now has an “add_content_type” method



9
10
11
12
13
14
15
# File 'lib/sablon/document_object_model/content_types.rb', line 9

def self.extend_model(model_klass)
  super do
    define_method(:add_content_type) do |extension, type|
      @dom['[Content_Types].xml'].add_content_type(extension, type)
    end
  end
end

Instance Method Details

#add_content_type(extension, type) ⇒ Object

Adds a new content type to the file



26
27
28
29
30
31
32
# File 'lib/sablon/document_object_model/content_types.rb', line 26

def add_content_type(extension, type)
  #
  # don't add duplicate extensions to the document
  return unless @types.css(%(Default[Extension="#{extension}"])).empty?
  #
  @types << %(<Default Extension="#{extension}" ContentType="#{type}"/>)
end