docx_templater 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/docx/document_replacer.rb +10 -5
- data/lib/docx_templater.rb +6 -2
- metadata +1 -1
- metadata.gz.sig +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efdfa9bf0b9f3f9b8a839b56285c729d8446230d
|
4
|
+
data.tar.gz: 63bc8a8a664adb5509451bd4f690b70681c2bf54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef3e7e1aff9c4beaef794f52718dd976079d4da493b60281d88dc483fb8d750ea81db07add5209665fbedb0078601a373067b24888f26dec16786b6e8f1bf22a
|
7
|
+
data.tar.gz: 2cb665bd5b4878dce85a6b4e1bb3825469ec84c61785f1309fbe8a700020edc4944ec1d94cfb65c0f71e1f1447e5a04e2dcbe85db1b4d9d3da5a5113de728c5f
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
@@ -2,22 +2,24 @@ require 'rexml/document'
|
|
2
2
|
require 'docx/placeholder_observer'
|
3
3
|
|
4
4
|
module Docx
|
5
|
-
|
5
|
+
class DocumentReplacer
|
6
6
|
|
7
7
|
attr_reader :doc, :observer
|
8
8
|
|
9
|
-
def initialize(str, data_provider)
|
9
|
+
def initialize(str, data_provider, opts = {})
|
10
10
|
@doc = REXML::Document.new(str)
|
11
11
|
@observer = Docx::PlaceholderObserver.new(data_provider)
|
12
|
-
walk_node(
|
12
|
+
walk_node(doc.root)
|
13
13
|
@observer.end_of_document
|
14
|
+
convert_newlines if opts.fetch(:convert_newlines){ true }
|
14
15
|
end
|
15
16
|
|
16
17
|
def replaced
|
17
|
-
|
18
|
+
doc.to_s
|
18
19
|
end
|
19
20
|
|
20
21
|
private
|
22
|
+
attr_reader :doc
|
21
23
|
|
22
24
|
def walk_node(node)
|
23
25
|
if node.is_a?(REXML::Element)
|
@@ -29,5 +31,8 @@ module Docx
|
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
|
-
|
34
|
+
def convert_newlines
|
35
|
+
NewlineReplacer.new(doc).replace
|
36
|
+
end
|
37
|
+
end
|
33
38
|
end
|
data/lib/docx_templater.rb
CHANGED
@@ -3,6 +3,7 @@ require 'zip'
|
|
3
3
|
require 'htmlentities'
|
4
4
|
require 'docx/argument_combiner'
|
5
5
|
require 'docx/document_replacer'
|
6
|
+
require 'docx/newline_replacer'
|
6
7
|
|
7
8
|
# Use .docx as reusable templates
|
8
9
|
#
|
@@ -41,11 +42,14 @@ class DocxTemplater
|
|
41
42
|
def entry_requires_replacement?(entry)
|
42
43
|
entry.ftype != :directory && entry.name =~ /document|header|footer/
|
43
44
|
end
|
44
|
-
|
45
|
+
|
46
|
+
private
|
47
|
+
attr_reader :options
|
48
|
+
|
45
49
|
def get_entry_content(entry, data_provider)
|
46
50
|
file_string = entry.get_input_stream.read
|
47
51
|
if entry_requires_replacement?(entry)
|
48
|
-
replacer = Docx::DocumentReplacer.new(file_string, data_provider)
|
52
|
+
replacer = Docx::DocumentReplacer.new(file_string, data_provider, options)
|
49
53
|
replacer.replaced
|
50
54
|
else
|
51
55
|
file_string
|
metadata
CHANGED
metadata.gz.sig
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
�r-��\�E�������2
|
2
|
+
���I��������,,bյ�*.���*7Ө�E�m�kyΔP��B����_]K,h���p���8��5*J9�
|
3
|
+
��-<G0���B�U�$}I�7g�Zz�<������PAF�@�7�6+�(⢖����#���U����sJ�8�n���3��V���d��`^�`b6m�e��#����C������_��|y'ʅ���z�+:x{�_�*�S���T�l(�lծ���s���
|