docx 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a33dcd9e31c60144261a15670cd1c01b37877044aaf33f7091b46cc85ab3412
4
- data.tar.gz: 1911db027b3e2fbf8eb9363eaa99b95231f875afe8de2a0c060b38fee86c7238
3
+ metadata.gz: 96b871b0d07fecde4e6c93c67463da727565f3acca519b08b9c554d987570e58
4
+ data.tar.gz: 2f3b9362b91c33d02e6c1b4acf0b23fb723f71d26f9b2e800b930c91c3687eee
5
5
  SHA512:
6
- metadata.gz: 0a823fedf1b0bfc542c88533c787aefa5e9cee12ae4422a01f106985a2f03e8b636aa70820a179f5501ba8f996672f8f75e24356282cd7d81505cbb1984fa967
7
- data.tar.gz: c06b4078536bd8b12b5c5e4f61fe0ef5f2f9e03e9cbc7c4017f2d01d3e8a0bc9200fa7457fac54c0b110a57ddc4bff8ad74c28d3e873512900266ac00137c6e6
6
+ metadata.gz: 5e198cb74eb7a06b62bb63a3a0ff065b0c95cf26aafb53320bb5b14339dc386d975a1f57178316d1d5d7753081e07989b4498bcdfa3f0092f2fc14b1e4086b84
7
+ data.tar.gz: d0626b7332fd3a3d95b6358a3fb6ea09b0faf58545db9bd948c9f97baa5457eacb43267cc40914df2fa54872b42cca5c1963f66111a8b0b4be33a3e6f99c4b38
@@ -12,14 +12,14 @@ module Docx
12
12
  bold: false,
13
13
  underline: false
14
14
  }
15
-
15
+
16
16
  def self.tag
17
17
  'r'
18
18
  end
19
19
 
20
20
  attr_reader :text
21
21
  attr_reader :formatting
22
-
22
+
23
23
  def initialize(node, document_properties = {})
24
24
  @node = node
25
25
  @text_nodes = @node.xpath('w:t').map {|t_node| Elements::Text.new(t_node) }
@@ -40,6 +40,7 @@ module Docx
40
40
  new_t = Elements::Text.create_within(self)
41
41
  new_t.content = content
42
42
  end
43
+ reset_text
43
44
  end
44
45
 
45
46
  # Returns text contained within text run
@@ -52,6 +53,7 @@ module Docx
52
53
  @text_nodes.each do |text_node|
53
54
  text_node.content = text_node.content.gsub(match, replacement)
54
55
  end
56
+ reset_text
55
57
  end
56
58
 
57
59
  def parse_formatting
@@ -74,7 +76,7 @@ module Docx
74
76
  styles = {}
75
77
  styles['text-decoration'] = 'underline' if underlined?
76
78
  # No need to be granular with font size down to the span level if it doesn't vary.
77
- styles['font-size'] = "#{font_size}pt" if font_size != @font_size
79
+ styles['font-size'] = "#{font_size}pt" if font_size != @font_size
78
80
  html = html_tag(:span, content: html, styles: styles) unless styles.empty?
79
81
  html = html_tag(:a, content: html, attributes: {href: href, target: "_blank"}) if hyperlink?
80
82
  return html
@@ -83,11 +85,11 @@ module Docx
83
85
  def italicized?
84
86
  @formatting[:italic]
85
87
  end
86
-
88
+
87
89
  def bolded?
88
90
  @formatting[:bold]
89
91
  end
90
-
92
+
91
93
  def underlined?
92
94
  @formatting[:underline]
93
95
  end
@@ -102,12 +104,18 @@ module Docx
102
104
 
103
105
  def hyperlink_id
104
106
  @node.attributes['id'].value
105
- end
107
+ end
106
108
 
107
109
  def font_size
108
110
  size_tag = @node.xpath('w:rPr//w:sz').first
109
111
  size_tag ? size_tag.attributes['val'].value.to_i / 2 : @font_size
110
112
  end
113
+
114
+ private
115
+
116
+ def reset_text
117
+ @text = parse_text
118
+ end
111
119
  end
112
120
  end
113
121
  end
data/lib/docx/document.rb CHANGED
@@ -70,6 +70,10 @@ module Docx
70
70
  bkmrks_hsh
71
71
  end
72
72
 
73
+ def to_xml
74
+ Nokogiri::XML(@document_xml)
75
+ end
76
+
73
77
  def tables
74
78
  @doc.xpath('//w:document//w:body//w:tbl').map { |t_node| parse_table_from t_node }
75
79
  end
@@ -91,7 +91,7 @@ module Docx
91
91
  module ClassMethods
92
92
  def create_with(element)
93
93
  # Need to somehow get the xml document accessible here by default, but this is alright in the interim
94
- self.new(Nokogiri::XML::Node.new("w:#{self.tag}", element.node))
94
+ self.new(Nokogiri::XML::Node.new("w:#{self.tag}", element.node.document))
95
95
  end
96
96
 
97
97
  def create_within(element)
data/lib/docx/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Docx #:nodoc:
4
- VERSION = '0.6.2'
4
+ VERSION = '0.7.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Hunt
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2021-07-21 00:00:00.000000000 Z
15
+ date: 2022-03-13 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: nokogiri
@@ -20,20 +20,20 @@ dependencies:
20
20
  requirements:
21
21
  - - "~>"
22
22
  - !ruby/object:Gem::Version
23
- version: '1.10'
23
+ version: '1.13'
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.10.4
26
+ version: 1.13.0
27
27
  type: :runtime
28
28
  prerelease: false
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.10'
33
+ version: '1.13'
34
34
  - - ">="
35
35
  - !ruby/object:Gem::Version
36
- version: 1.10.4
36
+ version: 1.13.0
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rubyzip
39
39
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +128,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: 2.5.0
131
+ version: 2.6.0
132
132
  required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - ">="
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
- rubygems_version: 3.1.6
138
+ rubygems_version: 3.3.3
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: a ruby library/gem for interacting with .docx files