Class: Caracal::Renderers::CustomRenderer

Inherits:
XmlRenderer
  • Object
show all
Defined in:
lib/caracal/renderers/custom_renderer.rb

Instance Attribute Summary

Attributes inherited from XmlRenderer

#document

Instance Method Summary collapse

Methods inherited from XmlRenderer

#initialize, render

Constructor Details

This class inherits a constructor from Caracal::Renderers::XmlRenderer

Instance Method Details

#to_xmlObject

This method produces the xml required for the ‘docProps/custom.xml` sub-document.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/caracal/renderers/custom_renderer.rb', line 18

def to_xml
  builder = ::Nokogiri::XML::Builder.with(declaration_xml) do |xml|
    xml.send 'Properties', root_options do
      document.custom_props.each_with_index do |property, index|
        xml.send 'property',
          { fmtid: '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}', pid: index + 2, name: property.custom_property_name } do
            case property.custom_property_type.downcase
            when  'text'
              xml['vt'].lpwstr property.custom_property_value
            when 'date'
              xml['vt'].filetime property.custom_property_value.to_date
            when 'number'
              xml['vt'].i4 property.custom_property_value.to_f
            when 'boolean'
              if property.custom_property_value == 'true' || property.custom_property_value == 'false'
                xml['vt'].bool property.custom_property_value
              else
                # Not a boolean sent, so reverting to string so docx will open
                xml['vt'].lpwstr property.custom_property_value
              end
            else
              # Fail to string type
              xml['vt'].lpwstr property.custom_property_value
          end
        end
      end
    end
  end
  builder.to_xml(save_options)
end