Class: OpenXml::Pptx::Parts::Presentation

Inherits:
OpenXml::Part
  • Object
show all
Includes:
ContainsProperties, HasAttributes, RelatablePart
Defined in:
lib/openxml/pptx/parts/presentation.rb

Instance Attribute Summary collapse

Attributes included from RelatablePart

#parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RelatablePart

#add_child_part, #add_override, #add_part, #add_relationship, #content_type, #file_name, included, #indexed_path, #path, #path=, #relationship_type, #relationships, #relationships_by_path, #relationships_path

Constructor Details

#initialize(*_args) ⇒ Presentation

Returns a new instance of Presentation.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/openxml/pptx/parts/presentation.rb', line 59

def initialize(*_args)
  super
  @slides = []
  @slide_masters = []
  @themes = []
  @presentation_properties = OpenXml::Pptx::Parts::PresentationProperties.new
  add_child_part(presentation_properties)

  # Set defaults
  slide_size.length = 12_192_000
  slide_size.width = 6_858_000
  notes_size.length = 6_858_000
  notes_size.width = 9_144_000
end

Instance Attribute Details

#presentation_propertiesObject (readonly)

Returns the value of attribute presentation_properties.



10
11
12
# File 'lib/openxml/pptx/parts/presentation.rb', line 10

def presentation_properties
  @presentation_properties
end

#slide_mastersObject (readonly)

Returns the value of attribute slide_masters.



10
11
12
# File 'lib/openxml/pptx/parts/presentation.rb', line 10

def slide_masters
  @slide_masters
end

#slidesObject (readonly)

Returns the value of attribute slides.



10
11
12
# File 'lib/openxml/pptx/parts/presentation.rb', line 10

def slides
  @slides
end

#themesObject (readonly)

Returns the value of attribute themes.



10
11
12
# File 'lib/openxml/pptx/parts/presentation.rb', line 10

def themes
  @themes
end

Class Method Details

.namespaceObject



51
52
53
# File 'lib/openxml/pptx/parts/presentation.rb', line 51

def self.namespace
  :p
end

.tagObject

For proper interaction with HasAttributes



47
48
49
# File 'lib/openxml/pptx/parts/presentation.rb', line 47

def self.tag
  :presentation
end

Instance Method Details

#add_slide(slide) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/openxml/pptx/parts/presentation.rb', line 74

def add_slide(slide)
  slides.push(slide)
  add_child_part(slide, with_index: slides.count)
  slide_id_list << OpenXml::Pptx::Properties::SlideId.new.tap do |slide_id|
    slide_id.rid = relationships_by_path[slide.path].id
  end
end

#add_slide_master(slide_master) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/openxml/pptx/parts/presentation.rb', line 90

def add_slide_master(slide_master)
  slide_masters.push(slide_master)
  add_child_part(slide_master, with_index: slide_masters.count)
  slide_master_id_list << OpenXml::Pptx::Properties::SlideMasterId.new.tap do |master_id|
    master_id.rid = relationships_by_path[slide_master.path].id
  end
end

#add_theme(theme) ⇒ Object



106
107
108
109
# File 'lib/openxml/pptx/parts/presentation.rb', line 106

def add_theme(theme)
  themes.push(theme)
  add_child_part(theme, with_index: themes.count)
end

#build_slide(named: nil, slide_layout: nil) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/openxml/pptx/parts/presentation.rb', line 82

def build_slide(named: nil, slide_layout: nil)
  OpenXml::Pptx::Parts::Slide.new.tap do |slide|
    slide.common_slide_data.slide_name = named unless named.nil?
    slide.set_slide_layout(slide_layout) unless slide_layout.nil?
    add_slide(slide)
  end
end

#build_slide_master(named: nil, theme: nil) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/openxml/pptx/parts/presentation.rb', line 98

def build_slide_master(named: nil, theme: nil)
  OpenXml::Pptx::Parts::SlideMaster.new.tap do |slide_master|
    slide_master.common_slide_data.slide_name = named unless named.nil?
    slide_master.set_theme(theme) unless theme.nil?
    add_slide_master(slide_master)
  end
end

#build_themeObject



111
112
113
114
115
# File 'lib/openxml/pptx/parts/presentation.rb', line 111

def build_theme
  OpenXml::Pptx::Parts::Theme.new.tap do |theme|
    add_theme(theme)
  end
end

#nameObject



55
56
57
# File 'lib/openxml/pptx/parts/presentation.rb', line 55

def name
  "presentation"
end

#next_image_indexObject



117
118
119
# File 'lib/openxml/pptx/parts/presentation.rb', line 117

def next_image_index
  @image_index = (@image_index || 0) + 1
end

#to_xmlObject



121
122
123
124
125
126
127
# File 'lib/openxml/pptx/parts/presentation.rb', line 121

def to_xml
  build_standalone_xml do |xml|
    xml[:p].presentation(namespaces.merge(xml_attributes)) do
      property_xml(xml)
    end
  end
end