docx_report 0.2.3 → 0.2.5
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_report/block_value.rb +11 -1
- data/lib/docx_report/data_item.rb +2 -2
- data/lib/docx_report/field.rb +5 -3
- data/lib/docx_report/parser.rb +22 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e951d302c3b072bf8f06d91b83c86e2da9718530
|
4
|
+
data.tar.gz: 9dafad1a65092a86fa575c8e63229b2f65de2179
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f93c2e8dde7e7a183951d700f1d10316493e3bb86b78550c50e2ccacfc95114d13d978d0827feac62e90f70ade5fe0b175a1ee1172dc8f9f096b708bb6a88bd
|
7
|
+
data.tar.gz: 40344c336a174ee3fa57c6256b5860db29c0e1a35e51ac109986edd15b2b10a90cb223271aa1882548540048ca94d0c06e94f3b2b6b5592d461e07953623dc6a
|
@@ -2,10 +2,20 @@ module DocxReport
|
|
2
2
|
module BlockValue
|
3
3
|
def load_value(item)
|
4
4
|
if @value.is_a? Proc
|
5
|
-
@value.call(item)
|
5
|
+
val = @value.call(item)
|
6
|
+
val.is_a?(Hash) ? val[:value] : val
|
6
7
|
else
|
7
8
|
item.is_a?(Hash) ? item[@value] : item.send(@value)
|
8
9
|
end
|
9
10
|
end
|
11
|
+
|
12
|
+
def load_text_direction(item)
|
13
|
+
if @value.is_a? Proc
|
14
|
+
val = @value.call(item)
|
15
|
+
val.is_a?(Hash) ? val[:text_direction] : :none
|
16
|
+
else
|
17
|
+
:none
|
18
|
+
end
|
19
|
+
end
|
10
20
|
end
|
11
21
|
end
|
@@ -2,8 +2,8 @@ module DocxReport
|
|
2
2
|
module DataItem
|
3
3
|
attr_reader :fields, :images, :tables
|
4
4
|
|
5
|
-
def add_field(name, value, type = :text)
|
6
|
-
field = Field.new name, value, type
|
5
|
+
def add_field(name, value, type = :text, text_direction = :none)
|
6
|
+
field = Field.new name, value, type, text_direction
|
7
7
|
raise 'duplicate field name' if @fields.any? { |f| f.name == field.name }
|
8
8
|
@fields << field
|
9
9
|
end
|
data/lib/docx_report/field.rb
CHANGED
@@ -4,11 +4,13 @@ require 'docx_report/block_value'
|
|
4
4
|
module DocxReport
|
5
5
|
class Field
|
6
6
|
include BlockValue
|
7
|
-
attr_reader :name, :value, :type
|
7
|
+
attr_reader :name, :value, :type, :text_direction
|
8
8
|
|
9
|
-
def initialize(name, value = nil, type = :text,
|
9
|
+
def initialize(name, value = nil, type = :text, text_direction = :none,
|
10
|
+
&block)
|
10
11
|
@name = "@#{name}@"
|
11
12
|
@type = type
|
13
|
+
@text_direction = text_direction
|
12
14
|
set_value(value || block)
|
13
15
|
end
|
14
16
|
|
@@ -17,7 +19,7 @@ module DocxReport
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def load_field(item)
|
20
|
-
Field.new(name[1..-2], load_value(item), type)
|
22
|
+
Field.new(name[1..-2], load_value(item), type, load_text_direction(item))
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
data/lib/docx_report/parser.rb
CHANGED
@@ -26,6 +26,23 @@ module DocxReport
|
|
26
26
|
parent_node.xpath(".//*[contains(text(), '#{name}')]")
|
27
27
|
end
|
28
28
|
|
29
|
+
def apply_text_direction(name, parent_node, text_direction)
|
30
|
+
parent_node.xpath("//w:p[.//*[contains(text(), '#{name}')]]")
|
31
|
+
.each do |node|
|
32
|
+
bidi = node.xpath('.//w:bidi').first
|
33
|
+
if text_direction == :ltr
|
34
|
+
bidi.remove if bidi
|
35
|
+
elsif bidi.nil?
|
36
|
+
p_pr = node.xpath('.//w:pPr').first
|
37
|
+
if p_pr.nil?
|
38
|
+
node.first_element_child.before('<w:pPr><w:bidi/></w:pPr>')
|
39
|
+
else
|
40
|
+
p_pr.first_element_child.before('<w:bidi/>')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
29
46
|
def find_hyperlink_nodes(name, parent_node, file)
|
30
47
|
links = file.rels_xml.xpath "//*[@Target='#{name}']"
|
31
48
|
parent_node.xpath(".//w:hyperlink[@r:id='#{find_by_id(links)}']")
|
@@ -42,8 +59,11 @@ module DocxReport
|
|
42
59
|
|
43
60
|
def replace_node_fields(fields, parent_node)
|
44
61
|
fields.select { |f| f.type == :text }.each do |field|
|
45
|
-
|
46
|
-
|
62
|
+
if field.text_direction != :none
|
63
|
+
apply_text_direction(field.name, parent_node, field.text_direction)
|
64
|
+
end
|
65
|
+
find_text_nodes(field.name, parent_node).each do |node|
|
66
|
+
node.content = node.content.gsub field.name, field.value.to_s
|
47
67
|
end
|
48
68
|
end
|
49
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docx_report
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmed Abudaqqa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|