rtftopdf 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b349e528e63f28b19bfeb734a1c369eb9beb44d0
4
- data.tar.gz: e245e053d9fdf40b2e86d59e2c5cd09a1c20df40
3
+ metadata.gz: 16ec7e86b90d1688af99d07ac54e013b02e18415
4
+ data.tar.gz: 96ed18974c06aa59c7f907be9c7d7359d18e5d53
5
5
  SHA512:
6
- metadata.gz: 815246fc2511b05a6973212e9b5560d0f1c97e8f8308f6c8946854be61de9ecc9ea1e992f3718795c758bab4948385ace66043dcc7e1be7c29b90020fc0d6ca9
7
- data.tar.gz: 6b1d232c55bb8dc61a9a4d573b1ad38eb0feba916e95c7c953b307cd15e2e2747e5d09fb6f444328ffeb150ba6bc758af6396cdcd06882261caf882034ff2405
6
+ metadata.gz: 5368048ab3effe780495ebeb0a562d4266f50761de93cd7d29492b1a6779f9417e7b2c3febb349c6834608d21697c43f2ddd60fac89f6173dacb7616b2823009
7
+ data.tar.gz: 6340974ac18bca97fd9f3ec4e50eb34d4ccd8bb13691cc1a6af46d17d784ddbd5903ce4d9898139619c6799cefa6aba0c5454ce680ec98d0a231c9fc9a8ed457
@@ -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.new(rtf_content).to_html
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Rtftopdf
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -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")
@@ -0,0 +1,9 @@
1
+ require_relative '../test_helper'
2
+
3
+ describe RTFtoPDF::RTF do
4
+
5
+ it "should exist" do
6
+ true.must_equal true
7
+ end
8
+
9
+ end
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.2
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-17 00:00:00.000000000 Z
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