docx 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/docx/containers/text_run.rb +14 -6
- data/lib/docx/document.rb +4 -0
- data/lib/docx/elements/element.rb +1 -1
- data/lib/docx/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96b871b0d07fecde4e6c93c67463da727565f3acca519b08b9c554d987570e58
|
4
|
+
data.tar.gz: 2f3b9362b91c33d02e6c1b4acf0b23fb723f71d26f9b2e800b930c91c3687eee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
@@ -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
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.
|
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:
|
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.
|
23
|
+
version: '1.13'
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
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.
|
33
|
+
version: '1.13'
|
34
34
|
- - ">="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: 1.
|
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.
|
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.
|
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
|