ooxml_parser 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +17 -1
  3. data/lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content/chart_style.rb +4 -0
  4. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb +1 -0
  5. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_axis.rb +9 -0
  6. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_axis/scaling.rb +20 -0
  7. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb +1 -1
  8. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb +3 -2
  9. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_body_properties/ooxml_shape_body_properties.rb +8 -0
  10. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties/text_box.rb +1 -1
  11. data/lib/ooxml_parser/common_parser/common_data/borders_properties.rb +2 -2
  12. data/lib/ooxml_parser/common_parser/common_data/color.rb +11 -20
  13. data/lib/ooxml_parser/common_parser/common_data/color/color_helper.rb +1 -1
  14. data/lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb +57 -0
  15. data/lib/ooxml_parser/common_parser/common_data/colors/theme_colors.rb +3 -6
  16. data/lib/ooxml_parser/common_parser/common_data/coordinates.rb +17 -1
  17. data/lib/ooxml_parser/common_parser/common_data/hyperlink.rb +12 -1
  18. data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +4 -4
  19. data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object/ooxml_document_object_helper.rb +30 -1
  20. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb +5 -2
  21. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb +9 -1
  22. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties.rb +1 -1
  23. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/text.rb +23 -0
  24. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/paragraph_borders.rb +2 -2
  25. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb +0 -1
  26. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/tabs.rb +2 -2
  27. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/{tab_list/presentation_tab.rb → tabs/tab.rb} +17 -4
  28. data/lib/ooxml_parser/common_parser/common_data/table.rb +1 -1
  29. data/lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb +1 -3
  30. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style.rb +31 -37
  31. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_properties.rb +4 -0
  32. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_properties/table_style_properties_helper.rb +2 -2
  33. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell.rb +4 -4
  34. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/border.rb +1 -1
  35. data/lib/ooxml_parser/common_parser/common_data/table/table_properties.rb +1 -16
  36. data/lib/ooxml_parser/docx_parser/docx_data/document_structure.rb +14 -7
  37. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comment.rb +2 -2
  38. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comments_extended.rb +39 -0
  39. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comments_extended/comment_extended.rb +24 -0
  40. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb +9 -12
  41. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb +1 -1
  42. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph.rb +51 -73
  43. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/delimeter.rb +2 -2
  44. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_helper.rb +8 -0
  45. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb +8 -56
  46. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/docx_paragraph_run_helpers.rb +2 -12
  47. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/inserted.rb +15 -1
  48. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb +30 -0
  49. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_properties.rb +28 -0
  50. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/structured_document_tag.rb +26 -0
  51. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb +1 -1
  52. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb +10 -10
  53. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_margins.rb +9 -16
  54. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb +11 -9
  55. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation.rb +5 -2
  56. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme/theme_color.rb +1 -3
  57. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb +35 -24
  58. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/common_slide_data.rb +26 -0
  59. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/common_slide_data/shape_tree.rb +33 -0
  60. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/connection_shape.rb +5 -0
  61. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/graphic_frame/graphic_frame.rb +2 -0
  62. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/presentation_notes.rb +21 -0
  63. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/shapes_grouping.rb +2 -0
  64. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb +3 -3
  65. data/lib/ooxml_parser/version.rb +1 -1
  66. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb +1 -1
  67. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill.rb +20 -0
  68. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill/pattern_fill.rb +2 -2
  69. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb +5 -1
  70. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb +10 -1
  71. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/ole_objects.rb +18 -0
  72. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view.rb +1 -1
  73. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part.rb +7 -1
  74. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/autofilter.rb +34 -0
  75. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/autofilter/filter_column.rb +28 -0
  76. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension.rb +5 -0
  77. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/sparkline_groups.rb +31 -0
  78. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/sparkline_groups/sparkline_group.rb +113 -0
  79. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/table_style_info.rb +41 -0
  80. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing.rb +5 -11
  81. metadata +31 -14
  82. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/tab_list.rb +0 -36
  83. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/tabs/paragraph_tab.rb +0 -26
@@ -61,21 +61,11 @@ module OoxmlParser
61
61
  unless node_child.attribute('fill').value == 'auto' || node_child.attribute('fill').value == '' || node_child.attribute('fill').value == 'null'
62
62
  self.background_color = Color.new(parent: self).parse_hex_string(node_child.attribute('fill').value)
63
63
  end
64
- when 'uCs'
64
+ when 'u', 'uCs'
65
65
  font_style.underlined = Underline.new
66
66
  if option_enabled?(node_child)
67
67
  font_style.underlined.style = node_child.attribute('val').value
68
- unless node_child.attribute('color').nil?
69
- font_style.underlined.color = Color.new(parent: font_style.underlined).parse_hex_string(node_child.attribute('color').value)
70
- end
71
- end
72
- when 'u'
73
- font_style.underlined = Underline.new
74
- if option_enabled?(node_child)
75
- font_style.underlined.style = node_child.attribute('val').value
76
- unless node_child.attribute('color').nil?
77
- font_style.underlined.color = Color.new(parent: font_style.underlined).parse_hex_string(node_child.attribute('color').value)
78
- end
68
+ font_style.underlined.color = Color.new(parent: font_style.underlined).parse_hex_string(node_child.attribute('color').value) unless node_child.attribute('color').nil?
79
69
  end
80
70
  when 'strike'
81
71
  font_style.strike = :single if option_enabled?(node_child)
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  module OoxmlParser
2
4
  # Class for parsing `w:ins` tag - Inserted Run Content
3
5
  class Inserted < OOXMLDocumentObject
@@ -23,7 +25,7 @@ module OoxmlParser
23
25
  when 'author'
24
26
  @author = value.value.to_s
25
27
  when 'date'
26
- @date = DateTime.parse(value.value.to_s)
28
+ @date = parse_date(value.value.to_s)
27
29
  when 'oouserid'
28
30
  @user_id = value.value.to_s
29
31
  end
@@ -37,5 +39,17 @@ module OoxmlParser
37
39
  end
38
40
  self
39
41
  end
42
+
43
+ private
44
+
45
+ # Parse date and handle incorrect dates
46
+ # @param value [Sting] value of date
47
+ # @return [DateTime, String] if date correct or incorrect
48
+ def parse_date(value)
49
+ DateTime.parse(value)
50
+ rescue ArgumentError
51
+ warn "Date #{value} is incorrect format"
52
+ value
53
+ end
40
54
  end
41
55
  end
@@ -0,0 +1,30 @@
1
+ module OoxmlParser
2
+ # Class for parsing `w:w:sdtContent` tags
3
+ class SDTContent < OOXMLDocumentObject
4
+ # @return [Array, ParagraphRun] runs of sdt
5
+ attr_reader :runs
6
+ # @return [Array, ParagraphRun] paragraphs of sdt
7
+ attr_reader :paragraphs
8
+
9
+ def initialize(parent: nil)
10
+ @runs = []
11
+ @paragraphs = []
12
+ @parent = parent
13
+ end
14
+
15
+ # Parse SDTContent object
16
+ # @param node [Nokogiri::XML:Element] node to parse
17
+ # @return [SDTContent] result of parsing
18
+ def parse(node)
19
+ node.xpath('*').each do |node_child|
20
+ case node_child.name
21
+ when 'p'
22
+ @paragraphs << DocxParagraph.new(parent: self).parse(node_child)
23
+ when 'r'
24
+ @runs << ParagraphRun.new(parent: self).parse(node_child)
25
+ end
26
+ end
27
+ self
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ module OoxmlParser
2
+ # Class for parsing `w:sdtPr` tags
3
+ class SDTProperties < OOXMLDocumentObject
4
+ # @return [ValuedChild] alias value
5
+ attr_reader :alias
6
+ # @return [ValuedChild] tag value
7
+ attr_reader :tag
8
+ # @return [ValuedChild] Locking Setting
9
+ attr_reader :lock
10
+
11
+ # Parse SDTProperties object
12
+ # @param node [Nokogiri::XML:Element] node to parse
13
+ # @return [SDTProperties] result of parsing
14
+ def parse(node)
15
+ node.xpath('*').each do |node_child|
16
+ case node_child.name
17
+ when 'alias'
18
+ @alias = ValuedChild.new(:string, parent: self).parse(node_child)
19
+ when 'tag'
20
+ @tag = ValuedChild.new(:string, parent: self).parse(node_child)
21
+ when 'lock'
22
+ @lock = ValuedChild.new(:symbol, parent: self).parse(node_child)
23
+ end
24
+ end
25
+ self
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'sdt/sdt_content'
2
+ require_relative 'sdt/sdt_properties'
3
+ module OoxmlParser
4
+ # Class for parsing `w:std`
5
+ class StructuredDocumentTag < OOXMLDocumentObject
6
+ # @return [SDTContent] content of sdt
7
+ attr_reader :sdt_content
8
+ # @return [SDTProperties] properties of sdt
9
+ attr_reader :properties
10
+
11
+ # Parse StructuredDocumentTag object
12
+ # @param node [Nokogiri::XML:Element] node to parse
13
+ # @return [StructuredDocumentTag] result of parsing
14
+ def parse(node)
15
+ node.xpath('*').each do |node_child|
16
+ case node_child.name
17
+ when 'sdtContent'
18
+ @sdt_content = SDTContent.new(parent: self).parse(node_child)
19
+ when 'sdtPr'
20
+ @properties = SDTProperties.new(parent: self).parse(node_child)
21
+ end
22
+ end
23
+ self
24
+ end
25
+ end
26
+ end
@@ -46,7 +46,7 @@ module OoxmlParser
46
46
  next unless footnote.attribute('id').value.to_i == @id
47
47
  paragraph_number = 0
48
48
  footnote.xpath('w:p').each do |paragraph|
49
- @elements << DocumentStructure.default_paragraph_style.copy.parse(paragraph, paragraph_number, DocumentStructure.default_run_style, parent: self)
49
+ @elements << DocumentStructure.default_paragraph_style.dup.parse(paragraph, paragraph_number, DocumentStructure.default_run_style, parent: self)
50
50
  paragraph_number += 1
51
51
  end
52
52
  end
@@ -6,15 +6,15 @@ module OoxmlParser
6
6
  @elements = []
7
7
  end
8
8
 
9
- def self.parse(default_paragraph, default_character, target, assigned_to, type, parent: nil)
9
+ def self.parse(params)
10
10
  note = Note.new
11
- note.type = type
12
- note.assigned_to = assigned_to
13
- note.parent = parent
14
- doc = Nokogiri::XML(File.open(OOXMLDocumentObject.path_to_folder + "word/#{target}"))
15
- if type.include?('footer')
11
+ note.type = params[:type]
12
+ note.assigned_to = params[:assigned_to]
13
+ note.parent = params[:parent]
14
+ doc = Nokogiri::XML(File.open(OOXMLDocumentObject.path_to_folder + "word/#{params[:target]}"))
15
+ if note.type.include?('footer')
16
16
  xpath_note = '//w:ftr'
17
- elsif type.include?('header')
17
+ elsif note.type.include?('header')
18
18
  xpath_note = '//w:hdr'
19
19
  else
20
20
  raise "Cannot parse unknown Note type: #{type}"
@@ -23,19 +23,19 @@ module OoxmlParser
23
23
  number = 0
24
24
  ftr.xpath('*').each do |sub_element|
25
25
  if sub_element.name == 'p'
26
- note.elements << default_paragraph.copy.parse(sub_element, number, default_character, parent: note)
26
+ note.elements << params[:default_paragraph].dup.parse(sub_element, number, params[:default_character], parent: note)
27
27
  number += 1
28
28
  elsif sub_element.name == 'tbl'
29
29
  note.elements << Table.new(parent: note).parse(sub_element, number)
30
30
  number += 1
31
31
  elsif sub_element.name == 'std'
32
32
  sub_element.xpath('w:p').each do |p|
33
- note.elements << default_paragraph.copy.parse(p, number, default_character)
33
+ note.elements << params[:default_paragraph].copy.parse(p, number, params[:default_character])
34
34
  number += 1
35
35
  end
36
36
  sub_element.xpath('w:sdtContent').each do |sdt_content|
37
37
  sdt_content.xpath('w:p').each do |p|
38
- note.elements << default_paragraph.copy.parse(p, number, default_character)
38
+ note.elements << params[:default_paragraph].copy.parse(p, number, params[:default_character])
39
39
  number += 1
40
40
  end
41
41
  end
@@ -3,22 +3,15 @@ module OoxmlParser
3
3
  class PageMargins < OOXMLDocumentObject
4
4
  attr_accessor :top, :bottom, :left, :right, :footer, :gutter, :header
5
5
 
6
- def initialize(top: nil,
7
- bottom: nil,
8
- left: nil,
9
- right: nil,
10
- header: nil,
11
- footer: nil,
12
- gutter: nil,
13
- parent: nil)
14
- @top = top
15
- @bottom = bottom
16
- @left = left
17
- @right = right
18
- @header = header
19
- @footer = footer
20
- @gutter = gutter
21
- @parent = parent
6
+ def initialize(params)
7
+ @top = params[:top]
8
+ @bottom = params[:bottom]
9
+ @left = params[:left]
10
+ @right = params[:right]
11
+ @header = params[:header]
12
+ @footer = params[:footer]
13
+ @gutter = params[:gutter]
14
+ @parent = params[:parent]
22
15
  end
23
16
 
24
17
  # Parse BordersProperties
@@ -10,6 +10,8 @@ module OoxmlParser
10
10
  :notes
11
11
  # @return [FootnoteProperties] properties of footnote
12
12
  attr_accessor :footnote_properties
13
+ # @return [True, False] Specifies whether the section should have a different header and footer for its first page
14
+ attr_reader :title_page
13
15
 
14
16
  def initialize(parent: nil)
15
17
  @notes = []
@@ -26,12 +28,8 @@ module OoxmlParser
26
28
  @size = PageSize.new.parse(pg_size_subnode)
27
29
  when 'pgBorders'
28
30
  page_borders = Borders.new
29
- unless pg_size_subnode.attribute('display').nil?
30
- page_borders.display = pg_size_subnode.attribute('display').value.to_sym
31
- end
32
- unless pg_size_subnode.attribute('offsetFrom').nil?
33
- page_borders.offset_from = pg_size_subnode.attribute('offsetFrom').value.to_sym
34
- end
31
+ page_borders.display = pg_size_subnode.attribute('display').value.to_sym unless pg_size_subnode.attribute('display').nil?
32
+ page_borders.offset_from = pg_size_subnode.attribute('offsetFrom').value.to_sym unless pg_size_subnode.attribute('offsetFrom').nil?
35
33
  pg_size_subnode.xpath('w:bottom').each do |bottom|
36
34
  page_borders.bottom = BordersProperties.new(parent: page_borders).parse(bottom)
37
35
  end
@@ -57,14 +55,18 @@ module OoxmlParser
57
55
  @text_direction = pg_size_subnode.attribute('val').value
58
56
  when 'docGrid'
59
57
  @document_grid = DocumentGrid.new(parent: self).parse(pg_size_subnode)
58
+ when 'titlePg'
59
+ @title_page = option_enabled?(pg_size_subnode)
60
60
  when 'cols'
61
61
  @columns = Columns.new.parse(pg_size_subnode)
62
62
  when 'headerReference', 'footerReference'
63
63
  target = OOXMLDocumentObject.get_link_from_rels(pg_size_subnode.attribute('id').value)
64
64
  OOXMLDocumentObject.add_to_xmls_stack("word/#{target}")
65
- note = Note.parse(default_paragraph, default_character, target,
66
- pg_size_subnode.attribute('type').value,
67
- File.basename(target).sub('.xml', ''),
65
+ note = Note.parse(default_paragraph: default_paragraph,
66
+ default_character: default_character,
67
+ target: target,
68
+ assigned_to: pg_size_subnode.attribute('type').value,
69
+ type: File.basename(target).sub('.xml', ''),
68
70
  parent: self)
69
71
  @notes << note
70
72
  OOXMLDocumentObject.xmls_stack.pop
@@ -7,6 +7,8 @@ module OoxmlParser
7
7
  class Presentation < CommonDocumentStructure
8
8
  include PresentationHelpers
9
9
  attr_accessor :slides, :theme, :slide_size, :comments
10
+ # @return [Relationships] relationships of presentation
11
+ attr_accessor :relationships
10
12
 
11
13
  def initialize(slides = [], theme = nil, comments = [])
12
14
  @slides = slides
@@ -32,18 +34,19 @@ module OoxmlParser
32
34
  silde_id_node.attribute_nodes.select { |node| id = node.to_s if node.namespace && node.namespace.prefix == 'r' }
33
35
  presentation.slides << Slide.new(parent: presentation,
34
36
  xml_path: "#{OOXMLDocumentObject.root_subfolder}/#{OOXMLDocumentObject.get_link_from_rels(id)}")
35
- .parse
37
+ .parse
36
38
  end
37
39
  end
38
40
  end
39
41
  presentation.comments = PresentationComment.parse_list
40
42
  OOXMLDocumentObject.xmls_stack.pop
43
+ presentation.relationships = Relationships.parse_rels("#{OOXMLDocumentObject.path_to_folder}/ppt/_rels/presentation.xml.rels")
41
44
  presentation
42
45
  end
43
46
 
44
47
  class << self
45
48
  # @return [FontStyle] current font_style
46
- attr_accessor :current_font_style
49
+ attr_writer :current_font_style
47
50
 
48
51
  def current_font_style
49
52
  @current_font_style = FontStyle.new if @current_font_style.nil?
@@ -14,9 +14,7 @@ module OoxmlParser
14
14
  else
15
15
  all_instance_variables = instance_variables
16
16
  all_instance_variables.each do |current_attributes|
17
- unless instance_variable_get(current_attributes) == other.instance_variable_get(current_attributes)
18
- return false
19
- end
17
+ return false unless instance_variable_get(current_attributes) == other.instance_variable_get(current_attributes)
20
18
  end
21
19
  true
22
20
  end
@@ -1,5 +1,8 @@
1
1
  require_relative 'slide/presentation_alternate_content'
2
2
  require_relative 'slide/background'
3
+ require_relative 'slide/common_slide_data'
4
+ require_relative 'slide/connection_shape.rb'
5
+ require_relative 'slide/presentation_notes.rb'
3
6
  require_relative 'slide/graphic_frame/graphic_frame'
4
7
  require_relative 'slide/slide/shapes_grouping'
5
8
  require_relative 'slide/slide/timing'
@@ -8,50 +11,47 @@ module OoxmlParser
8
11
  # Class for parsing `slide.xml`
9
12
  class Slide < OOXMLDocumentObject
10
13
  include SlideHelper
11
- attr_accessor :elements, :background, :transition, :timing, :alternate_content
14
+ attr_accessor :transition, :timing, :alternate_content
15
+ # @return [CommonSlideData] common slide data
16
+ attr_reader :common_slide_data
17
+ # @return [Relationships] relationships of slide
18
+ attr_reader :relationships
19
+ # @return [String] name of slide
20
+ attr_reader :name
21
+ # @return [Notes] note of slide
22
+ attr_reader :note
12
23
 
13
24
  def initialize(parent: nil, xml_path: nil)
14
- @elements = []
15
- @background = nil
16
25
  @parent = parent
17
26
  @xml_path = xml_path
18
27
  end
19
28
 
20
29
  def with_data?
21
- return true unless @background.nil?
22
- @elements.each do |current_element|
30
+ return true unless background.nil?
31
+ elements.each do |current_element|
23
32
  return true if current_element.with_data?
24
33
  end
25
34
  false
26
35
  end
27
36
 
37
+ def elements
38
+ @common_slide_data.shape_tree.elements
39
+ end
40
+
41
+ def background
42
+ @common_slide_data.background
43
+ end
44
+
28
45
  # Parse Slide object
29
46
  # @return [Slide] result of parsing
30
47
  def parse
31
48
  OOXMLDocumentObject.add_to_xmls_stack(@xml_path)
49
+ @name = File.basename(@xml_path, '.*')
32
50
  node = Nokogiri::XML(File.open(OOXMLDocumentObject.current_xml))
33
51
  node.xpath('//p:sld/*').each do |node_child|
34
52
  case node_child.name
35
53
  when 'cSld'
36
- node_child.xpath('*').each do |common_slide_node_child|
37
- case common_slide_node_child.name
38
- when 'spTree'
39
- common_slide_node_child.xpath('*').each do |slide_element_node|
40
- case slide_element_node.name
41
- when 'sp'
42
- @elements << DocxShape.new(parent: self).parse(slide_element_node).dup
43
- when 'pic'
44
- @elements << DocxPicture.new(parent: self).parse(slide_element_node)
45
- when 'graphicFrame'
46
- @elements << GraphicFrame.new(parent: self).parse(slide_element_node)
47
- when 'grpSp'
48
- @elements << ShapesGrouping.new(parent: self).parse(slide_element_node)
49
- end
50
- end
51
- when 'bg'
52
- @background = Background.new(parent: self).parse(common_slide_node_child)
53
- end
54
- end
54
+ @common_slide_data = CommonSlideData.new(parent: self).parse(node_child)
55
55
  when 'timing'
56
56
  @timing = Timing.new(parent: self).parse(node_child)
57
57
  when 'transition'
@@ -61,7 +61,18 @@ module OoxmlParser
61
61
  end
62
62
  end
63
63
  OOXMLDocumentObject.xmls_stack.pop
64
+ @relationships = Relationships.parse_rels("#{OOXMLDocumentObject.path_to_folder}#{File.dirname(@xml_path)}/_rels/#{@name}.xml.rels")
65
+ parse_note
64
66
  self
65
67
  end
68
+
69
+ private
70
+
71
+ # Parse slide notes if present
72
+ def parse_note
73
+ notes_target = @relationships.target_by_type('notes')
74
+ return nil unless notes_target
75
+ @note = PresentationNotes.new(parent: self).parse("#{OOXMLDocumentObject.path_to_folder}#{File.dirname(@xml_path)}/#{notes_target}")
76
+ end
66
77
  end
67
78
  end
@@ -0,0 +1,26 @@
1
+ require_relative 'common_slide_data/shape_tree'
2
+
3
+ module OoxmlParser
4
+ # Class for parsing `cSld` tag
5
+ class CommonSlideData < OOXMLDocumentObject
6
+ # @return [ShapeTree] tree of shape
7
+ attr_reader :shape_tree
8
+ # @return [Background] background
9
+ attr_reader :background
10
+
11
+ # Parse CommonSlideData object
12
+ # @param node [Nokogiri::XML:Element] node to parse
13
+ # @return [CommonSlideData] result of parsing
14
+ def parse(node)
15
+ node.xpath('*').each do |node_child|
16
+ case node_child.name
17
+ when 'spTree'
18
+ @shape_tree = ShapeTree.new(parent: self).parse(node_child)
19
+ when 'bg'
20
+ @background = Background.new(parent: self).parse(node_child)
21
+ end
22
+ end
23
+ self
24
+ end
25
+ end
26
+ end