summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/content_type
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-04-01 00:35:26 +0900
committerRandy Morgan <[email protected]>2012-04-01 00:35:26 +0900
commit22a341841f191a5aa00e87b1f166b4f25cc67f0a (patch)
tree505f46708d5cac7d33d0dd6679c125e2eb819075 /lib/axlsx/content_type
parentbb2117ba17297e02a0fc6d5ad5a22462e72a9a79 (diff)
downloadcaxlsx-22a341841f191a5aa00e87b1f166b4f25cc67f0a.tar.gz
caxlsx-22a341841f191a5aa00e87b1f166b4f25cc67f0a.zip
part way through changing all serialization to use string concatenation prior to dropping Nokogiri dep in production.
Diffstat (limited to 'lib/axlsx/content_type')
-rw-r--r--lib/axlsx/content_type/content_type.rb17
-rw-r--r--lib/axlsx/content_type/default.rb14
-rw-r--r--lib/axlsx/content_type/override.rb18
3 files changed, 25 insertions, 24 deletions
diff --git a/lib/axlsx/content_type/content_type.rb b/lib/axlsx/content_type/content_type.rb
index 8b58bf04..6b4facd0 100644
--- a/lib/axlsx/content_type/content_type.rb
+++ b/lib/axlsx/content_type/content_type.rb
@@ -10,15 +10,14 @@ module Axlsx
super [Override, Default]
end
- # Generates the xml document for [Content_Types].xml
- # @return [String] The document as a string.
- def to_xml()
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
- xml.Types(:xmlns => Axlsx::XML_NS_T) {
- each { |type| type.to_xml(xml) }
- }
- end
- builder.to_xml(:save_with => 0)
+ # serialize the content types
+ # @return [String] str
+ def to_xml_string(str = '')
+ str << '<?xml version="1.0" encoding="UTF-8"?>'
+ str << '<Types xmlns="' << XML_NS_T << '">'
+ each { |type| type.to_xml_string(str) }
+ str << '</Types>'
end
+
end
end
diff --git a/lib/axlsx/content_type/default.rb b/lib/axlsx/content_type/default.rb
index bd572b14..2ff24527 100644
--- a/lib/axlsx/content_type/default.rb
+++ b/lib/axlsx/content_type/default.rb
@@ -8,7 +8,7 @@ module Axlsx
attr_reader :Extension
# The type of content.
- # @return [String]
+ # @return [String]
attr_reader :ContentType
#Creates a new Default object
@@ -19,7 +19,7 @@ module Axlsx
raise ArgumentError, "Extension and ContentType are required" unless options[:Extension] && options[:ContentType]
options.each do |o|
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
- end
+ end
end
# Sets the file extension for this content type.
def Extension=(v) Axlsx::validate_string v; @Extension = v end
@@ -28,11 +28,11 @@ module Axlsx
# @see Axlsx#validate_content_type
def ContentType=(v) Axlsx::validate_content_type v; @ContentType = v end
- # Serializes the object to xml
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml.Default(self.instance_values)
+ def to_xml_string(str = '')
+ str << '<Default '
+ str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
+ str << '/>'
end
+
end
end
diff --git a/lib/axlsx/content_type/override.rb b/lib/axlsx/content_type/override.rb
index 2513b8ff..665a538a 100644
--- a/lib/axlsx/content_type/override.rb
+++ b/lib/axlsx/content_type/override.rb
@@ -4,11 +4,11 @@ module Axlsx
class Override
# The type of content.
- # @return [String]
+ # @return [String]
attr_reader :ContentType
# The name and location of the part.
- # @return [String]
+ # @return [String]
attr_reader :PartName
#Creates a new Override object
@@ -19,20 +19,22 @@ module Axlsx
raise ArgumentError, "PartName and ContentType are required" unless options[:PartName] && options[:ContentType]
options.each do |o|
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
- end
+ end
end
# The name and location of the part.
def PartName=(v) Axlsx::validate_string v; @PartName = v end
- # The content type.
+ # The content type.
# @see Axlsx#validate_content_type
def ContentType=(v) Axlsx::validate_content_type v; @ContentType = v end
- # Serializes the Override object to xml
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- def to_xml(xml)
- xml.Override(self.instance_values)
+ # Serialize the Override
+ def to_xml_string(str = '')
+ str << '<Override '
+ str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
+ str << '/>'
end
+
end
end