Class: PPTX::Presentation

Inherits:
OPC::Part show all
Defined in:
lib/pptx/presentation.rb

Constant Summary collapse

NS =
'http://schemas.openxmlformats.org/presentationml/2006/main'
MIN_SLIDE_ID =
256

Instance Method Summary collapse

Methods inherited from OPC::Part

#relationship_part_name, #relationships, #relative_part_name

Methods inherited from OPC::BasePart

#base_xml, #content_type, #doc, #marshal, #part_name, #template

Constructor Details

#initialize(package, part_name) ⇒ Presentation

Returns a new instance of Presentation.



6
7
8
# File 'lib/pptx/presentation.rb', line 6

def initialize(package, part_name)
  super(package, part_name)
end

Instance Method Details

#add_slide(slide) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pptx/presentation.rb', line 10

def add_slide(slide)
  # TODO remove me - remove existing slide from template
  # slide_list_xml.xpath('./p:sldId').each do |slide|
  #   slide_list.children.delete(slide)
  # end
  ref_id = relationships.add(relative_part_name(slide.part_name), RELTYPE_SLIDE)

  # add slide to sldIdList in presentation
  slide_id = Nokogiri::XML::Node.new('p:sldId', doc)
  slide_id['id'] = next_slide_id
  slide_id['r:id'] = ref_id
  slide_list_xml.add_child(slide_id)
end

#next_slide_idObject



24
25
26
27
# File 'lib/pptx/presentation.rb', line 24

def next_slide_id
  ids = slide_list_xml.xpath('./p:sldId').map { |sid| sid['id'].to_i }
  return (ids.max || MIN_SLIDE_ID - 1) + 1
end

#slide_list_xmlObject



29
30
31
# File 'lib/pptx/presentation.rb', line 29

def slide_list_xml
  @slide_list_xml ||= doc.xpath('/p:presentation/p:sldIdLst', p: NS).first
end