prawnto_2 0.1.0 → 0.1.1
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/MIT-LICENSE +2 -1
- data/README.rdoc +12 -4
- data/lib/prawnto.rb +13 -13
- data/lib/prawnto/action_controller_mixin.rb +7 -45
- data/lib/prawnto/action_controller_mixins/header_methods.rb +68 -0
- data/lib/prawnto/action_controller_mixins/options_manager.rb +56 -0
- data/lib/prawnto/action_view_mixin.rb +4 -3
- data/lib/prawnto/railtie.rb +2 -2
- data/prawnto.gemspec +1 -1
- metadata +9 -8
- data/lib/prawnto/template_handler/compile_support.rb +0 -82
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright on Updates - Copyright (c) 2011 OctopusApp Inc. (http://getjobber.com), released under the MIT license
|
2
|
+
Original Copyright - Copyright (c) 2008 cracklabs.com, released under the MIT license
|
2
3
|
|
3
4
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
5
|
a copy of this software and associated documentation files (the
|
data/README.rdoc
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
A rails plugin providing templating abilities for generating pdf files leveraging the new kick-ass prawn library (http://prawn.majesticseacreature.com/)
|
4
4
|
|
5
|
-
Full (slightly out of date) documentation/demos at: http://cracklabs.com/prawnto
|
6
|
-
|
7
5
|
This is my attempt to merge the various forks of the prawnto gem, and <b>update it for Rails 3.1</b>. I want to thank the many developers who's code I collected together for the gem. Main credit goes to the developer of the initial Prawnto plugin - smecsia.
|
8
6
|
|
9
7
|
<b>Note:</b> It has not been tested with earlier versions of Rails.
|
@@ -13,10 +11,20 @@ This is my attempt to merge the various forks of the prawnto gem, and <b>update
|
|
13
11
|
In your <code>Gemfile</code>:
|
14
12
|
|
15
13
|
gem "prawnto_2", :require => "prawnto"
|
14
|
+
|
15
|
+
Then run:
|
16
|
+
|
17
|
+
bundle install
|
18
|
+
|
19
|
+
Now make a view:
|
20
|
+
|
21
|
+
<action name>.pdf.prawnto
|
16
22
|
|
17
23
|
== Usage
|
18
24
|
|
19
|
-
|
25
|
+
Please check out the {wiki}[http://github.com/forrest/prawnto/wiki] for usage details.
|
26
|
+
|
27
|
+
In the meantime you can read the original (slightly out of date) documentation/demos at: http://cracklabs.com/prawnto
|
20
28
|
|
21
29
|
== Contributing & Reporting Issues
|
22
30
|
|
@@ -26,6 +34,6 @@ While I can't promise the most speedy response, I do plan to continue to maintai
|
|
26
34
|
---
|
27
35
|
|
28
36
|
|
29
|
-
Copyright on Updates - Copyright (c) 2011 getjobber.com, released under the MIT license
|
37
|
+
Copyright on Updates - Copyright (c) 2011 OctopusApp Inc. ({getjobber.com}[http://getjobber.com]), released under the MIT license
|
30
38
|
|
31
39
|
Original Copyright - Copyright (c) 2008 cracklabs.com, released under the MIT license
|
data/lib/prawnto.rb
CHANGED
@@ -4,7 +4,8 @@ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname
|
|
4
4
|
require 'prawnto/railtie' if defined?(Rails)
|
5
5
|
|
6
6
|
module Prawnto
|
7
|
-
VERSION='0.1.
|
7
|
+
VERSION='0.1.1'
|
8
|
+
|
8
9
|
autoload :ActionControllerMixin, 'prawnto/action_controller_mixin'
|
9
10
|
autoload :ActionViewMixin, 'prawnto/action_view_mixin'
|
10
11
|
module TemplateHandlers
|
@@ -12,26 +13,25 @@ module Prawnto
|
|
12
13
|
autoload :Dsl, 'prawnto/template_handlers/dsl'
|
13
14
|
end
|
14
15
|
|
15
|
-
module TemplateHandler
|
16
|
-
autoload :CompileSupport, 'prawnto/template_handler/compile_support'
|
17
|
-
end
|
18
|
-
|
19
16
|
class << self
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
ActionView::Base.send :include, Prawnto::ActionViewMixin
|
24
|
-
end
|
25
|
-
|
26
|
-
def register_handlers
|
18
|
+
# Register the MimeType and the two template handlers.
|
19
|
+
def on_init
|
27
20
|
Mime::Type.register "application/pdf", :pdf unless defined?(Mime::PDF)
|
28
21
|
ActionView::Template.register_template_handler 'prawn', Prawnto::TemplateHandlers::Base
|
29
22
|
ActionView::Template.register_template_handler 'prawn_dsl', Prawnto::TemplateHandlers::Dsl
|
30
23
|
end
|
31
24
|
|
25
|
+
# Include the mixins for ActionController and ActionView.
|
26
|
+
def on_load
|
27
|
+
ActionController::Base.send :include, Prawnto::ActionControllerMixin
|
28
|
+
ActionView::Base.send :include, Prawnto::ActionViewMixin
|
29
|
+
end
|
30
|
+
|
31
|
+
# Runs the registration and include methods. This is used for testing only as railtie.rb usually runs these individually.
|
32
32
|
def init_both
|
33
|
-
|
34
|
-
|
33
|
+
on_init
|
34
|
+
on_load
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
@@ -1,53 +1,15 @@
|
|
1
|
+
require "prawnto/action_controller_mixins/options_manager"
|
2
|
+
require "prawnto/action_controller_mixins/header_methods"
|
3
|
+
|
1
4
|
module Prawnto
|
2
5
|
module ActionControllerMixin
|
3
|
-
|
4
|
-
DEFAULT_PRAWNTO_OPTIONS = {:inline=>true}
|
5
|
-
|
6
6
|
def self.included(base)
|
7
|
-
base.
|
8
|
-
|
9
|
-
|
10
|
-
base.extend ClassMethods
|
11
|
-
end
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
|
15
|
-
# Sets options in the class attributes. Can be pulled into the instance variable with :compute_prawnto_options
|
16
|
-
def prawnto(options)
|
17
|
-
prawn_options, prawnto_options = breakdown_prawnto_options options
|
18
|
-
self.prawn_hash = prawn_options
|
19
|
-
self.prawnto_hash = DEFAULT_PRAWNTO_OPTIONS.dup.merge(prawnto_options)
|
7
|
+
base.class_eval do
|
8
|
+
include HeaderMethods
|
9
|
+
include OptionsManager
|
20
10
|
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
# splits the :prawn key out into a seperate hash
|
25
|
-
def breakdown_prawnto_options(options)
|
26
|
-
prawnto_options = options.dup
|
27
|
-
prawn_options = (prawnto_options.delete(:prawn) || {}).dup
|
28
|
-
[prawn_options, prawnto_options]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
# Sets options directly on the instance
|
34
|
-
def prawnto(options)
|
35
|
-
@prawnto_options ||= {}
|
36
|
-
@prawnto_options.merge! options
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
# Used to set the @prawnto_options variable before rendering. Called from compile_support just before rendering.
|
43
|
-
def compute_prawnto_options
|
44
|
-
@prawnto_options ||= DEFAULT_PRAWNTO_OPTIONS.dup
|
45
|
-
@prawnto_options[:prawn] ||= {}
|
46
|
-
@prawnto_options[:prawn].merge!(self.class.prawn_hash || {}) {|k,o,n| o}
|
47
|
-
@prawnto_options.merge!(self.class.prawnto_hash || {}) {|k,o,n| o}
|
48
|
-
@prawnto_options
|
49
11
|
end
|
50
|
-
|
12
|
+
|
51
13
|
end
|
52
14
|
end
|
53
15
|
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Prawnto
|
2
|
+
module ActionControllerMixin
|
3
|
+
module HeaderMethods
|
4
|
+
|
5
|
+
|
6
|
+
def set_headers
|
7
|
+
compute_prawnto_options
|
8
|
+
|
9
|
+
unless defined?(ActionMailer) && defined?(ActionMailer::Base) && self.is_a?(ActionMailer::Base)
|
10
|
+
set_pragma
|
11
|
+
set_cache_control
|
12
|
+
set_content_type
|
13
|
+
set_disposition
|
14
|
+
set_other_headers_for_ie_ssl
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# TODO: kept around from railspdf-- maybe not needed anymore? should check.
|
21
|
+
def ie_request?
|
22
|
+
request.env['HTTP_USER_AGENT'] =~ /msie/i
|
23
|
+
end
|
24
|
+
# memoize :ie_request?
|
25
|
+
|
26
|
+
# added to make ie happy with ssl pdf's (per naisayer)
|
27
|
+
def ssl_request?
|
28
|
+
request.ssl?
|
29
|
+
end
|
30
|
+
# memoize :ssl_request?
|
31
|
+
|
32
|
+
def set_other_headers_for_ie_ssl
|
33
|
+
return unless ssl_request? && ie_request?
|
34
|
+
headers['Content-Description'] = 'File Transfer'
|
35
|
+
headers['Content-Transfer-Encoding'] = 'binary'
|
36
|
+
headers['Expires'] = '0'
|
37
|
+
end
|
38
|
+
|
39
|
+
# TODO: kept around from railspdf-- maybe not needed anymore? should check.
|
40
|
+
def set_pragma
|
41
|
+
if ssl_request? && ie_request?
|
42
|
+
headers['Pragma'] = 'public' # added to make ie ssl pdfs work (per naisayer)
|
43
|
+
else
|
44
|
+
headers['Pragma'] ||= ie_request? ? 'no-cache' : ''
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# TODO: kept around from railspdf-- maybe not needed anymore? should check.
|
49
|
+
def set_cache_control
|
50
|
+
if ssl_request? && ie_request?
|
51
|
+
headers['Cache-Control'] = 'maxage=1' # added to make ie ssl pdfs work (per naisayer)
|
52
|
+
else
|
53
|
+
headers['Cache-Control'] ||= ie_request? ? 'no-cache, must-revalidate' : ''
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_content_type
|
58
|
+
response.content_type ||= Mime::PDF
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_disposition
|
62
|
+
inline = @prawnto_options[:inline] ? 'inline' : 'attachment'
|
63
|
+
filename = @prawnto_options[:filename] ? "filename=\"#{@prawnto_options[:filename]}\"" : nil
|
64
|
+
headers["Content-Disposition"] = [inline,filename].compact.join(';')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Prawnto
|
2
|
+
module ActionControllerMixin
|
3
|
+
module OptionsManager
|
4
|
+
DEFAULT_PRAWNTO_OPTIONS = {:inline=>true}
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.send :attr_reader, :prawnto_options
|
8
|
+
base.class_attribute :prawn_hash, :prawnto_hash
|
9
|
+
base.prawn_hash = {}
|
10
|
+
base.prawnto_hash = {}
|
11
|
+
base.extend ClassMethods
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
|
16
|
+
# This is the class setter. It lets you set default options for all prawn actions within a controller.
|
17
|
+
def prawnto(options)
|
18
|
+
prawn_options, prawnto_options = breakdown_prawnto_options options
|
19
|
+
self.prawn_hash = prawn_options
|
20
|
+
self.prawnto_hash = DEFAULT_PRAWNTO_OPTIONS.dup.merge(prawnto_options)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# splits the :prawn key out into a seperate hash
|
26
|
+
def breakdown_prawnto_options(options)
|
27
|
+
prawnto_options = options.dup
|
28
|
+
prawn_options = (prawnto_options.delete(:prawn) || {}).dup
|
29
|
+
[prawn_options, prawnto_options]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Sets the prawn options. Use in the controller method.
|
34
|
+
#
|
35
|
+
# respond_to {|format|
|
36
|
+
# format.pdf { prawnto(:page_orientation => :landscape) }
|
37
|
+
# }
|
38
|
+
def prawnto(options)
|
39
|
+
@prawnto_options ||= {}
|
40
|
+
@prawnto_options.merge! options
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# this merges the default prawnto options, the controller prawnto options, and the instance prawnto options, and the splits out then joins in the :prawn options.
|
46
|
+
# This is called when setting the header information just before render.
|
47
|
+
def compute_prawnto_options
|
48
|
+
@prawnto_options ||= DEFAULT_PRAWNTO_OPTIONS.dup
|
49
|
+
@prawnto_options[:prawn] ||= {}
|
50
|
+
@prawnto_options[:prawn].merge!(self.class.prawn_hash || {}) {|k,o,n| o}
|
51
|
+
@prawnto_options.merge!(self.class.prawnto_hash || {}) {|k,o,n| o}
|
52
|
+
@prawnto_options
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module Prawnto
|
2
2
|
module ActionViewMixin
|
3
3
|
|
4
|
-
|
4
|
+
private
|
5
|
+
|
5
6
|
def _prawnto_compile_setup
|
6
|
-
|
7
|
-
@prawnto_options =
|
7
|
+
controller.set_headers
|
8
|
+
@prawnto_options = controller.prawnto_options
|
8
9
|
end
|
9
10
|
|
10
11
|
end
|
data/lib/prawnto/railtie.rb
CHANGED
@@ -3,12 +3,12 @@ module Prawnto
|
|
3
3
|
|
4
4
|
# This runs once during initialization.
|
5
5
|
initializer "prawnto.register_handlers" do
|
6
|
-
Prawnto.
|
6
|
+
Prawnto.on_init
|
7
7
|
end
|
8
8
|
|
9
9
|
# This will run it once in production and before each load in development.
|
10
10
|
config.to_prepare do
|
11
|
-
Prawnto.
|
11
|
+
Prawnto.on_load
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
data/prawnto.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.description = 'Simple PDF generation using the prawn library.'
|
12
12
|
s.summary = "This gem allows you to use the PDF mime-type and the simple prawn syntax to generate impressive looking PDFs."
|
13
13
|
|
14
|
-
s.homepage = "http://cracklabs.com/prawnto"
|
14
|
+
# s.homepage = "http://cracklabs.com/prawnto"
|
15
15
|
|
16
16
|
s.required_rubygems_version = ">= 1.3.6"
|
17
17
|
s.platform = Gem::Platform::RUBY
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawnto_2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-18 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156441200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156441200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: prawn
|
27
|
-
requirement: &
|
27
|
+
requirement: &2156440740 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 0.12.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2156440740
|
36
36
|
description: Simple PDF generation using the prawn library.
|
37
37
|
email:
|
38
38
|
- development@forrestzeisler.com
|
@@ -48,9 +48,10 @@ files:
|
|
48
48
|
- Rakefile
|
49
49
|
- lib/prawnto.rb
|
50
50
|
- lib/prawnto/action_controller_mixin.rb
|
51
|
+
- lib/prawnto/action_controller_mixins/header_methods.rb
|
52
|
+
- lib/prawnto/action_controller_mixins/options_manager.rb
|
51
53
|
- lib/prawnto/action_view_mixin.rb
|
52
54
|
- lib/prawnto/railtie.rb
|
53
|
-
- lib/prawnto/template_handler/compile_support.rb
|
54
55
|
- lib/prawnto/template_handlers/base.rb
|
55
56
|
- lib/prawnto/template_handlers/dsl.rb
|
56
57
|
- prawnto.gemspec
|
@@ -60,7 +61,7 @@ files:
|
|
60
61
|
- test/dsl_template_handler_test.rb
|
61
62
|
- test/template_handler_test_mocks.rb
|
62
63
|
- test/test_helper.rb
|
63
|
-
homepage:
|
64
|
+
homepage:
|
64
65
|
licenses: []
|
65
66
|
post_install_message:
|
66
67
|
rdoc_options: []
|
@@ -1,82 +0,0 @@
|
|
1
|
-
module Prawnto
|
2
|
-
module TemplateHandler
|
3
|
-
|
4
|
-
class CompileSupport
|
5
|
-
extend ActiveSupport::Memoizable
|
6
|
-
|
7
|
-
attr_reader :options
|
8
|
-
|
9
|
-
def initialize(controller)
|
10
|
-
@controller = controller
|
11
|
-
@options = pull_options
|
12
|
-
set_headers
|
13
|
-
end
|
14
|
-
|
15
|
-
# This sets the @options hash which is used for rendering.
|
16
|
-
def pull_options
|
17
|
-
@controller.send :compute_prawnto_options || {}
|
18
|
-
end
|
19
|
-
|
20
|
-
def set_headers
|
21
|
-
unless defined?(ActionMailer) && defined?(ActionMailer::Base) && @controller.is_a?(ActionMailer::Base)
|
22
|
-
set_pragma
|
23
|
-
set_cache_control
|
24
|
-
set_content_type
|
25
|
-
set_disposition
|
26
|
-
set_other_headers_for_ie_ssl
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# TODO: kept around from railspdf-- maybe not needed anymore? should check.
|
31
|
-
def ie_request?
|
32
|
-
@controller.request.env['HTTP_USER_AGENT'] =~ /msie/i
|
33
|
-
end
|
34
|
-
memoize :ie_request?
|
35
|
-
|
36
|
-
# added to make ie happy with ssl pdf's (per naisayer)
|
37
|
-
def ssl_request?
|
38
|
-
@controller.request.ssl?
|
39
|
-
end
|
40
|
-
memoize :ssl_request?
|
41
|
-
|
42
|
-
def set_other_headers_for_ie_ssl
|
43
|
-
return unless ssl_request? && ie_request?
|
44
|
-
@controller.headers['Content-Description'] = 'File Transfer'
|
45
|
-
@controller.headers['Content-Transfer-Encoding'] = 'binary'
|
46
|
-
@controller.headers['Expires'] = '0'
|
47
|
-
end
|
48
|
-
|
49
|
-
# TODO: kept around from railspdf-- maybe not needed anymore? should check.
|
50
|
-
def set_pragma
|
51
|
-
if ssl_request? && ie_request?
|
52
|
-
@controller.headers['Pragma'] = 'public' # added to make ie ssl pdfs work (per naisayer)
|
53
|
-
else
|
54
|
-
@controller.headers['Pragma'] ||= ie_request? ? 'no-cache' : ''
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# TODO: kept around from railspdf-- maybe not needed anymore? should check.
|
59
|
-
def set_cache_control
|
60
|
-
if ssl_request? && ie_request?
|
61
|
-
@controller.headers['Cache-Control'] = 'maxage=1' # added to make ie ssl pdfs work (per naisayer)
|
62
|
-
else
|
63
|
-
@controller.headers['Cache-Control'] ||= ie_request? ? 'no-cache, must-revalidate' : ''
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def set_content_type
|
68
|
-
@controller.response.content_type ||= Mime::PDF
|
69
|
-
end
|
70
|
-
|
71
|
-
def set_disposition
|
72
|
-
inline = options[:inline] ? 'inline' : 'attachment'
|
73
|
-
filename = options[:filename] ? "filename=\"#{options[:filename]}\"" : nil
|
74
|
-
@controller.headers["Content-Disposition"] = [inline,filename].compact.join(';')
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
|