norr-prince-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Nicholas Orr
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,28 @@
1
+ = PrinceXML Library for Ruby
2
+
3
+ Simple ruby library to utilise the princexml program.
4
+ Based on the work done by Subimage Interactive - http://www.subimage.com
5
+
6
+ == Usage
7
+
8
+ file = "/tmp/file.pdf"
9
+ prince = Prince.new
10
+ prince.html2pdf_to_file("<p>hello world</p>", file)
11
+
12
+ == PrinceXML
13
+
14
+ Prince is a computer program that converts XML and HTML into PDF documents.
15
+ Prince can read many XML formats, including XHTML and SVG.
16
+ Prince formats documents according to style sheets written in CSS.
17
+
18
+ http://www.princexml.com/
19
+
20
+ == Notes
21
+
22
+ There is vast room for improvement.
23
+ I've only done two methods I'll add to them as I need extra functionality
24
+ I wanted a gem I could simply include in my sinatra / merb projects
25
+
26
+ == Copyright
27
+
28
+ Copyright (c) 2009 Nicholas Orr. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "prince-ruby"
8
+ gem.summary = %Q{TODO}
9
+ gem.email = "nicholas.orr@zxgen.net"
10
+ gem.homepage = "http://github.com/norr/prince-ruby"
11
+ gem.authors = ["Nicholas Orr"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/rdoctask'
20
+ Rake::RDocTask.new do |rdoc|
21
+ if File.exist?('VERSION.yml')
22
+ config = YAML.load(File.read('VERSION.yml'))
23
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
24
+ else
25
+ version = ""
26
+ end
27
+
28
+ rdoc.rdoc_dir = 'rdoc'
29
+ rdoc.title = "prince-ruby #{version}"
30
+ rdoc.rdoc_files.include('README*')
31
+ rdoc.rdoc_files.include('lib/**/*.rb')
32
+ end
33
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,63 @@
1
+ class Prince
2
+
3
+ attr_accessor :exe_path, :style_sheets, :log_file, :options
4
+
5
+ # Initialize method
6
+ #
7
+ def initialize()
8
+ # Finds where the application lives, so we can call it.
9
+ @exe_path = `which prince`.chomp
10
+ @style_sheets = ""
11
+ @log_file = nil
12
+ @options = " --silent --no-network --disallow-modify --disallow-annotate"
13
+ end
14
+
15
+ # Sets stylesheets...
16
+ # Can pass in multiple paths for css files.
17
+ #
18
+ def add_style_sheets(*sheets)
19
+ for sheet in sheets do
20
+ @style_sheets << " -s #{sheet} "
21
+ end
22
+ end
23
+
24
+ # Returns fully formed executable path with any command line switches
25
+ # we've set based on our variables.
26
+ #
27
+ def exe_path
28
+ @exe_path << " --log=#{@log_file}" unless @log_file.nil?
29
+ @exe_path << @options
30
+ @exe_path << @style_sheets
31
+ return @exe_path
32
+ end
33
+
34
+ # Makes a pdf from a passed in string (html).
35
+ #
36
+ def html2pdf_to_string(string)
37
+ path = self.exe_path()
38
+ # set up to take IO as input and output
39
+ path << " --input=html - -o -"
40
+ # Actually call the prince command, and pass the entire data stream back.
41
+ pdf = IO.popen(path, "w+")
42
+ pdf.puts(string)
43
+ pdf.close_write
44
+ output = pdf.gets(nil)
45
+ pdf.close_read
46
+ return output
47
+ end
48
+
49
+ # Makes a pdf from a passed in string (html) and saves to file specified
50
+ # returns true / false if it everything completed ok
51
+ #
52
+ def html2pdf_to_file(string, file)
53
+ path = self.exe_path()
54
+ # set up to take IO as input and output
55
+ path << " --input=html - -o #{file}"
56
+ # Actually call the prince command.
57
+ pdf = IO.popen(path, "w+")
58
+ pdf.puts(string)
59
+ pdf.close
60
+ # see if everything finished ok
61
+ $?.exitstatus == 0
62
+ end
63
+ end
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{prince-ruby}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Nicholas Orr"]
9
+ s.date = %q{2009-07-24}
10
+ s.email = %q{nicholas.orr@zxgen.net}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "lib/prince-ruby.rb",
23
+ "prince-ruby.gemspec"
24
+ ]
25
+ s.has_rdoc = true
26
+ s.homepage = %q{http://github.com/norr/prince-ruby}
27
+ s.rdoc_options = ["--charset=UTF-8"]
28
+ s.require_paths = ["lib"]
29
+ s.rubygems_version = %q{1.3.1}
30
+ s.summary = %q{TODO}
31
+
32
+ if s.respond_to? :specification_version then
33
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
34
+ s.specification_version = 2
35
+
36
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
37
+ else
38
+ end
39
+ else
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: norr-prince-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicholas Orr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-24 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: nicholas.orr@zxgen.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/prince-ruby.rb
33
+ - prince-ruby.gemspec
34
+ has_rdoc: true
35
+ homepage: http://github.com/norr/prince-ruby
36
+ post_install_message:
37
+ rdoc_options:
38
+ - --charset=UTF-8
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project:
56
+ rubygems_version: 1.2.0
57
+ signing_key:
58
+ specification_version: 2
59
+ summary: TODO
60
+ test_files: []
61
+