Class: OpenXml::Pptx::Parts::SlideMaster

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

Instance Attribute Summary collapse

Attributes included from RelatablePart

#parent

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) ⇒ SlideMaster

Returns a new instance of SlideMaster.



31
32
33
34
35
# File 'lib/openxml/pptx/parts/slide_master.rb', line 31

def initialize(*_args)
  super
  @layouts = []
  @images = []
end

Instance Attribute Details

#imagesObject (readonly)

Returns the value of attribute images.



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

def images
  @images
end

#layoutsObject (readonly)

Returns the value of attribute layouts.



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

def layouts
  @layouts
end

#themeObject (readonly)

Returns the value of attribute theme.



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

def theme
  @theme
end

Instance Method Details

#add_image(image_part) ⇒ Object



63
64
65
66
67
# File 'lib/openxml/pptx/parts/slide_master.rb', line 63

def add_image(image_part)
  images.push(image_part)
  index = (parent && parent.next_image_index) || images.count
  add_child_part(image_part, with_index: index)
end

#add_slide_layout(layout) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/openxml/pptx/parts/slide_master.rb', line 47

def add_slide_layout(layout)
  layouts.push(layout)
  add_child_part(layout, with_index: layouts.count)
  slide_layout_id_list << OpenXml::Pptx::Properties::SlideLayoutId.new.tap do |layout_id|
    layout_id.rid = relationships_by_path[layout.path].id
  end
end

#background_propertiesObject



100
101
102
# File 'lib/openxml/pptx/parts/slide_master.rb', line 100

def background_properties
  common_slide_data.background.background_properties
end

#build_image_part(path) ⇒ Object



69
70
71
72
73
74
# File 'lib/openxml/pptx/parts/slide_master.rb', line 69

def build_image_part(path)
  path = Pathname.new(path)
  OpenXml::Pptx::Parts::Image.new(path.read, extension: path.extname).tap do |image|
    add_image(image)
  end
end

#build_required_propertiesObject



88
89
90
91
92
93
# File 'lib/openxml/pptx/parts/slide_master.rb', line 88

def build_required_properties
  super
  DEFAULT_COLOR_MAPPING.each do |key, value|
    color_mapping.public_send(:"#{key}=", value)
  end
end

#build_slide_layout(named: nil) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/openxml/pptx/parts/slide_master.rb', line 55

def build_slide_layout(named: nil)
  OpenXml::Pptx::Parts::SlideLayout.new.tap do |layout|
    layout.set_slide_master(self)
    layout.common_slide_data.slide_name = named unless named.nil?
    add_slide_layout(layout)
  end
end

#nameObject

Necessary for HasAttributes



38
39
40
# File 'lib/openxml/pptx/parts/slide_master.rb', line 38

def name
  "slide_master"
end

#next_image_indexObject



76
77
78
# File 'lib/openxml/pptx/parts/slide_master.rb', line 76

def next_image_index
  @image_index = (parent && parent.next_image_index) || @image_index + 1
end

#set_theme(theme) ⇒ Object



42
43
44
45
# File 'lib/openxml/pptx/parts/slide_master.rb', line 42

def set_theme(theme)
  @theme = theme
  add_relationship theme.relationship_type, theme.path
end

#shapesObject

Convenience accessors



96
97
98
# File 'lib/openxml/pptx/parts/slide_master.rb', line 96

def shapes
  common_slide_data.shape_tree.shapes
end

#to_xmlObject



80
81
82
83
84
85
86
# File 'lib/openxml/pptx/parts/slide_master.rb', line 80

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