ooxml_parser 0.27.0 → 0.30.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb +4 -4
  3. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/docx_graphic.rb +2 -2
  4. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb +16 -3
  5. data/lib/ooxml_parser/common_parser/common_data/content_types.rb +1 -1
  6. data/lib/ooxml_parser/common_parser/common_data/hyperlink.rb +3 -3
  7. data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +2 -91
  8. data/lib/ooxml_parser/common_parser/common_document_structure.rb +38 -0
  9. data/lib/ooxml_parser/common_parser/parser/ooxml_file.rb +68 -0
  10. data/lib/ooxml_parser/common_parser/parser.rb +32 -38
  11. data/lib/ooxml_parser/docx_parser/document_structure/comments.rb +1 -1
  12. data/lib/ooxml_parser/docx_parser/document_structure/comments_extended.rb +1 -1
  13. data/lib/ooxml_parser/docx_parser/document_structure/document_properties.rb +1 -1
  14. data/lib/ooxml_parser/docx_parser/document_structure/document_settings.rb +1 -1
  15. data/lib/ooxml_parser/docx_parser/document_structure/document_style.rb +8 -2
  16. data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb +7 -18
  17. data/lib/ooxml_parser/docx_parser/document_structure/header_footer.rb +1 -1
  18. data/lib/ooxml_parser/docx_parser/document_structure/numbering.rb +1 -1
  19. data/lib/ooxml_parser/docx_parser/document_structure/page_properties/note.rb +2 -2
  20. data/lib/ooxml_parser/docx_parser/document_structure/page_properties/page_properties.rb +3 -3
  21. data/lib/ooxml_parser/docx_parser/document_structure/styles.rb +1 -1
  22. data/lib/ooxml_parser/docx_parser/document_structure.rb +34 -36
  23. data/lib/ooxml_parser/docx_parser.rb +3 -2
  24. data/lib/ooxml_parser/pptx_parser/presentation/comment_authors.rb +1 -1
  25. data/lib/ooxml_parser/pptx_parser/presentation/presentation_comments.rb +1 -1
  26. data/lib/ooxml_parser/pptx_parser/presentation/presentation_theme.rb +23 -23
  27. data/lib/ooxml_parser/pptx_parser/presentation/slide/graphic_frame/graphic_frame.rb +2 -2
  28. data/lib/ooxml_parser/pptx_parser/presentation/slide.rb +5 -5
  29. data/lib/ooxml_parser/pptx_parser/presentation/slide_layout_file.rb +2 -2
  30. data/lib/ooxml_parser/pptx_parser/presentation/slide_layouts_helper.rb +1 -1
  31. data/lib/ooxml_parser/pptx_parser/presentation/slide_master_file.rb +2 -2
  32. data/lib/ooxml_parser/pptx_parser/presentation/slide_masters_helper.rb +1 -1
  33. data/lib/ooxml_parser/pptx_parser/presentation/table_styles.rb +1 -1
  34. data/lib/ooxml_parser/pptx_parser/presentation.rb +7 -8
  35. data/lib/ooxml_parser/pptx_parser.rb +3 -2
  36. data/lib/ooxml_parser/version.rb +1 -1
  37. data/lib/ooxml_parser/xlsx_parser/workbook/chartsheet.rb +3 -3
  38. data/lib/ooxml_parser/xlsx_parser/workbook/pivot_cache.rb +1 -1
  39. data/lib/ooxml_parser/xlsx_parser/workbook/pivot_table_definition.rb +1 -1
  40. data/lib/ooxml_parser/xlsx_parser/workbook/style_sheet.rb +1 -1
  41. data/lib/ooxml_parser/xlsx_parser/workbook/worksheet/table_part.rb +2 -2
  42. data/lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb +11 -11
  43. data/lib/ooxml_parser/xlsx_parser/workbook.rb +7 -8
  44. data/lib/ooxml_parser/xlsx_parser.rb +3 -2
  45. metadata +4 -4
  46. data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/style_parametres.rb +0 -30
@@ -44,7 +44,7 @@ module OoxmlParser
44
44
  # @return [CommentsExtended] extended comments
45
45
  attr_accessor :comments_extended
46
46
 
47
- def initialize
47
+ def initialize(params = {})
48
48
  @elements = []
49
49
  @notes = []
50
50
  @document_properties = DocumentProperties.new
@@ -156,67 +156,65 @@ module OoxmlParser
156
156
 
157
157
  # Parse docx file
158
158
  # @return [DocumentStructure] parsed structure
159
- def self.parse
160
- doc_structure = DocumentStructure.new
161
- doc_structure.content_types = ContentTypes.new(parent: doc_structure).parse
162
- OOXMLDocumentObject.root_subfolder = 'word/'
163
- OOXMLDocumentObject.xmls_stack = []
159
+ def parse
160
+ @content_types = ContentTypes.new(parent: self).parse
161
+ @root_subfolder = 'word/'
164
162
  @comments = []
165
163
  DocumentStructure.default_paragraph_style = DocxParagraph.new
166
- DocumentStructure.default_run_style = DocxParagraphRun.new(parent: doc_structure)
167
- doc_structure.theme = PresentationTheme.parse('word/theme/theme1.xml')
168
- doc_structure.relationships = Relationships.new(parent: self).parse_file("#{OOXMLDocumentObject.path_to_folder}word/_rels/document.xml.rels")
169
- doc_structure.parse_styles
164
+ DocumentStructure.default_run_style = DocxParagraphRun.new(parent: self)
165
+ @theme = PresentationTheme.new(parent: self).parse('word/theme/theme1.xml')
166
+ @relationships = Relationships.new(parent: self).parse_file("#{root_object.unpacked_folder}word/_rels/document.xml.rels")
167
+ parse_styles
170
168
  number = 0
171
- OOXMLDocumentObject.add_to_xmls_stack('word/document.xml')
172
- doc = doc_structure.parse_xml(OOXMLDocumentObject.current_xml)
169
+ root_object.add_to_xmls_stack('word/document.xml')
170
+ doc = parse_xml(root_object.current_xml)
173
171
  doc.search('//w:document').each do |document|
174
172
  document.xpath('w:background').each do |background|
175
- doc_structure.background = DocumentBackground.new(parent: doc_structure).parse(background)
173
+ @background = DocumentBackground.new(parent: self).parse(background)
176
174
  end
177
175
  document.xpath('w:body').each do |body|
178
176
  body.xpath('*').each do |element|
179
177
  case element.name
180
178
  when 'p'
181
179
  child = element.child
182
- unless child.nil? && doc_structure.elements.last.instance_of?(Table)
183
- paragraph_style = DocumentStructure.default_paragraph_style.dup.parse(element, number, DocumentStructure.default_run_style, parent: doc_structure)
180
+ unless child.nil? && @elements.last.instance_of?(Table)
181
+ paragraph_style = DocumentStructure.default_paragraph_style.dup.parse(element, number, DocumentStructure.default_run_style, parent: self)
184
182
  number += 1
185
- doc_structure.elements << paragraph_style.dup
183
+ @elements << paragraph_style.dup
186
184
  end
187
185
  when 'tbl'
188
- table = Table.new(parent: doc_structure).parse(element,
189
- number,
190
- TableProperties.new)
186
+ table = Table.new(parent: self).parse(element,
187
+ number,
188
+ TableProperties.new)
191
189
  number += 1
192
- doc_structure.elements << table
190
+ @elements << table
193
191
  when 'sdt'
194
- doc_structure.elements << StructuredDocumentTag.new(parent: doc_structure).parse(element)
192
+ @elements << StructuredDocumentTag.new(parent: self).parse(element)
195
193
  end
196
194
  end
197
195
  body.xpath('w:sectPr').each do |sect_pr|
198
- doc_structure.page_properties = PageProperties.new(parent: doc_structure).parse(sect_pr,
199
- DocumentStructure.default_paragraph_style,
200
- DocumentStructure.default_run_style)
201
- doc_structure.notes = doc_structure.page_properties.notes # keep copy of notes to compatibility with previous docx models
196
+ @page_properties = PageProperties.new(parent: self).parse(sect_pr,
197
+ DocumentStructure.default_paragraph_style,
198
+ DocumentStructure.default_run_style)
199
+ @notes = page_properties.notes # keep copy of notes to compatibility with previous docx models
202
200
  end
203
201
  end
204
202
  end
205
- OOXMLDocumentObject.xmls_stack.pop
206
- doc_structure.document_properties = DocumentProperties.new(parent: doc_structure).parse
207
- doc_structure.comments = Comments.new(parent: doc_structure).parse
208
- doc_structure.comments_extended = CommentsExtended.new(parent: doc_structure).parse
209
- doc_structure.comments_document = Comments.new(parent: doc_structure,
210
- file: "#{OOXMLDocumentObject.path_to_folder}word/#{doc_structure.relationships.target_by_type('commentsDocument').first}")
211
- .parse
212
- doc_structure.settings = DocumentSettings.new(parent: doc_structure).parse
213
- doc_structure
203
+ root_object.xmls_stack.pop
204
+ @document_properties = DocumentProperties.new(parent: self).parse
205
+ @comments = Comments.new(parent: self).parse
206
+ @comments_extended = CommentsExtended.new(parent: self).parse
207
+ @comments_document = Comments.new(parent: self,
208
+ file: "#{root_object.unpacked_folder}word/#{relationships.target_by_type('commentsDocument').first}")
209
+ .parse
210
+ @settings = DocumentSettings.new(parent: self).parse
211
+ self
214
212
  end
215
213
 
216
214
  # Parse default style
217
215
  # @return [void]
218
216
  def parse_default_style
219
- doc = parse_xml("#{OOXMLDocumentObject.path_to_folder}word/styles.xml")
217
+ doc = parse_xml("#{root_object.unpacked_folder}word/styles.xml")
220
218
  doc.search('//w:style').each do |style|
221
219
  next if style.attribute('default').nil?
222
220
 
@@ -257,7 +255,7 @@ module OoxmlParser
257
255
 
258
256
  # Perform parsing styles.xml
259
257
  def parse_styles
260
- file = "#{OOXMLDocumentObject.path_to_folder}/word/styles.xml"
258
+ file = "#{root_object.unpacked_folder}/word/styles.xml"
261
259
  DocumentStructure.default_paragraph_style = DocxParagraph.new(parent: self)
262
260
  DocumentStructure.default_table_paragraph_style = DocxParagraph.new(parent: self)
263
261
  DocumentStructure.default_run_style = DocxParagraphRun.new(parent: self)
@@ -10,8 +10,9 @@ module OoxmlParser
10
10
  # @param path_to_file [String] file path
11
11
  # @return [DocumentStructure] result of parse
12
12
  def self.parse_docx(path_to_file)
13
- Parser.parse_format(path_to_file) do
14
- DocumentStructure.parse
13
+ file = OoxmlFile.new(path_to_file)
14
+ Parser.parse_format(file) do |yielded_file|
15
+ DocumentStructure.new(unpacked_folder: yielded_file.path_to_folder).parse
15
16
  end
16
17
  end
17
18
  end
@@ -15,7 +15,7 @@ module OoxmlParser
15
15
  # Parse CommentAuthors object
16
16
  # @param file [Nokogiri::XML:Element] node to parse
17
17
  # @return [CommentAuthors] result of parsing
18
- def parse(file = "#{OOXMLDocumentObject.path_to_folder}/#{OOXMLDocumentObject.root_subfolder}/commentAuthors.xml")
18
+ def parse(file = "#{root_object.unpacked_folder}/#{root_object.root_subfolder}/commentAuthors.xml")
19
19
  return nil unless File.exist?(file)
20
20
 
21
21
  document = parse_xml(File.open(file))
@@ -15,7 +15,7 @@ module OoxmlParser
15
15
  # Parse PresentationComments object
16
16
  # @param file [Nokogiri::XML:Element] node to parse
17
17
  # @return [PresentationComments] result of parsing
18
- def parse(file = "#{OOXMLDocumentObject.path_to_folder}/#{OOXMLDocumentObject.root_subfolder}/comments/comment1.xml")
18
+ def parse(file = "#{root_object.unpacked_folder}/#{root_object.root_subfolder}/comments/comment1.xml")
19
19
  return nil unless File.exist?(file)
20
20
 
21
21
  document = parse_xml(File.open(file))
@@ -9,46 +9,46 @@ module OoxmlParser
9
9
  # @return [FontScheme] font scheme
10
10
  attr_accessor :font_scheme
11
11
 
12
- def initialize(name = '', color_scheme = {})
13
- @name = name
14
- @color_scheme = color_scheme
15
- super(parent: nil)
12
+ def initialize(parent: nil)
13
+ @name = ''
14
+ @color_scheme = {}
15
+ super
16
16
  end
17
17
 
18
18
  # Parse PresentationTheme
19
19
  # @param file [String] path to file to parse
20
20
  # @return [PresentationTheme] result of parsing
21
- def self.parse(file)
22
- OOXMLDocumentObject.theme = PresentationTheme.new
23
- OOXMLDocumentObject.add_to_xmls_stack(file)
24
- unless File.exist?(OOXMLDocumentObject.current_xml)
25
- OOXMLDocumentObject.xmls_stack.pop
21
+ def parse(file)
22
+ root_object.add_to_xmls_stack(file)
23
+ unless File.exist?(root_object.current_xml)
24
+ root_object.xmls_stack.pop
26
25
  return
27
26
  end
28
- doc = OOXMLDocumentObject.theme.parse_xml(OOXMLDocumentObject.current_xml)
27
+ doc = parse_xml(root_object.current_xml)
28
+
29
29
  doc.xpath('a:theme').each do |theme_node|
30
- OOXMLDocumentObject.theme.name = theme_node.attribute('name').value if theme_node.attribute('name')
30
+ @name = theme_node.attribute('name').value if theme_node.attribute('name')
31
31
  theme_node.xpath('a:themeElements/*').each do |theme_element_node|
32
32
  case theme_element_node.name
33
33
  when 'clrScheme'
34
34
  theme_element_node.xpath('*').each do |color_scheme_element|
35
- OOXMLDocumentObject.theme.color_scheme[color_scheme_element.name.to_sym] = ThemeColor.new.parse(color_scheme_element)
35
+ @color_scheme[color_scheme_element.name.to_sym] = ThemeColor.new.parse(color_scheme_element)
36
36
  end
37
- OOXMLDocumentObject.theme.color_scheme[:background1] = OOXMLDocumentObject.theme.color_scheme[:lt1]
38
- OOXMLDocumentObject.theme.color_scheme[:background2] = OOXMLDocumentObject.theme.color_scheme[:lt2]
39
- OOXMLDocumentObject.theme.color_scheme[:bg1] = OOXMLDocumentObject.theme.color_scheme[:lt1]
40
- OOXMLDocumentObject.theme.color_scheme[:bg2] = OOXMLDocumentObject.theme.color_scheme[:lt2]
41
- OOXMLDocumentObject.theme.color_scheme[:text1] = OOXMLDocumentObject.theme.color_scheme[:dk1]
42
- OOXMLDocumentObject.theme.color_scheme[:text2] = OOXMLDocumentObject.theme.color_scheme[:dk2]
43
- OOXMLDocumentObject.theme.color_scheme[:tx1] = OOXMLDocumentObject.theme.color_scheme[:dk1]
44
- OOXMLDocumentObject.theme.color_scheme[:tx2] = OOXMLDocumentObject.theme.color_scheme[:dk2]
37
+ @color_scheme[:background1] = @color_scheme[:lt1]
38
+ @color_scheme[:background2] = @color_scheme[:lt2]
39
+ @color_scheme[:bg1] = @color_scheme[:lt1]
40
+ @color_scheme[:bg2] = @color_scheme[:lt2]
41
+ @color_scheme[:text1] = @color_scheme[:dk1]
42
+ @color_scheme[:text2] = @color_scheme[:dk2]
43
+ @color_scheme[:tx1] = @color_scheme[:dk1]
44
+ @color_scheme[:tx2] = @color_scheme[:dk2]
45
45
  when 'fontScheme'
46
- OOXMLDocumentObject.theme.font_scheme = FontScheme.new(parent: self).parse(theme_element_node)
46
+ @font_scheme = FontScheme.new(parent: self).parse(theme_element_node)
47
47
  end
48
48
  end
49
49
  end
50
- OOXMLDocumentObject.xmls_stack.pop
51
- OOXMLDocumentObject.theme
50
+ root_object.xmls_stack.pop
51
+ self
52
52
  end
53
53
  end
54
54
  end
@@ -30,9 +30,9 @@ module OoxmlParser
30
30
  when 'tbl'
31
31
  graphic_data << Table.new(parent: self).parse(graphic_node_child)
32
32
  when 'chart'
33
- OOXMLDocumentObject.add_to_xmls_stack(OOXMLDocumentObject.get_link_from_rels(graphic_node_child.attribute('id').value))
33
+ root_object.add_to_xmls_stack(root_object.get_link_from_rels(graphic_node_child.attribute('id').value))
34
34
  graphic_data << Chart.new(parent: self).parse
35
- OOXMLDocumentObject.xmls_stack.pop
35
+ root_object.xmls_stack.pop
36
36
  when 'oleObj'
37
37
  graphic_data << OleObject.new(parent: self).parse(graphic_node_child)
38
38
  end
@@ -51,9 +51,9 @@ module OoxmlParser
51
51
  # Parse Slide object
52
52
  # @return [Slide] result of parsing
53
53
  def parse
54
- OOXMLDocumentObject.add_to_xmls_stack(@xml_path)
54
+ root_object.add_to_xmls_stack(@xml_path)
55
55
  @name = File.basename(@xml_path, '.*')
56
- node = parse_xml(OOXMLDocumentObject.current_xml)
56
+ node = parse_xml(root_object.current_xml)
57
57
  node.xpath('//p:sld/*').each do |node_child|
58
58
  case node_child.name
59
59
  when 'cSld'
@@ -66,8 +66,8 @@ module OoxmlParser
66
66
  @alternate_content = PresentationAlternateContent.new(parent: self).parse(node_child)
67
67
  end
68
68
  end
69
- OOXMLDocumentObject.xmls_stack.pop
70
- @relationships = Relationships.new(parent: self).parse_file("#{OOXMLDocumentObject.path_to_folder}#{File.dirname(@xml_path)}/_rels/#{@name}.xml.rels")
69
+ root_object.xmls_stack.pop
70
+ @relationships = Relationships.new(parent: self).parse_file("#{root_object.unpacked_folder}#{File.dirname(@xml_path)}/_rels/#{@name}.xml.rels")
71
71
  parse_note
72
72
  self
73
73
  end
@@ -79,7 +79,7 @@ module OoxmlParser
79
79
  notes_target = @relationships.target_by_type('notes')
80
80
  return nil if notes_target.empty?
81
81
 
82
- @note = PresentationNotes.new(parent: self).parse("#{OOXMLDocumentObject.path_to_folder}#{File.dirname(@xml_path)}/#{notes_target.first}")
82
+ @note = PresentationNotes.new(parent: self).parse("#{root_object.unpacked_folder}#{File.dirname(@xml_path)}/#{notes_target.first}")
83
83
  end
84
84
  end
85
85
  end
@@ -10,7 +10,7 @@ module OoxmlParser
10
10
  # @param file [String] path to file to parse
11
11
  # @return [SlideLayoutFile] result of parsing
12
12
  def parse(file)
13
- OOXMLDocumentObject.add_to_xmls_stack(file.gsub(OOXMLDocumentObject.path_to_folder, ''))
13
+ root_object.add_to_xmls_stack(file.gsub(root_object.unpacked_folder, ''))
14
14
  doc = parse_xml(file)
15
15
  doc.xpath('p:sldLayout/*').each do |node_child|
16
16
  case node_child.name
@@ -18,7 +18,7 @@ module OoxmlParser
18
18
  @common_slide_data = CommonSlideData.new(parent: self).parse(node_child)
19
19
  end
20
20
  end
21
- OOXMLDocumentObject.xmls_stack.pop
21
+ root_object.xmls_stack.pop
22
22
  self
23
23
  end
24
24
  end
@@ -5,7 +5,7 @@ module OoxmlParser
5
5
  module SlideLayoutsHelper
6
6
  # @return [Array<String>] list of slide layouts files
7
7
  def slide_layouts_files
8
- Dir["#{OOXMLDocumentObject.path_to_folder}ppt/slideLayouts/*.xml"]
8
+ Dir["#{root_object.unpacked_folder}ppt/slideLayouts/*.xml"]
9
9
  end
10
10
 
11
11
  private
@@ -10,7 +10,7 @@ module OoxmlParser
10
10
  # @param file [String] path to file to parse
11
11
  # @return [SlideMasterFile] result of parsing
12
12
  def parse(file)
13
- OOXMLDocumentObject.add_to_xmls_stack(file.gsub(OOXMLDocumentObject.path_to_folder, ''))
13
+ root_object.add_to_xmls_stack(file.gsub(root_object.unpacked_folder, ''))
14
14
  doc = parse_xml(file)
15
15
  doc.xpath('p:sldMaster/*').each do |node_child|
16
16
  case node_child.name
@@ -18,7 +18,7 @@ module OoxmlParser
18
18
  @common_slide_data = CommonSlideData.new(parent: self).parse(node_child)
19
19
  end
20
20
  end
21
- OOXMLDocumentObject.xmls_stack.pop
21
+ root_object.xmls_stack.pop
22
22
  self
23
23
  end
24
24
  end
@@ -5,7 +5,7 @@ module OoxmlParser
5
5
  module SlideMastersHelper
6
6
  # @return [Array<String>] list of slide masters files
7
7
  def slide_masters_files
8
- Dir["#{OOXMLDocumentObject.path_to_folder}ppt/slideMasters/*.xml"]
8
+ Dir["#{root_object.unpacked_folder}ppt/slideMasters/*.xml"]
9
9
  end
10
10
 
11
11
  private
@@ -14,7 +14,7 @@ module OoxmlParser
14
14
  # Parse TableStyles object
15
15
  # @param file [Nokogiri::XML:Element] node to parse
16
16
  # @return [TableStyles] result of parsing
17
- def parse(file = "#{OOXMLDocumentObject.path_to_folder}/#{OOXMLDocumentObject.root_subfolder}/tableStyles.xml")
17
+ def parse(file = "#{root_object.unpacked_folder}/#{root_object.root_subfolder}/tableStyles.xml")
18
18
  return nil unless File.exist?(file)
19
19
 
20
20
  document = parse_xml(file)
@@ -43,11 +43,10 @@ module OoxmlParser
43
43
  # @return [Presentation] parsed presentation
44
44
  def parse
45
45
  @content_types = ContentTypes.new(parent: self).parse
46
- OOXMLDocumentObject.root_subfolder = 'ppt/'
47
- OOXMLDocumentObject.xmls_stack = []
48
- OOXMLDocumentObject.add_to_xmls_stack('ppt/presentation.xml')
49
- doc = parse_xml(OOXMLDocumentObject.current_xml)
50
- @theme = PresentationTheme.parse('ppt/theme/theme1.xml')
46
+ @root_subfolder = 'ppt/'
47
+ root_object.add_to_xmls_stack('ppt/presentation.xml')
48
+ doc = parse_xml(root_object.current_xml)
49
+ @theme = PresentationTheme.new(parent: self).parse('ppt/theme/theme1.xml')
51
50
  @table_styles = TableStyles.new(parent: self).parse
52
51
  @comment_authors = CommentAuthors.new(parent: self).parse
53
52
  @comments = PresentationComments.new(parent: self).parse
@@ -60,13 +59,13 @@ module OoxmlParser
60
59
  presentation_node_child.xpath('p:sldId').each do |silde_id_node|
61
60
  slide_id = silde_id_node.attr('r:id')
62
61
  @slides << Slide.new(parent: self,
63
- xml_path: "#{OOXMLDocumentObject.root_subfolder}/#{OOXMLDocumentObject.get_link_from_rels(slide_id)}")
62
+ xml_path: "#{root_object.root_subfolder}/#{root_object.get_link_from_rels(slide_id)}")
64
63
  .parse
65
64
  end
66
65
  end
67
66
  end
68
- OOXMLDocumentObject.xmls_stack.pop
69
- @relationships = Relationships.new(parent: self).parse_file("#{OOXMLDocumentObject.path_to_folder}/ppt/_rels/presentation.xml.rels")
67
+ root_object.xmls_stack.pop
68
+ @relationships = Relationships.new(parent: self).parse_file("#{root_object.unpacked_folder}/ppt/_rels/presentation.xml.rels")
70
69
  parse_slide_layouts
71
70
  parse_slide_masters
72
71
  self
@@ -9,8 +9,9 @@ module OoxmlParser
9
9
  # @param path_to_file [String] file path
10
10
  # @return [Presentation] result of parse
11
11
  def self.parse_pptx(path_to_file)
12
- Parser.parse_format(path_to_file) do
13
- Presentation.new.parse
12
+ file = OoxmlFile.new(path_to_file)
13
+ Parser.parse_format(file) do |yielded_file|
14
+ Presentation.new(unpacked_folder: yielded_file.path_to_folder).parse
14
15
  end
15
16
  end
16
17
  end
@@ -4,6 +4,6 @@ module OoxmlParser
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
6
  # [String] Version of Gem
7
- STRING = '0.27.0'
7
+ STRING = '0.30.0'
8
8
  end
9
9
  end
@@ -15,8 +15,8 @@ module OoxmlParser
15
15
  # @param file [String] file to parse
16
16
  # @return [Chartsheet] result of parsing
17
17
  def parse(file)
18
- OOXMLDocumentObject.add_to_xmls_stack(OOXMLDocumentObject.root_subfolder + file)
19
- doc = parse_xml(OOXMLDocumentObject.current_xml)
18
+ root_object.add_to_xmls_stack(root_object.root_subfolder + file)
19
+ doc = parse_xml(root_object.current_xml)
20
20
  node = doc.xpath('//xmlns:chartsheet').first
21
21
  node.xpath('*').each do |node_child|
22
22
  case node_child.name
@@ -26,7 +26,7 @@ module OoxmlParser
26
26
  end
27
27
  end
28
28
  end
29
- OOXMLDocumentObject.xmls_stack.pop
29
+ root_object.xmls_stack.pop
30
30
  self
31
31
  end
32
32
  end
@@ -33,7 +33,7 @@ module OoxmlParser
33
33
  # @return [PivotCacheDefinition] pivot cache definition for current pivot cache
34
34
  def parse_pivot_cache_definition
35
35
  definition_file = root_object.relationships.target_by_id(id)
36
- full_file_path = "#{OOXMLDocumentObject.path_to_folder}/xl/#{definition_file}"
36
+ full_file_path = "#{root_object.unpacked_folder}/xl/#{definition_file}"
37
37
  @pivot_cache_definition = PivotCacheDefinition.new(parent: root_object)
38
38
  .parse(full_file_path)
39
39
  end
@@ -55,7 +55,7 @@ module OoxmlParser
55
55
  # @param [String] file path
56
56
  # @return [PivotTableDefinition] result of parsing
57
57
  def parse(file)
58
- doc = Nokogiri::XML.parse(File.open("#{OOXMLDocumentObject.path_to_folder}/#{file}"))
58
+ doc = Nokogiri::XML.parse(File.open("#{root_object.unpacked_folder}/#{file}"))
59
59
  node = doc.xpath('//xmlns:pivotTableDefinition').first
60
60
  node.attributes.each do |key, value|
61
61
  case key
@@ -32,7 +32,7 @@ module OoxmlParser
32
32
  # Parse StyleSheet object
33
33
  # @return [StyleSheet] result of parsing
34
34
  def parse
35
- doc = parse_xml("#{OOXMLDocumentObject.path_to_folder}/#{OOXMLDocumentObject.root_subfolder}/styles.xml")
35
+ doc = parse_xml("#{root_object.unpacked_folder}/#{root_object.root_subfolder}/styles.xml")
36
36
  doc.root.xpath('*').each do |node_child|
37
37
  case node_child.name
38
38
  when 'numFmts'
@@ -19,8 +19,8 @@ module OoxmlParser
19
19
  # @param node [Nokogiri::XML:Element] node to parse
20
20
  # @return [TablePart] result of parsing
21
21
  def parse(node)
22
- link_to_table_part_xml = OOXMLDocumentObject.get_link_from_rels(node.attribute('id').value)
23
- doc = parse_xml(OOXMLDocumentObject.path_to_folder + link_to_table_part_xml.gsub('..', 'xl'))
22
+ link_to_table_part_xml = root_object.get_link_from_rels(node.attribute('id').value)
23
+ doc = parse_xml(root_object.unpacked_folder + link_to_table_part_xml.gsub('..', 'xl'))
24
24
  table_node = doc.xpath('xmlns:table').first
25
25
  table_node.attributes.each do |key, value|
26
26
  case key
@@ -61,9 +61,9 @@ module OoxmlParser
61
61
  # Perform parsing of relationships
62
62
  # @return [nil]
63
63
  def parse_relationships
64
- OOXMLDocumentObject.add_to_xmls_stack("#{OOXMLDocumentObject.root_subfolder}/worksheets/_rels/#{@xml_name}.rels")
65
- @relationships = Relationships.new(parent: self).parse_file(OOXMLDocumentObject.current_xml) if File.exist?(OOXMLDocumentObject.current_xml)
66
- OOXMLDocumentObject.xmls_stack.pop
64
+ root_object.add_to_xmls_stack("#{root_object.root_subfolder}/worksheets/_rels/#{@xml_name}.rels")
65
+ @relationships = Relationships.new(parent: self).parse_file(root_object.current_xml) if File.exist?(root_object.current_xml)
66
+ root_object.xmls_stack.pop
67
67
  end
68
68
 
69
69
  # @return [True, false] if structure contain any user data
@@ -79,7 +79,7 @@ module OoxmlParser
79
79
 
80
80
  # Parse list of drawings in file
81
81
  def parse_drawing
82
- drawing_node = parse_xml(OOXMLDocumentObject.current_xml)
82
+ drawing_node = parse_xml(root_object.current_xml)
83
83
  drawing_node.xpath('xdr:wsDr/*').each do |drawing_node_child|
84
84
  @drawings << XlsxDrawing.new(parent: self).parse(drawing_node_child)
85
85
  end
@@ -91,8 +91,8 @@ module OoxmlParser
91
91
  def parse(path_to_xml_file)
92
92
  @xml_name = File.basename path_to_xml_file
93
93
  parse_relationships
94
- OOXMLDocumentObject.add_to_xmls_stack("#{OOXMLDocumentObject.root_subfolder}/worksheets/#{File.basename(path_to_xml_file)}")
95
- doc = parse_xml(OOXMLDocumentObject.current_xml)
94
+ root_object.add_to_xmls_stack("#{root_object.root_subfolder}/worksheets/#{File.basename(path_to_xml_file)}")
95
+ doc = parse_xml(root_object.current_xml)
96
96
  sheet = doc.search('//xmlns:worksheet').first
97
97
  sheet.xpath('*').each do |worksheet_node_child|
98
98
  case worksheet_node_child.name
@@ -107,11 +107,11 @@ module OoxmlParser
107
107
  @merge << merge_node.attribute('ref').value.to_s
108
108
  end
109
109
  when 'drawing'
110
- path_to_drawing = OOXMLDocumentObject.get_link_from_rels(worksheet_node_child.attribute('id').value)
110
+ path_to_drawing = root_object.get_link_from_rels(worksheet_node_child.attribute('id').value)
111
111
  unless path_to_drawing.nil?
112
- OOXMLDocumentObject.add_to_xmls_stack(path_to_drawing)
112
+ root_object.add_to_xmls_stack(path_to_drawing)
113
113
  parse_drawing
114
- OOXMLDocumentObject.xmls_stack.pop
114
+ root_object.xmls_stack.pop
115
115
  end
116
116
  when 'hyperlinks'
117
117
  worksheet_node_child.xpath('xmlns:hyperlink').each do |hyperlink_node|
@@ -150,7 +150,7 @@ module OoxmlParser
150
150
  end
151
151
  end
152
152
  parse_comments
153
- OOXMLDocumentObject.xmls_stack.pop
153
+ root_object.xmls_stack.pop
154
154
  self
155
155
  end
156
156
 
@@ -175,7 +175,7 @@ module OoxmlParser
175
175
  comments_target = relationships.target_by_type('comment')
176
176
  return if comments_target.empty?
177
177
 
178
- comments_file = "#{OOXMLDocumentObject.path_to_folder}/#{OOXMLDocumentObject.root_subfolder}/#{comments_target.first.gsub('..', '')}"
178
+ comments_file = "#{root_object.unpacked_folder}/#{root_object.root_subfolder}/#{comments_target.first.gsub('..', '')}"
179
179
  @comments = ExcelComments.new(parent: self).parse(comments_file)
180
180
  end
181
181
  end
@@ -109,7 +109,7 @@ module OoxmlParser
109
109
  shared_strings_target = relationships.target_by_type('sharedString')
110
110
  return if shared_strings_target.empty?
111
111
 
112
- shared_string_file = "#{OOXMLDocumentObject.path_to_folder}/xl/#{shared_strings_target.first}"
112
+ shared_string_file = "#{root_object.unpacked_folder}/xl/#{shared_strings_target.first}"
113
113
  @shared_strings_table = SharedStringTable.new(parent: self).parse(shared_string_file)
114
114
  end
115
115
 
@@ -117,13 +117,12 @@ module OoxmlParser
117
117
  # @return [XLSXWorkbook]
118
118
  def parse
119
119
  @content_types = ContentTypes.new(parent: self).parse
120
- @relationships = Relationships.new(parent: self).parse_file("#{OOXMLDocumentObject.path_to_folder}xl/_rels/workbook.xml.rels")
120
+ @relationships = Relationships.new(parent: self).parse_file("#{root_object.unpacked_folder}xl/_rels/workbook.xml.rels")
121
121
  parse_shared_strings
122
- OOXMLDocumentObject.xmls_stack = []
123
- OOXMLDocumentObject.root_subfolder = 'xl/'
124
- OOXMLDocumentObject.add_to_xmls_stack('xl/workbook.xml')
125
- @doc = Nokogiri::XML.parse(File.open(OOXMLDocumentObject.current_xml))
126
- @theme = PresentationTheme.parse("xl/#{link_to_theme_xml}") if link_to_theme_xml
122
+ @root_subfolder = 'xl/'
123
+ root_object.add_to_xmls_stack('xl/workbook.xml')
124
+ @doc = Nokogiri::XML.parse(File.open(root_object.current_xml))
125
+ @theme = PresentationTheme.new(parent: self).parse("xl/#{link_to_theme_xml}") if link_to_theme_xml
127
126
  @style_sheet = StyleSheet.new(parent: self).parse
128
127
  @doc.xpath('xmlns:workbook/xmlns:sheets/xmlns:sheet').each do |sheet|
129
128
  @sheets << Sheet.new(parent: self).parse(sheet)
@@ -139,7 +138,7 @@ module OoxmlParser
139
138
  parse_pivot_table
140
139
  parse_defined_names
141
140
  parse_workbook_protection
142
- OOXMLDocumentObject.xmls_stack.pop
141
+ root_object.xmls_stack.pop
143
142
  self
144
143
  end
145
144
 
@@ -9,8 +9,9 @@ module OoxmlParser
9
9
  # @param path_to_file [String] file path
10
10
  # @return [XLSXWorkbook] result of parse
11
11
  def self.parse_xlsx(path_to_file)
12
- Parser.parse_format(path_to_file) do
13
- XLSXWorkbook.new.parse
12
+ file = OoxmlFile.new(path_to_file)
13
+ Parser.parse_format(file) do |yielded_file|
14
+ XLSXWorkbook.new(unpacked_folder: yielded_file.path_to_folder).parse
14
15
  end
15
16
  end
16
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ooxml_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.0
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ONLYOFFICE
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-08-31 00:00:00.000000000 Z
13
+ date: 2022-09-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -363,6 +363,7 @@ files:
363
363
  - lib/ooxml_parser/common_parser/common_document_structure.rb
364
364
  - lib/ooxml_parser/common_parser/parser.rb
365
365
  - lib/ooxml_parser/common_parser/parser/encryption_checker.rb
366
+ - lib/ooxml_parser/common_parser/parser/ooxml_file.rb
366
367
  - lib/ooxml_parser/configuration.rb
367
368
  - lib/ooxml_parser/docx_parser.rb
368
369
  - lib/ooxml_parser/docx_parser/document_structure.rb
@@ -423,7 +424,6 @@ files:
423
424
  - lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
424
425
  - lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_properties.rb
425
426
  - lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/structured_document_tag.rb
426
- - lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/style_parametres.rb
427
427
  - lib/ooxml_parser/docx_parser/document_structure/header_footer.rb
428
428
  - lib/ooxml_parser/docx_parser/document_structure/numbering.rb
429
429
  - lib/ooxml_parser/docx_parser/document_structure/numbering/abstract_numbering.rb
@@ -608,7 +608,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
608
608
  - !ruby/object:Gem::Version
609
609
  version: '0'
610
610
  requirements: []
611
- rubygems_version: 3.3.21
611
+ rubygems_version: 3.3.22
612
612
  signing_key:
613
613
  specification_version: 4
614
614
  summary: OoxmlParser Gem