ezprint 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/ezprint.gemspec +14 -16
- data/init.rb +1 -1
- data/lib/ezprint.rb +8 -0
- data/lib/ezprint/pdf_helper.rb +50 -44
- data/lib/ezprint/railtie.rb +18 -0
- metadata +7 -8
- data/.gitignore +0 -22
- data/rails/init.rb +0 -4
data/README
CHANGED
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/ezprint.gemspec
CHANGED
@@ -1,37 +1,35 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ezprint}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jason Stewart"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-01-04}
|
13
13
|
s.description = %q{A Rails wrapper for the PDFkit library. Meant to be a drop in replacement for princely.}
|
14
14
|
s.email = %q{jstewart@fusionary.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
"rails/init.rb"
|
21
|
+
"MIT-LICENSE",
|
22
|
+
"README",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"ezprint.gemspec",
|
27
|
+
"init.rb",
|
28
|
+
"lib/ezprint.rb",
|
29
|
+
"lib/ezprint/pdf_helper.rb",
|
30
|
+
"lib/ezprint/railtie.rb"
|
32
31
|
]
|
33
32
|
s.homepage = %q{http://github.com/jstewart/ezprint}
|
34
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
35
33
|
s.require_paths = ["lib"]
|
36
34
|
s.rubygems_version = %q{1.3.7}
|
37
35
|
s.summary = %q{A Rails wrapper for the PDFkit library. Meant to be a drop in replacement for princely.}
|
data/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.join(File.dirname(__FILE__), "lib", "ezprint")
|
data/lib/ezprint.rb
CHANGED
data/lib/ezprint/pdf_helper.rb
CHANGED
@@ -1,52 +1,58 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
base
|
6
|
-
|
7
|
-
|
8
|
-
|
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)
|
1
|
+
module EzPrint
|
2
|
+
module PdfHelper
|
3
|
+
require 'pdfkit'
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
alias_method_chain :render, :ezprint
|
8
|
+
end
|
16
9
|
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
10
|
|
26
|
-
|
27
|
-
|
28
|
-
|
11
|
+
def render_with_ezprint(options = nil, *args, &block)
|
12
|
+
if options.is_a?(Symbol) or options.nil? or options[:pdf].nil?
|
13
|
+
render_without_ezprint(options, *args, &block)
|
14
|
+
else
|
15
|
+
options[:name] ||= options.delete(:pdf)
|
16
|
+
make_and_send_pdf(options.delete(:name), options)
|
17
|
+
end
|
18
|
+
end
|
29
19
|
|
30
|
-
|
31
|
-
kit.stylesheets = options[:stylesheets].collect{ |style| stylesheet_file_path(style) }
|
20
|
+
private
|
32
21
|
|
33
|
-
|
34
|
-
|
22
|
+
def make_pdf(options = {})
|
23
|
+
options[:stylesheets] ||= []
|
24
|
+
options[:layout] ||= false
|
25
|
+
options[:template] ||= File.join(controller_path,action_name)
|
35
26
|
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
27
|
+
# Stop Rails from appending timestamps to assets.
|
28
|
+
ENV["RAILS_ASSET_ID"] = ''
|
29
|
+
html_string = render_to_string(:template => options[:template], :layout => options[:layout])
|
48
30
|
|
49
|
-
|
50
|
-
|
31
|
+
kit = PDFKit.new(process_html_string(html_string))
|
32
|
+
kit.stylesheets = options[:stylesheets].collect{ |style| stylesheet_file_path(style) }
|
33
|
+
|
34
|
+
kit.to_pdf
|
35
|
+
end
|
36
|
+
|
37
|
+
def make_and_send_pdf(pdf_name, options = {})
|
38
|
+
send_data(
|
39
|
+
make_pdf(options),
|
40
|
+
:filename => pdf_name + ".pdf",
|
41
|
+
:type => 'application/pdf'
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def stylesheet_file_path(stylesheet)
|
46
|
+
stylesheet = stylesheet.to_s.gsub(".css","")
|
47
|
+
File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR,"#{stylesheet}.css")
|
48
|
+
end
|
49
|
+
|
50
|
+
def process_html_string(html)
|
51
|
+
# reroute absolute paths
|
52
|
+
html.gsub!("src=\"/", "src=\"#{RAILS_ROOT}/public/")
|
53
|
+
html.gsub!("href=\"/", "src=\"#{RAILS_ROOT}/public/")
|
54
|
+
html.gsub!("url(/", "url(#{RAILS_ROOT}/public/")
|
55
|
+
html
|
56
|
+
end
|
51
57
|
end
|
52
58
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'action_controller/base'
|
2
|
+
require 'action_dispatch/http/mime_types'
|
3
|
+
require 'ezprint/pdf_helper'
|
4
|
+
|
5
|
+
module EzPrint
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
|
8
|
+
initializer :init_mime_types do
|
9
|
+
Mime::Type.register 'application/pdf', :pdf
|
10
|
+
end
|
11
|
+
|
12
|
+
initializer :insert_into_action_controller do
|
13
|
+
ActiveSupport.on_load :action_controller do
|
14
|
+
ActionController::Base.send(:include, EzPrint::PdfHelper)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ezprint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jason Stewart
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-04 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -45,7 +45,6 @@ extra_rdoc_files:
|
|
45
45
|
- README.rdoc
|
46
46
|
files:
|
47
47
|
- .document
|
48
|
-
- .gitignore
|
49
48
|
- MIT-LICENSE
|
50
49
|
- README
|
51
50
|
- README.rdoc
|
@@ -55,14 +54,14 @@ files:
|
|
55
54
|
- init.rb
|
56
55
|
- lib/ezprint.rb
|
57
56
|
- lib/ezprint/pdf_helper.rb
|
58
|
-
-
|
57
|
+
- lib/ezprint/railtie.rb
|
59
58
|
has_rdoc: true
|
60
59
|
homepage: http://github.com/jstewart/ezprint
|
61
60
|
licenses: []
|
62
61
|
|
63
62
|
post_install_message:
|
64
|
-
rdoc_options:
|
65
|
-
|
63
|
+
rdoc_options: []
|
64
|
+
|
66
65
|
require_paths:
|
67
66
|
- lib
|
68
67
|
required_ruby_version: !ruby/object:Gem::Requirement
|
data/.gitignore
DELETED
data/rails/init.rb
DELETED