showoff 0.6.0 → 0.7.0

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.
data/lib/princely.rb DELETED
@@ -1,84 +0,0 @@
1
- # PrinceXML Ruby interface.
2
- # http://www.princexml.com
3
- #
4
- # Library by Subimage Interactive - http://www.subimage.com
5
- #
6
- #
7
- # USAGE
8
- # -----------------------------------------------------------------------------
9
- # princely = Princely.new()
10
- # html_string = render_to_string(:template => 'some_document')
11
- # send_data(
12
- # princely.pdf_from_string(html_string),
13
- # :filename => 'some_document.pdf'
14
- # :type => 'application/pdf'
15
- # )
16
- #
17
- $:.unshift(File.dirname(__FILE__))
18
-
19
- class Princely
20
- VERSION = "1.0.0" unless const_defined?("VERSION")
21
-
22
- attr_accessor :exe_path, :style_sheets, :log_file
23
-
24
- # Initialize method
25
- #
26
- def initialize()
27
- # Finds where the application lives, so we can call it.
28
- @exe_path = `which prince`.chomp
29
- raise "Cannot find prince command-line app in $PATH" if @exe_path.length == 0
30
- @style_sheets = ''
31
- @log_file = "/tmp/prince.log"
32
- end
33
-
34
- # Sets stylesheets...
35
- # Can pass in multiple paths for css files.
36
- #
37
- def add_style_sheets(*sheets)
38
- for sheet in sheets do
39
- @style_sheets << " -s #{sheet} "
40
- end
41
- end
42
-
43
- # Returns fully formed executable path with any command line switches
44
- # we've set based on our variables.
45
- #
46
- def exe_path
47
- # Add any standard cmd line arguments we need to pass
48
- @exe_path << " --input=html --server --log=#{@log_file} "
49
- @exe_path << @style_sheets
50
- return @exe_path
51
- end
52
-
53
- # Makes a pdf from a passed in string.
54
- #
55
- # Returns PDF as a stream, so we can use send_data to shoot
56
- # it down the pipe using Rails.
57
- #
58
- def pdf_from_string(string, output_file = '-')
59
- path = self.exe_path()
60
- # Don't spew errors to the standard out...and set up to take IO
61
- # as input and output
62
- path << ' --silent - -o -'
63
-
64
- # Actually call the prince command, and pass the entire data stream back.
65
- pdf = IO.popen(path, "w+")
66
- pdf.puts(string)
67
- pdf.close_write
68
- result = pdf.gets(nil)
69
- pdf.close_read
70
- return result
71
- end
72
-
73
- def pdf_from_string_to_file(string, output_file)
74
- path = self.exe_path()
75
- # Don't spew errors to the standard out...and set up to take IO
76
- # as input and output
77
- path << " --silent - -o '#{output_file}' >> '#{@log_file}' 2>> '#{@log_file}'"
78
-
79
- # Actually call the prince command, and pass the entire data stream back.
80
- pdf = IO.popen(path, "w+")
81
- pdf.puts(string)
82
- pdf.close
83
- end
84
- end