docx_replace 1.0.2 → 1.0.3
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 +5 -13
- data/README.md +3 -3
- data/docx_replace.gemspec +1 -1
- data/lib/docx_replace.rb +5 -2
- data/lib/docx_replace/version.rb +1 -1
- metadata +16 -10
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MTE5YzQ3YWFkMDFjYWQ1ZTliNmFkZDBlYzkyZDIyZWViMzU3ZmQ0Mg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dab91a42454bac7f4aab7f66f9e242c5af9ea431
|
4
|
+
data.tar.gz: c570d2f4f0f99d061984c302ced071ea4adc2e5b
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YmRmMjFhNjMzOTY5MzBjZjUxNWVjM2FhNGYyNWYzMWIyODE0NDkzZWIxZmE5
|
11
|
-
ZDdkODZmMDAzYzI5NWNiY2U3MzM2ZDNiNzY1ZTA0ZmQzNGZiN2U=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZjEyNDJiMzNhYjc5MTEyNGFmNWU4NzhmMDhmNDhjOGFjYzU2MmNiNzQ2MWM1
|
14
|
-
MTdmNTVlODJhM2U3MWEwM2NkNWFkNzA2NjAzODY4MzA4ODJlZGIyMDhhNmNm
|
15
|
-
NjcwNjJkYjMwNWRkN2U3OTI1Nzk4MDE5ZWNiMDU4ZDYyMTgwMTg=
|
6
|
+
metadata.gz: 435ab57fbb9b0797753767e1d6dc7b1f20980dcefea1a672305d4de63fb5d0c9c10d53b16fe60d3383f6a59b4d8365a449bb511aed58357763055ab2be34f90b
|
7
|
+
data.tar.gz: 706d645075e5535d139f6a54eef6caecc02c7f03b5933a2ae1167c4eb912b2376a1f41bd8da7213ff5f10ddb9eaa7540715c8dcf2206510793914f70204c0734
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
Inside of a rails controller, your code might look something like this:
|
23
|
+
Inside of a rails controller, your code might look something like this (although I would recommend extracting most of this into a separate class):
|
24
24
|
|
25
25
|
```ruby
|
26
26
|
def user_report
|
@@ -37,8 +37,8 @@ def user_report
|
|
37
37
|
doc.replace("$user_bio$", @user.bio)
|
38
38
|
|
39
39
|
# Write the document back to a temporary file
|
40
|
-
tmp_file =
|
41
|
-
doc.commit(tmp_file)
|
40
|
+
tmp_file = Tempfile.new('word_tempate', "#{Rails.root}/tmp")
|
41
|
+
doc.commit(tmp_file.path)
|
42
42
|
|
43
43
|
# Respond to the request by sending the temp file
|
44
44
|
send_file tmp_file.path, filename: "user_#{@user.id}_report.docx", disposition: 'attachment'
|
data/docx_replace.gemspec
CHANGED
@@ -17,5 +17,5 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
|
-
gem.add_runtime_dependency
|
20
|
+
gem.add_runtime_dependency 'rubyzip', '~> 1.1', '>= 1.1.6'
|
21
21
|
end
|
data/lib/docx_replace.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require "docx_replace/version"
|
2
4
|
require 'zip'
|
3
5
|
require 'tempfile'
|
@@ -11,10 +13,11 @@ module DocxReplace
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def replace(pattern, replacement, multiple_occurrences=false)
|
16
|
+
replace = replacement.to_s
|
14
17
|
if multiple_occurrences
|
15
|
-
@document_content.gsub!(pattern,
|
18
|
+
@document_content.force_encoding("UTF-8").gsub!(pattern, replace)
|
16
19
|
else
|
17
|
-
@document_content.sub!(pattern,
|
20
|
+
@document_content.force_encoding("UTF-8").sub!(pattern, replace)
|
18
21
|
end
|
19
22
|
end
|
20
23
|
|
data/lib/docx_replace/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docx_replace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Albrecht
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.1
|
19
|
+
version: '1.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.1.6
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - ~>
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.1'
|
30
|
+
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.1.
|
32
|
+
version: 1.1.6
|
27
33
|
description: Find and replace variables inside a Micorsoft Word (.docx) template
|
28
34
|
email:
|
29
35
|
- adam.albrecht@gmail.com
|
@@ -31,7 +37,7 @@ executables: []
|
|
31
37
|
extensions: []
|
32
38
|
extra_rdoc_files: []
|
33
39
|
files:
|
34
|
-
- .gitignore
|
40
|
+
- ".gitignore"
|
35
41
|
- CHANGELOG
|
36
42
|
- Gemfile
|
37
43
|
- LICENSE.txt
|
@@ -50,17 +56,17 @@ require_paths:
|
|
50
56
|
- lib
|
51
57
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
58
|
requirements:
|
53
|
-
- -
|
59
|
+
- - ">="
|
54
60
|
- !ruby/object:Gem::Version
|
55
61
|
version: '0'
|
56
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
63
|
requirements:
|
58
|
-
- -
|
64
|
+
- - ">="
|
59
65
|
- !ruby/object:Gem::Version
|
60
66
|
version: '0'
|
61
67
|
requirements: []
|
62
68
|
rubyforge_project:
|
63
|
-
rubygems_version: 2.
|
69
|
+
rubygems_version: 2.2.2
|
64
70
|
signing_key:
|
65
71
|
specification_version: 4
|
66
72
|
summary: Find and replace variables inside a Micorsoft Word (.docx) template
|