Class: PPTXMarkdown::Shape

Inherits:
Struct
  • Object
show all
Defined in:
lib/pptx_markdown/shape.rb

Constant Summary collapse

TITLE_IDS =
%w(ctrTitle title).freeze
BODY_IDS =
%w(subTitle body).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShape

Returns a new instance of Shape.



9
10
11
12
13
# File 'lib/pptx_markdown/shape.rb', line 9

def initialize(*)
  super

  raise PPTXMarkdown::TypeError unless (TITLE_IDS + BODY_IDS).include?(type)
end

Instance Attribute Details

#contentObject

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



5
6
7
# File 'lib/pptx_markdown/shape.rb', line 5

def content
  @content
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



5
6
7
# File 'lib/pptx_markdown/shape.rb', line 5

def type
  @type
end

Instance Method Details

#body?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/pptx_markdown/shape.rb', line 21

def body?
  BODY_IDS.include?(type)
end

#title?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/pptx_markdown/shape.rb', line 16

def title?
  TITLE_IDS.include?(type)
end

#to_markdownObject



25
26
27
28
# File 'lib/pptx_markdown/shape.rb', line 25

def to_markdown
  tag = title? ? '* ' : "\t* "
  format("%s%s\n", tag, content)
end

#to_xml(node) ⇒ String

Returns XML for text shape for ppt/slides/slide0.xml.

Returns:

  • (String)

    XML for text shape for ppt/slides/slide0.xml



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pptx_markdown/shape.rb', line 31

def to_xml(node)
  Nokogiri::XML::Builder.new do |xml|
    xml.sp(XML_NAMESPACES) do
      xml.nvSpPr do
        xml.cNvPr(id: '', name: '')
        xml.cNvSpPr(txBox: 1)
        xml.nvPr do
          xml.ph(idx: nil, type: type)
        end
      end
      xml.spPr do
        xml['a'].xfrm do
          xml.off(x: node.x, y: node.y)
          xml.ext(cx: node.cx, cy: node.cy)
        end
        xml['a'].prstGeom(prst: 'rect') do
          xml.avLst
        end
      end

      xml.txBody do
        xml['a'].bodyPr(anchorCtr: 0, anchor: 't', bIns: 0, lIns: 0, rIns: 0, tIns: 0) do
          xml.noAutofit
        end
        xml['a'].lstStyle
        xml['a'].p do
          xml.pPr(lvl: 0) do
            xml.spcBef do
              xml.spcPts(val: 0)
            end
            xml.buNone
          end
          xml.r do
            xml.t(content)
          end
        end
      end
    end
  end.doc.root.to_xml
end