prince-ruby 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -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.
@@ -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.
@@ -0,0 +1,53 @@
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{Simple PrinceXML ruby lib}
9
+ gem.description = %Q{PrinceXML is a PDF generator that takes html,css input. This gem is a simple wrapper for use with ruby apps}
10
+ gem.email = "nicholas.orr@zxgen.net"
11
+ gem.homepage = "http://github.com/norr/prince-ruby"
12
+ gem.authors = ["Nicholas Orr"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "prince-ruby #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.1
@@ -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 html_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 html_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,48 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{prince-ruby}
8
+ s.version = "0.2.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nicholas Orr"]
12
+ s.date = %q{2010-01-13}
13
+ s.description = %q{PrinceXML is a PDF generator that takes html,css input. This gem is a simple wrapper for use with ruby apps}
14
+ s.email = %q{nicholas.orr@zxgen.net}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/prince-ruby.rb",
27
+ "prince-ruby.gemspec"
28
+ ]
29
+ s.homepage = %q{http://github.com/norr/prince-ruby}
30
+ s.rdoc_options = ["--charset=UTF-8"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.5}
33
+ s.summary = %q{Simple PrinceXML ruby lib}
34
+
35
+ if s.respond_to? :specification_version then
36
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
40
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
41
+ else
42
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
43
+ end
44
+ else
45
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
46
+ end
47
+ end
48
+
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prince-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Nicholas Orr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-13 00:00:00 +11:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: PrinceXML is a PDF generator that takes html,css input. This gem is a simple wrapper for use with ruby apps
26
+ email: nicholas.orr@zxgen.net
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/prince-ruby.rb
42
+ - prince-ruby.gemspec
43
+ has_rdoc: true
44
+ homepage: http://github.com/norr/prince-ruby
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.5
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Simple PrinceXML ruby lib
71
+ test_files: []
72
+