ezprint 0.1.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/.document +6 -0
- data/.gitignore +22 -0
- data/MIT-LICENSE +20 -0
- data/README +54 -0
- data/README.rdoc +49 -0
- data/Rakefile +41 -0
- data/VERSION +1 -0
- data/ezprint.gemspec +50 -0
- data/init.rb +1 -0
- data/lib/ezprint.rb +1 -0
- data/lib/ezprint/pdf_helper.rb +52 -0
- data/lib/ezprint/rails.rb +3 -0
- data/rails/init.rb +1 -0
- metadata +80 -0
data/.document
ADDED
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Jason Stewart
|
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
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
Ezprint
|
2
|
+
=======
|
3
|
+
|
4
|
+
Ezprint is a drop in replacement for the princely plugin. It uses PDFKit
|
5
|
+
as the backend instead pf princexml, possibly saving you millions of
|
6
|
+
dollars. I recommend using the Rack middleware component of PDFKit to
|
7
|
+
print PDFs in rails, but this plugin makes an easy transition from
|
8
|
+
prince->PDFKit for those using princely.
|
9
|
+
|
10
|
+
Example
|
11
|
+
=======
|
12
|
+
|
13
|
+
The examples here are similar to princely, since the
|
14
|
+
plugin is basically a reworking of the princely source
|
15
|
+
|
16
|
+
class PDFExample < ApplicationController
|
17
|
+
def show
|
18
|
+
respond_to do |format|
|
19
|
+
format.html
|
20
|
+
format.pdf do
|
21
|
+
render :pdf => "My Awesome PDF",
|
22
|
+
:template => "controller/action.pdf.erb",
|
23
|
+
:stylesheets => ["application","print"]
|
24
|
+
:layout => "pdf"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Alternatively, you can use make_and_send_pdf to
|
30
|
+
# render out a PDF for the action without a
|
31
|
+
# respond_to block.
|
32
|
+
def pdf
|
33
|
+
make_and_send_pdf("file_name")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
Render Defaults
|
38
|
+
===============
|
39
|
+
|
40
|
+
The defaults for the render options are as follows:
|
41
|
+
|
42
|
+
layout: false
|
43
|
+
template: the template for the current controller/action
|
44
|
+
stylesheets: none
|
45
|
+
|
46
|
+
Credits
|
47
|
+
=======
|
48
|
+
|
49
|
+
Michael Bleigh for writing the awesome princely plugin, which most of the code is reworked from.
|
50
|
+
|
51
|
+
Resources
|
52
|
+
=========
|
53
|
+
|
54
|
+
Copyright (c) 2010 Jason Stewart, released under the MIT license.
|
data/README.rdoc
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= Ezprint
|
2
|
+
|
3
|
+
Ezprint is a drop in replacement for the princely plugin. It uses PDFKit
|
4
|
+
as the backend instead pf princexml, possibly saving you millions of
|
5
|
+
dollars. I recommend using the Rack middleware component of PDFKit to
|
6
|
+
print PDFs in rails, but this plugin makes an easy transition from
|
7
|
+
prince->PDFKit for those using princely.
|
8
|
+
|
9
|
+
== Example
|
10
|
+
|
11
|
+
The examples here are similar to princely, since the
|
12
|
+
plugin is basically a reworking of the princely source
|
13
|
+
|
14
|
+
class PDFExample < ApplicationController
|
15
|
+
def show
|
16
|
+
respond_to do |format|
|
17
|
+
format.html
|
18
|
+
format.pdf do
|
19
|
+
render :pdf => "My Awesome PDF",
|
20
|
+
:template => "controller/action.pdf.erb",
|
21
|
+
:stylesheets => ["application","print"]
|
22
|
+
:layout => "pdf"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Alternatively, you can use make_and_send_pdf to
|
28
|
+
# render out a PDF for the action without a
|
29
|
+
# respond_to block.
|
30
|
+
def pdf
|
31
|
+
make_and_send_pdf("file_name")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
== Render Defaults
|
36
|
+
|
37
|
+
The defaults for the render options are as follows:
|
38
|
+
|
39
|
+
layout: false
|
40
|
+
template: the template for the current controller/action
|
41
|
+
stylesheets: none
|
42
|
+
|
43
|
+
== Credits
|
44
|
+
|
45
|
+
* Michael Bleigh for writing the awesome princely plugin, which most of the code is reworked from.
|
46
|
+
|
47
|
+
== Resources
|
48
|
+
|
49
|
+
* Copyright (c) 2010 Jason Stewart, released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ezprint"
|
8
|
+
gem.summary = %Q{A Rails wrapper for the PDFkit library. Meant to be a drop in replacement for princely.}
|
9
|
+
gem.description = %Q{A Rails wrapper for the PDFkit library. Meant to be a drop in replacement for princely.}
|
10
|
+
gem.email = "jstewart@fusionary.com"
|
11
|
+
gem.homepage = "http://github.com/jstewart/ezprint"
|
12
|
+
gem.authors = ["Jason Stewart"]
|
13
|
+
end
|
14
|
+
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
23
|
+
test.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
task :default => :test
|
27
|
+
|
28
|
+
require 'rake/rdoctask'
|
29
|
+
Rake::RDocTask.new do |rdoc|
|
30
|
+
if File.exist?('VERSION')
|
31
|
+
version = File.read('VERSION')
|
32
|
+
else
|
33
|
+
version = ""
|
34
|
+
end
|
35
|
+
|
36
|
+
rdoc.rdoc_dir = 'rdoc'
|
37
|
+
rdoc.title = "ezprint #{version}"
|
38
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
39
|
+
rdoc.rdoc_files.include('README*')
|
40
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
41
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/ezprint.gemspec
ADDED
@@ -0,0 +1,50 @@
|
|
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{ezprint}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jason Stewart"]
|
12
|
+
s.date = %q{2010-07-22}
|
13
|
+
s.description = %q{A Rails wrapper for the PDFkit library. Meant to be a drop in replacement for princely.}
|
14
|
+
s.email = %q{jstewart@fusionary.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"MIT-LICENSE",
|
23
|
+
"README",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"ezprint.gemspec",
|
28
|
+
"init.rb",
|
29
|
+
"lib/ezprint.rb",
|
30
|
+
"lib/ezprint/pdf_helper.rb",
|
31
|
+
"lib/ezprint/rails.rb",
|
32
|
+
"rails/init.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/jstewart/ezprint}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.7}
|
38
|
+
s.summary = %q{A Rails wrapper for the PDFkit library. Meant to be a drop in replacement for princely.}
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
else
|
46
|
+
end
|
47
|
+
else
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/rails/init'
|
data/lib/ezprint.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'ezprint/pdf_helper'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module PdfHelper
|
2
|
+
require 'pdfkit'
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
alias_method_chain :render, :ezprint
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def render_with_ezprint(options = nil, *args, &block)
|
11
|
+
if options.is_a?(Symbol) or options.nil? or options[:pdf].nil?
|
12
|
+
render_without_ezprint(options, *args, &block)
|
13
|
+
else
|
14
|
+
options[:name] ||= options.delete(:pdf)
|
15
|
+
make_and_send_pdf(options.delete(:name), options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def make_pdf(options = {})
|
22
|
+
options[:stylesheets] ||= []
|
23
|
+
options[:layout] ||= false
|
24
|
+
options[:template] ||= File.join(controller_path,action_name)
|
25
|
+
|
26
|
+
# Stop Rails from appending timestamps to assets.
|
27
|
+
ENV["RAILS_ASSET_ID"] = ''
|
28
|
+
html_string = render_to_string(:template => options[:template], :layout => options[:layout])
|
29
|
+
|
30
|
+
kit = PDFKit.new(process_html_string(html_string))
|
31
|
+
kit.stylesheets = options[:stylesheets].collect{ |style| stylesheet_file_path(style) }
|
32
|
+
|
33
|
+
kit.to_pdf
|
34
|
+
end
|
35
|
+
|
36
|
+
def make_and_send_pdf(pdf_name, options = {})
|
37
|
+
send_data(
|
38
|
+
make_pdf(options),
|
39
|
+
:filename => pdf_name + ".pdf",
|
40
|
+
:type => 'application/pdf'
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def stylesheet_file_path(stylesheet)
|
45
|
+
stylesheet = stylesheet.to_s.gsub(".css","")
|
46
|
+
File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR,"#{stylesheet}.css")
|
47
|
+
end
|
48
|
+
|
49
|
+
def process_html_string(html)
|
50
|
+
html.gsub!("src=\"/","src=\"#{RAILS_ROOT}/public/") # reroute absolute paths
|
51
|
+
end
|
52
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../lib/ezprint/rails"
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ezprint
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jason Stewart
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-22 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: A Rails wrapper for the PDFkit library. Meant to be a drop in replacement for princely.
|
23
|
+
email: jstewart@fusionary.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README
|
30
|
+
- README.rdoc
|
31
|
+
files:
|
32
|
+
- .document
|
33
|
+
- .gitignore
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README
|
36
|
+
- README.rdoc
|
37
|
+
- Rakefile
|
38
|
+
- VERSION
|
39
|
+
- ezprint.gemspec
|
40
|
+
- init.rb
|
41
|
+
- lib/ezprint.rb
|
42
|
+
- lib/ezprint/pdf_helper.rb
|
43
|
+
- lib/ezprint/rails.rb
|
44
|
+
- rails/init.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://github.com/jstewart/ezprint
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options:
|
51
|
+
- --charset=UTF-8
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.3.7
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: A Rails wrapper for the PDFkit library. Meant to be a drop in replacement for princely.
|
79
|
+
test_files: []
|
80
|
+
|