rtftopdf 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rtftopdf.rb +3 -17
- data/lib/rtftopdf/rtf.rb +21 -0
- data/lib/rtftopdf/temporary_file.rb +23 -0
- data/lib/rtftopdf/version.rb +1 -1
- data/test/lib/rtftopdf_test.rb +5 -5
- data/test/rtftopdf/rtf_spec.rb +9 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16ec7e86b90d1688af99d07ac54e013b02e18415
|
4
|
+
data.tar.gz: 96ed18974c06aa59c7f907be9c7d7359d18e5d53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5368048ab3effe780495ebeb0a562d4266f50761de93cd7d29492b1a6779f9417e7b2c3febb349c6834608d21697c43f2ddd60fac89f6173dacb7616b2823009
|
7
|
+
data.tar.gz: 6340974ac18bca97fd9f3ec4e50eb34d4ccd8bb13691cc1a6af46d17d784ddbd5903ce4d9898139619c6799cefa6aba0c5454ce680ec98d0a231c9fc9a8ed457
|
data/lib/rtftopdf.rb
CHANGED
@@ -1,27 +1,13 @@
|
|
1
|
+
require "rtftopdf/rtf"
|
2
|
+
require "rtftopdf/temporary_file"
|
1
3
|
require "rtftopdf/version"
|
2
4
|
require 'tempfile'
|
3
5
|
require 'pdfkit'
|
4
6
|
|
5
|
-
class RTF
|
6
|
-
def initialize rtf_content
|
7
|
-
@rtf_content = rtf_content
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_html
|
11
|
-
temporary_rtf_file = Tempfile.new('RTF')
|
12
|
-
temporary_rtf_file.write(@rtf_content)
|
13
|
-
temporary_rtf_file.close
|
14
|
-
|
15
|
-
html_content = `unrtf #{temporary_rtf_file.path}`
|
16
|
-
temporary_rtf_file.unlink
|
17
|
-
|
18
|
-
html_content
|
19
|
-
end
|
20
|
-
end
|
21
7
|
|
22
8
|
module RTFtoPDF
|
23
9
|
def self.to_pdf rtf_content
|
24
|
-
html_content = RTF.
|
10
|
+
html_content = RTF.parse(rtf_content).to_html
|
25
11
|
pdf_content = PDFKit.new(html_content).to_pdf
|
26
12
|
|
27
13
|
pdf_content
|
data/lib/rtftopdf/rtf.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module RTFtoPDF
|
2
|
+
|
3
|
+
class RTF
|
4
|
+
|
5
|
+
attr_accessor :content
|
6
|
+
|
7
|
+
def self.parse content
|
8
|
+
rtf = new
|
9
|
+
rtf.content = content
|
10
|
+
rtf
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_html
|
14
|
+
TemporaryFile.within_a_file(content) do |file|
|
15
|
+
`unrtf #{file.path}`
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module RTFtoPDF
|
2
|
+
|
3
|
+
module TemporaryFile
|
4
|
+
|
5
|
+
def self.within_a_file content, &file_operation
|
6
|
+
file = create_the_temporary_file_with content
|
7
|
+
result = file_operation.call file
|
8
|
+
file.unlink
|
9
|
+
result
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def self.create_the_temporary_file_with content
|
15
|
+
file = Tempfile.new('RTF')
|
16
|
+
file.write content
|
17
|
+
file.close
|
18
|
+
file
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/rtftopdf/version.rb
CHANGED
data/test/lib/rtftopdf_test.rb
CHANGED
@@ -32,17 +32,17 @@ describe "rtf to pdf conversion" do
|
|
32
32
|
RTFtoPDF.to_pdf(rtf_input)
|
33
33
|
|
34
34
|
end
|
35
|
-
it "must delete the temporary file when its finished" do
|
36
|
-
Tempfile.any_instance.expects(:unlink)
|
37
|
-
RTFtoPDF.to_pdf("asdf")
|
38
|
-
end
|
35
|
+
#it "must delete the temporary file when its finished" do
|
36
|
+
#Tempfile.any_instance.expects(:unlink)
|
37
|
+
#RTFtoPDF.to_pdf("asdf")
|
38
|
+
#end
|
39
39
|
end
|
40
40
|
|
41
41
|
it "must pass on the html result to pdf kit" do
|
42
42
|
|
43
43
|
mock_pdfkit.expects(:to_pdf)
|
44
44
|
|
45
|
-
RTF.any_instance.stubs(:to_html).returns("my html content!")
|
45
|
+
RTFtoPDF::RTF.any_instance.stubs(:to_html).returns("my html content!")
|
46
46
|
|
47
47
|
PDFKit.expects(:new).with("my html content!").returns(mock_pdfkit)
|
48
48
|
RTFtoPDF.to_pdf("bla bla /so-=1 RTF content")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rtftopdf
|
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
|
- Caleb Cauthon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pdfkit
|
@@ -93,9 +93,12 @@ files:
|
|
93
93
|
- README.md
|
94
94
|
- Rakefile
|
95
95
|
- lib/rtftopdf.rb
|
96
|
+
- lib/rtftopdf/rtf.rb
|
97
|
+
- lib/rtftopdf/temporary_file.rb
|
96
98
|
- lib/rtftopdf/version.rb
|
97
99
|
- rtftopdf.gemspec
|
98
100
|
- test/lib/rtftopdf_test.rb
|
101
|
+
- test/rtftopdf/rtf_spec.rb
|
99
102
|
- test/test_helper.rb
|
100
103
|
homepage: http://github.com/calebcauthon/rtftopdf
|
101
104
|
licenses:
|
@@ -123,4 +126,5 @@ specification_version: 4
|
|
123
126
|
summary: Converts rtf strings to pdf output using unrtf and wkhtmltopdf.
|
124
127
|
test_files:
|
125
128
|
- test/lib/rtftopdf_test.rb
|
129
|
+
- test/rtftopdf/rtf_spec.rb
|
126
130
|
- test/test_helper.rb
|