docx_template 0.5 → 0.6

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: 8d68c2632b62151431edc8aa8a49c591610b5615
4
- data.tar.gz: abcc21db45243d403c79418abdd43d975de619d8
3
+ metadata.gz: b2a132bc68fb9a267424f300ee5795e4f3e7f5ba
4
+ data.tar.gz: 3716348a6dadf603734e355bcba685572edad608
5
5
  SHA512:
6
- metadata.gz: 1e2cb8f41c12809ed379129c0ec3202443aab1cd5bfaae9674e0996e9967eec973500c83230de209f81feb4094c7927035689b7cbeb0a8facd61603a2bbec5a1
7
- data.tar.gz: 7d4b267f1deff78ee9e2410cf8061baa9c2fd376f694fa45dccc03e84fa35359c73c17ff346fb666b11c2e02cd94a16fa95f4ea8b76e0603bfe211215c383b23
6
+ metadata.gz: b2a6a7449e2ae67a8b94b40f81d14a77c1cc6ba89db80fbca26e1aa5a0a96a11f6589c4387b285c3c37c576dfe1551eaa16296ce708ad1480473c70f474b24f1
7
+ data.tar.gz: cfb32dcef2d05790f22b72bdfa2879b4c3fbdab7a4a7a50ef27c8ff7c88a9a27a031f1317b6a0758e4f4f1d154c77587238558bb8405f9798f58924393eaaa7c
@@ -5,7 +5,7 @@ require 'docx_template/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "docx_template"
8
- spec.version = "0.5"
8
+ spec.version = "0.6"
9
9
  spec.authors = ["Maniankara"]
10
10
  spec.email = ["Maniankara@gmail.com"]
11
11
  spec.summary = %q{Docx templating library which could replace docx contents such as text, images etc. in one go.}
@@ -1,4 +1,5 @@
1
1
  require 'zip'
2
+ Zip.unicode_names = true
2
3
 
3
4
  module DocxTemplate
4
5
 
@@ -82,11 +83,12 @@ module DocxTemplate
82
83
  e_list
83
84
  end
84
85
 
86
+ # Encoding should be handled by the user, check spec for examples
85
87
  def replace_content(out, dest_file, zip_file, list)
86
88
  out.put_next_entry(dest_file)
87
89
  string_buffer = zip_file.read(dest_file)
88
90
  list.each do |replacer|
89
- string_buffer.gsub!(replacer.src_entity,replacer.dest_entity)
91
+ string_buffer.gsub!(replacer.src_entity, replacer.dest_entity)
90
92
  end
91
93
  out.write string_buffer
92
94
  end
data/spec/docx_spec.rb CHANGED
@@ -8,16 +8,18 @@ RSpec.describe DocxTemplate::Docx do
8
8
 
9
9
  it "Replaces text once" do
10
10
  template = DocxTemplate::Docx.new "spec/unit/templates/docx_template.docx"
11
- template.replace_text("##SINGLE_REPLACE_TEXT##", "here")
11
+ template.replace_text("##SINGLE_REPLACE_TEXT##", "DOCX_TEMPLATE_REPLACE_TEXT")
12
12
  template.save("/tmp/a.docx")
13
13
  expect(@docx_verifier.verify_text_exists?("/tmp/a.docx", "##SINGLE_REPLACE_TEXT##")).to be(false)
14
+ expect(@docx_verifier.verify_text_exists?("/tmp/a.docx", "DOCX_TEMPLATE_REPLACE_TEXT")).to be(true)
14
15
  end
15
16
 
16
17
  it "Replaces text multiple occurances" do
17
18
  template = DocxTemplate::Docx.new "spec/unit/templates/docx_template.docx"
18
- template.replace_text("##MULTIPLE_REPLACE_TEXT##", "here")
19
+ template.replace_text("##MULTIPLE_REPLACE_TEXT##", "DOCX_TEMPLATE_REPLACE_TEXT", true)
19
20
  template.save("/tmp/a.docx")
20
21
  expect(@docx_verifier.verify_text_exists?("/tmp/a.docx", "##MULTIPLE_REPLACE_TEXT##")).to be(false)
22
+ expect(@docx_verifier.verify_text_exists?("/tmp/a.docx", "DOCX_TEMPLATE_REPLACE_TEXT")).to be(true)
21
23
  end
22
24
 
23
25
  it "Replaces an image" do
@@ -29,9 +31,11 @@ RSpec.describe DocxTemplate::Docx do
29
31
 
30
32
  it "Replaces text in header" do
31
33
  template = DocxTemplate::Docx.new "spec/unit/templates/docx_template.docx"
32
- template.replace_header("##HEADER_REPLACE_TEXT##", "here")
34
+ template.replace_header("##HEADER_REPLACE_TEXT##", "DOCX_TEMPLATE_REPLACE_TEXT", true)
33
35
  template.save("/tmp/a.docx")
34
36
  expect(@docx_verifier.verify_text_exists?("/tmp/a.docx", "##HEADER_REPLACE_TEXT##")).to be(false)
37
+ #TODO: implement for header searching
38
+ #expect(@docx_verifier.verify_text_exists?("/tmp/a.docx", "DOCX_TEMPLATE_REPLACE_TEXT")).to be(true)
35
39
  end
36
40
 
37
41
  # Negative cases
@@ -48,5 +52,16 @@ RSpec.describe DocxTemplate::Docx do
48
52
  template.save("/tmp/a.docx")
49
53
  expect(@docx_verifier.verify_image_exists?("/tmp/a.docx", "image1.jpeg", "spec/unit/images/image5.jpg")).to be(false)
50
54
  end
51
-
55
+
56
+ # Ref: http://yehudakatz.com/2010/05/05/ruby-1-9-encodings-a-primer-and-the-solution-for-rails/
57
+ it "Handling special characters for replace_text" do
58
+ Zip.unicode_names = true
59
+ template = DocxTemplate::Docx.new "spec/unit/templates/docx_template.docx"
60
+ dest_str = "1 Rummun päät tukossa: test\n"
61
+ template.replace_text("##MULTIPLE_REPLACE_TEXT##", dest_str.force_encoding('ASCII-8BIT'), true)
62
+ template.save("/tmp/a.docx")
63
+ expect(@docx_verifier.verify_text_exists?("/tmp/a.docx", "##MULTIPLE_REPLACE_TEXT##")).to be(false)
64
+ expect(@docx_verifier.verify_text_exists?("/tmp/a.docx", dest_str.force_encoding('ASCII-8BIT'))).to be(true)
65
+ end
66
+
52
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docx_template
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maniankara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-23 00:00:00.000000000 Z
11
+ date: 2014-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler