Class: Prince
- Inherits:
-
Object
- Object
- Prince
- Defined in:
- lib/prince-ruby.rb
Instance Attribute Summary collapse
-
#exe_path ⇒ Object
Returns fully formed executable path with any command line switches we’ve set based on our variables.
-
#log_file ⇒ Object
Returns the value of attribute log_file.
-
#options ⇒ Object
Returns the value of attribute options.
-
#style_sheets ⇒ Object
Returns the value of attribute style_sheets.
Instance Method Summary collapse
-
#add_style_sheets(*sheets) ⇒ Object
Sets stylesheets…
-
#html_to_file(string, file) ⇒ Object
Makes a pdf from a passed in string (html) and saves to file specified returns true / false if it everything completed ok.
-
#html_to_string(string) ⇒ Object
Makes a pdf from a passed in string (html).
-
#initialize ⇒ Prince
constructor
Initialize method.
Constructor Details
#initialize ⇒ Prince
Initialize method
7 8 9 10 11 12 13 |
# File 'lib/prince-ruby.rb', line 7 def initialize() # Finds where the application lives, so we can call it. @exe_path = `which prince`.chomp @style_sheets = "" @log_file = nil @options = " --silent --no-network" end |
Instance Attribute Details
#exe_path ⇒ Object
Returns fully formed executable path with any command line switches we’ve set based on our variables.
27 28 29 |
# File 'lib/prince-ruby.rb', line 27 def exe_path @exe_path end |
#log_file ⇒ Object
Returns the value of attribute log_file.
3 4 5 |
# File 'lib/prince-ruby.rb', line 3 def log_file @log_file end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/prince-ruby.rb', line 3 def @options end |
#style_sheets ⇒ Object
Returns the value of attribute style_sheets.
3 4 5 |
# File 'lib/prince-ruby.rb', line 3 def style_sheets @style_sheets end |
Instance Method Details
#add_style_sheets(*sheets) ⇒ Object
Sets stylesheets… Can pass in multiple paths for css files.
18 19 20 21 22 |
# File 'lib/prince-ruby.rb', line 18 def add_style_sheets(*sheets) for sheet in sheets do @style_sheets << " -s #{sheet} " end end |
#html_to_file(string, file) ⇒ Object
Makes a pdf from a passed in string (html) and saves to file specified returns true / false if it everything completed ok
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/prince-ruby.rb', line 52 def html_to_file(string, file) path = self.exe_path() # set up to take IO as input and output path << " --input=html - -o #{file}" # Actually call the prince command. pdf = IO.popen(path, "w+") pdf.puts(string) pdf.close # see if everything finished ok $?.exitstatus == 0 end |
#html_to_string(string) ⇒ Object
Makes a pdf from a passed in string (html).
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/prince-ruby.rb', line 36 def html_to_string(string) path = self.exe_path() # set up to take IO as input and output path << " --input=html - -o -" # Actually call the prince command, and pass the entire data stream back. pdf = IO.popen(path, "w+") pdf.puts(string) pdf.close_write output = pdf.gets(nil) pdf.close_read return output end |