Class: PPTX::Shapes::SlideNumber

Inherits:
Textbox show all
Defined in:
lib/pptx/shapes/slide_number.rb

Instance Method Summary collapse

Methods inherited from Textbox

#base_xml, #empty_paragraph, #set_formatting

Methods inherited from Shape

#base_node, #build_solid_fill, #set_shape_properties

Constructor Details

#initialize(transform, slidenum, formatting = {}) ⇒ SlideNumber

Returns a new instance of SlideNumber.



4
5
6
# File 'lib/pptx/shapes/slide_number.rb', line 4

def initialize(transform, slidenum, formatting={})
  super(transform, slidenum.to_s, formatting)
end

Instance Method Details

#build_nodeObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/pptx/shapes/slide_number.rb', line 8

def build_node
  node = super

  placeholder_xml = """
    <p:ph xmlns:p='#{Presentation::NS}' sz='quarter' type='sldNum'/>"""
  placeholder = Nokogiri::XML::DocumentFragment.parse(placeholder_xml)
  node.xpath('./p:sp/p:nvSpPr/p:nvPr', p:Presentation::NS).first.add_child placeholder

  node
end

#build_paragraph(slidenum) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pptx/shapes/slide_number.rb', line 19

def build_paragraph(slidenum)
  paragraph_xml = """
    <a:p xmlns:a='http://schemas.openxmlformats.org/drawingml/2006/main'>
        <a:pPr/>
        <a:fld id='REPLACE ME' type='slidenum'>
            <a:rPr lang='en-US' smtClean='0'/>
            <a:t>REPLACE ME</a:t>
        </a:fld>
        <a:endParaRPr lang='en-US'/>
    </a:p>
  """

  Nokogiri::XML::DocumentFragment.parse(paragraph_xml).tap do |node|
    node.xpath('./a:p/a:fld/a:t', a: DRAWING_NS).first.content = slidenum
    field_id = "{#{SecureRandom.uuid}}"
    node.xpath('./a:p/a:fld', a: DRAWING_NS).first['id'] = field_id
  end
end