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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac6cfdb1bdabf1ef28636d52607f8db6d36d6473
4
- data.tar.gz: 6a6b9141e4e07a3f67ae2940b0a6243d8d748ace
3
+ metadata.gz: efdfa9bf0b9f3f9b8a839b56285c729d8446230d
4
+ data.tar.gz: 63bc8a8a664adb5509451bd4f690b70681c2bf54
5
5
  SHA512:
6
- metadata.gz: 45b3f8e0579de24698d5e8b39ebd1bff6c4690a30f171c5428ccc05934850a858150dac23c37372ed45b8959e8a4657c65403f10a26a782062ed1adce05c3335
7
- data.tar.gz: fdf4a1d02e1ef6faae7c6e81de5723ec75b5bc6f4b07b858362ed5f402aeda149907d9aad6e2a6ae318dad36fc3b762b3430cf2fb896f5e7fd2b75bef2854125
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
- class DocumentReplacer
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(@doc.root)
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
- @doc.to_s
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
- end
34
+ def convert_newlines
35
+ NewlineReplacer.new(doc).replace
36
+ end
37
+ end
33
38
  end
@@ -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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docx_templater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Smith
metadata.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- (x�Q>������v� b������~|l=�fā��ŔW���4`&�w��2$B��د3���<�k˺,ݠ��3ὄo���L���.�T����v��Ğ�nS�r�!���i"�$7t��M��d��v߂�8!"B�đ�(6
2
- �E8��"g}��Y������_ݵ\>�l��� Sw���MH�A��[ 5lV��Vu�#X��� ~�㰠���󜸵�=D#�9�W�pV��0�PW�` q ��5��G
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���