Module: OpenXml::RelatablePart
- Included in:
- Pptx::Parts::Presentation, Pptx::Parts::PresentationProperties, Pptx::Parts::Slide, Pptx::Parts::SlideLayout, Pptx::Parts::SlideMaster, Pptx::Parts::Theme
- Defined in:
- lib/openxml/pptx/relatable_part.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
Class Method Summary collapse
Instance Method Summary collapse
- #add_child_part(part, with_index: nil) ⇒ Object
- #add_override(part_path, content_type) ⇒ Object
- #add_part(part_path, part) ⇒ Object
- #add_relationship(type, part_path) ⇒ Object
- #content_type ⇒ Object
- #file_name ⇒ Object
- #indexed_path(part_path, index) ⇒ Object
- #initialize(parent: nil, **_options) ⇒ Object
- #path ⇒ Object
- #path=(value) ⇒ Object
- #relationship_type ⇒ Object
- #relationships ⇒ Object
- #relationships_by_path ⇒ Object
- #relationships_path ⇒ Object
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
27 28 29 |
# File 'lib/openxml/pptx/relatable_part.rb', line 27 def parent @parent end |
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/openxml/pptx/relatable_part.rb', line 4 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#add_child_part(part, with_index: nil) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/openxml/pptx/relatable_part.rb', line 67 def add_child_part(part, with_index: nil) part.path = indexed_path(part.path, with_index) unless with_index.nil? part.parent = self if part.respond_to?(:parent=) add_relationship part.relationship_type, part.path return unless instance_variable_defined?("@parent") add_part part.path, part if part.respond_to?(:relationships_path) && !part.relationships_path.nil? rel_path = with_index.nil? ? part.relationships_path : indexed_path(part.relationships_path, with_index) add_part rel_path, part.relationships end add_override part.path, part.content_type if part.respond_to?(:content_type) end |
#add_override(part_path, content_type) ⇒ Object
84 85 86 |
# File 'lib/openxml/pptx/relatable_part.rb', line 84 def add_override(part_path, content_type) parent.add_override part_path, content_type end |
#add_part(part_path, part) ⇒ Object
80 81 82 |
# File 'lib/openxml/pptx/relatable_part.rb', line 80 def add_part(part_path, part) parent.add_part part_path.to_s, part end |
#add_relationship(type, part_path) ⇒ Object
88 89 90 91 |
# File 'lib/openxml/pptx/relatable_part.rb', line 88 def add_relationship(type, part_path) relationship = relationships.add_relationship type, Pathname.new(part_path).relative_path_from(path.dirname) relationships_by_path[part_path] = relationship end |
#content_type ⇒ Object
50 51 52 |
# File 'lib/openxml/pptx/relatable_part.rb', line 50 def content_type self.class.content_type end |
#file_name ⇒ Object
46 47 48 |
# File 'lib/openxml/pptx/relatable_part.rb', line 46 def file_name self.class.default_path.basename end |
#indexed_path(part_path, index) ⇒ Object
93 94 95 96 97 |
# File 'lib/openxml/pptx/relatable_part.rb', line 93 def indexed_path(part_path, index) extension = part_path.to_s.match(/\w(\..+)$/)[1] path_without_extension = part_path.to_s[0...-extension.length] Pathname.new("#{path_without_extension}#{index}#{extension}") end |
#initialize(parent: nil, **_options) ⇒ Object
29 30 31 32 |
# File 'lib/openxml/pptx/relatable_part.rb', line 29 def initialize(parent: nil, **) @parent = parent super() end |
#path ⇒ Object
54 55 56 |
# File 'lib/openxml/pptx/relatable_part.rb', line 54 def path @path || Pathname.new("#{self.class.default_path.dirname}/#{file_name}") end |
#path=(value) ⇒ Object
58 59 60 |
# File 'lib/openxml/pptx/relatable_part.rb', line 58 def path=(value) @path = Pathname.new(value) end |
#relationship_type ⇒ Object
42 43 44 |
# File 'lib/openxml/pptx/relatable_part.rb', line 42 def relationship_type self.class.relationship_type end |
#relationships ⇒ Object
34 35 36 |
# File 'lib/openxml/pptx/relatable_part.rb', line 34 def relationships @relationships ||= OpenXml::Parts::Rels.new end |
#relationships_by_path ⇒ Object
38 39 40 |
# File 'lib/openxml/pptx/relatable_part.rb', line 38 def relationships_by_path @relationships_by_path ||= {} end |
#relationships_path ⇒ Object
62 63 64 65 |
# File 'lib/openxml/pptx/relatable_part.rb', line 62 def relationships_path directory = self.class.default_path.dirname "#{directory}/_rels/#{file_name}.rels" end |