diff options
| author | Randy Morgan <[email protected]> | 2011-11-20 23:22:04 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2011-11-20 23:22:04 +0900 |
| commit | e53f04284618713b0a90b7a691425c380e829476 (patch) | |
| tree | 801fea138160f9af426d62bf94ad5bf97123ece9 /lib/axlsx/content_type | |
| download | caxlsx-e53f04284618713b0a90b7a691425c380e829476.tar.gz caxlsx-e53f04284618713b0a90b7a691425c380e829476.zip | |
first commit
Diffstat (limited to 'lib/axlsx/content_type')
| -rw-r--r-- | lib/axlsx/content_type/content_type.rb | 23 | ||||
| -rw-r--r-- | lib/axlsx/content_type/default.rb | 32 | ||||
| -rw-r--r-- | lib/axlsx/content_type/override.rb | 30 |
3 files changed, 85 insertions, 0 deletions
diff --git a/lib/axlsx/content_type/content_type.rb b/lib/axlsx/content_type/content_type.rb new file mode 100644 index 00000000..ac75a0d4 --- /dev/null +++ b/lib/axlsx/content_type/content_type.rb @@ -0,0 +1,23 @@ +module Axlsx + require 'axlsx/content_type/default.rb' + require 'axlsx/content_type/override.rb' + + # ContentTypes used in the package. This is automatcially managed by the package package. + class ContentType < SimpleTypedList + + def initialize + 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 + end + end +end diff --git a/lib/axlsx/content_type/default.rb b/lib/axlsx/content_type/default.rb new file mode 100644 index 00000000..c82e5f7d --- /dev/null +++ b/lib/axlsx/content_type/default.rb @@ -0,0 +1,32 @@ +module Axlsx + # An default content part. These parts are automatically created by for you based on the content of your package. + class Default + + # The extension of the content type. + # @return [String] + attr_accessor :Extension + + # @return [String] ContentType The type of content. TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, DRAWING_CT are allowed + attr_accessor :ContentType + + #Creates a new Default object + # @option options [String] Extension + # @option options [String] ContentType + # @raise [ArgumentError] An argument error is raised if both Extension and ContentType are not specified. + def initialize(options={}) + 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 + def Extension=(v) Axlsx::validate_string v; @Extension = v end + 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) + end + end +end diff --git a/lib/axlsx/content_type/override.rb b/lib/axlsx/content_type/override.rb new file mode 100644 index 00000000..4d1b008f --- /dev/null +++ b/lib/axlsx/content_type/override.rb @@ -0,0 +1,30 @@ +module Axlsx + # An override content part. These parts are automatically created by for you based on the content of your package. + class Override + + # @return [String] ContentType The type of content. TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, DRAWING_CT are allowed + attr_accessor :ContentType + + # @return [String] PartName The name and location of the part. + attr_accessor :PartName + + #Creates a new Override object + # @option options [String] PartName + # @option options [String] ContentType + # @raise [ArgumentError] An argument error is raised if both PartName and ContentType are not specified. + def initialize(options={}) + 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 + def PartName=(v) Axlsx::validate_string v; @PartName = v end + 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) + end + end +end |
