prawnto_2 0.1.2 → 0.2.0.beta
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/.gitignore +3 -0
- data/Gemfile +5 -1
- data/README.rdoc +3 -4
- data/Rakefile +3 -3
- data/lib/prawnto/action_controller_mixin.rb +47 -7
- data/lib/prawnto/action_view_mixins/action_view_mixin.rb +15 -0
- data/lib/prawnto/action_view_mixins/compile_support.rb +74 -0
- data/lib/prawnto/railtie.rb +7 -2
- data/lib/prawnto/template_handlers/base.rb +2 -0
- data/lib/prawnto.rb +6 -26
- data/prawnto.gemspec +2 -2
- data/script/rails +6 -0
- data/spec/assets/hello_world.pdf +69 -0
- data/spec/dummy/.rspec +1 -0
- data/spec/dummy/.sass-cache/387f7b3fde13680ae5a79212c089f81d2d418f1e/application.css.scssc +0 -0
- data/spec/dummy/.sass-cache/6a18c557e07dbc07a14d0809be02d4f21f1dbe91/_shared.css.scssc +0 -0
- data/spec/dummy/.sass-cache/6a18c557e07dbc07a14d0809be02d4f21f1dbe91/ab_tests.css.scssc +0 -0
- data/spec/dummy/.sass-cache/6a18c557e07dbc07a14d0809be02d4f21f1dbe91/application.css.scssc +0 -0
- data/spec/dummy/.sass-cache/6a18c557e07dbc07a14d0809be02d4f21f1dbe91/metrics.css.scssc +0 -0
- data/spec/dummy/.sass-cache/6a18c557e07dbc07a14d0809be02d4f21f1dbe91/reports.css.scssc +0 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +10 -0
- data/spec/dummy/app/assets/javascripts/highcharts.js +170 -0
- data/spec/dummy/app/assets/stylesheets/application.css.scss +78 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/test_controller.rb +7 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +23 -0
- data/spec/dummy/app/views/test/default_render.pdf.prawn +1 -0
- data/spec/dummy/config/application.rb +49 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +60 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/delayed_job +5 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/integrations/test_controller_spec.rb +17 -0
- data/spec/spec_helper.rb +29 -0
- data/{test → spec/support}/template_handler_test_mocks.rb +0 -0
- data/spec/units/action_controller_spec.rb +48 -0
- data/spec/units/compile_support_spec.rb +50 -0
- metadata +104 -20
- data/lib/prawnto/action_controller_mixins/header_methods.rb +0 -68
- data/lib/prawnto/action_controller_mixins/options_manager.rb +0 -56
- data/lib/prawnto/action_view_mixin.rb +0 -13
- data/test/action_controller_test.rb +0 -37
- data/test/base_template_handler_test.rb +0 -34
- data/test/dsl_template_handler_test.rb +0 -37
- data/test/test_helper.rb +0 -17
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
= Prawnto (prawnto_2)
|
|
2
2
|
|
|
3
|
-
A rails plugin providing templating abilities for generating pdf files leveraging the
|
|
3
|
+
A rails plugin providing templating abilities for generating pdf files leveraging the kick-ass prawn library (http://prawn.majesticseacreature.com/)
|
|
4
4
|
|
|
5
|
-
This is my attempt to merge the various forks of the prawnto gem, and <b>update it for Rails 3.1
|
|
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.
|
|
6
6
|
|
|
7
7
|
<b>Note:</b> It has not been tested with earlier versions of Rails.
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ This is my attempt to merge the various forks of the prawnto gem, and <b>update
|
|
|
10
10
|
|
|
11
11
|
In your <code>Gemfile</code>:
|
|
12
12
|
|
|
13
|
-
gem "prawnto_2", :require => "prawnto"
|
|
13
|
+
gem "prawnto_2", "0.2.0.beta", :require => "prawnto"
|
|
14
14
|
|
|
15
15
|
Then run:
|
|
16
16
|
|
|
@@ -30,7 +30,6 @@ In the meantime you can read the original (slightly out of date) documentation/d
|
|
|
30
30
|
|
|
31
31
|
While I can't promise the most speedy response, I do plan to continue to maintain this gem. Please feel free to report any issues, provide feedback, or make suggestions on the {Issue Tracker}[http://github.com/forrest/prawnto/issues]
|
|
32
32
|
|
|
33
|
-
|
|
34
33
|
---
|
|
35
34
|
|
|
36
35
|
|
data/Rakefile
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'rake'
|
|
2
2
|
require 'rake/testtask'
|
|
3
|
-
require 'rdoc/task'
|
|
4
|
-
|
|
3
|
+
require 'rdoc/task'
|
|
4
|
+
require 'rubygems/package_task'
|
|
5
5
|
|
|
6
6
|
desc 'Default: run unit tests.'
|
|
7
7
|
task :default => :test
|
|
@@ -20,4 +20,4 @@ Rake::TestTask.new(:test) do |t|
|
|
|
20
20
|
t.libs << 'lib'
|
|
21
21
|
t.pattern = 'test/*_test.rb'
|
|
22
22
|
# t.verbose = true
|
|
23
|
-
end
|
|
23
|
+
end
|
|
@@ -1,15 +1,55 @@
|
|
|
1
|
-
require "prawnto/action_controller_mixins/options_manager"
|
|
2
|
-
require "prawnto/action_controller_mixins/header_methods"
|
|
3
|
-
|
|
4
1
|
module Prawnto
|
|
5
2
|
module ActionControllerMixin
|
|
3
|
+
DEFAULT_PRAWNTO_OPTIONS = {:inline=>true}
|
|
4
|
+
|
|
6
5
|
def self.included(base)
|
|
7
|
-
base.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
base.send :attr_reader, :prawnto_options
|
|
7
|
+
base.class_attribute :prawn_hash, :prawnto_hash
|
|
8
|
+
base.prawn_hash = {}
|
|
9
|
+
base.prawnto_hash = {}
|
|
10
|
+
base.extend ClassMethods
|
|
11
11
|
end
|
|
12
|
+
|
|
13
|
+
module ClassMethods
|
|
12
14
|
|
|
15
|
+
# This is the class setter. It lets you set default options for all prawn actions within a controller.
|
|
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)
|
|
20
|
+
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
|
+
# Sets the prawn options. Use in the controller method.
|
|
33
|
+
#
|
|
34
|
+
# respond_to {|format|
|
|
35
|
+
# format.pdf { prawnto(:page_orientation => :landscape) }
|
|
36
|
+
# }
|
|
37
|
+
def prawnto(options)
|
|
38
|
+
@prawnto_options ||= {}
|
|
39
|
+
@prawnto_options.merge! options
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
# 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.
|
|
45
|
+
# This is called when setting the header information just before render.
|
|
46
|
+
def compute_prawnto_options
|
|
47
|
+
@prawnto_options ||= DEFAULT_PRAWNTO_OPTIONS.dup
|
|
48
|
+
@prawnto_options[:prawn] ||= {}
|
|
49
|
+
@prawnto_options[:prawn].merge!(self.class.prawn_hash || {}) {|k,o,n| o}
|
|
50
|
+
@prawnto_options.merge!(self.class.prawnto_hash || {}) {|k,o,n| o}
|
|
51
|
+
@prawnto_options
|
|
52
|
+
end
|
|
13
53
|
end
|
|
14
54
|
end
|
|
15
55
|
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module Prawnto
|
|
2
|
+
module ActionViewMixins
|
|
3
|
+
class CompileSupport
|
|
4
|
+
attr_reader :options
|
|
5
|
+
|
|
6
|
+
def initialize(controller)
|
|
7
|
+
@controller = controller
|
|
8
|
+
@options = pull_options
|
|
9
|
+
set_headers
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def pull_options
|
|
13
|
+
@controller.send :compute_prawnto_options || {}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def set_headers
|
|
17
|
+
# unless defined?(ActionMailer) && defined?(ActionMailer::Base) && self.is_a?(ActionMailer::Base)
|
|
18
|
+
set_pragma
|
|
19
|
+
set_cache_control
|
|
20
|
+
set_content_type
|
|
21
|
+
set_disposition
|
|
22
|
+
set_other_headers_for_ie_ssl
|
|
23
|
+
# end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def ie_request?
|
|
27
|
+
@controller.request.env['HTTP_USER_AGENT'] =~ /msie/i
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def ssl_request?
|
|
31
|
+
@controller.request.ssl?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def set_other_headers_for_ie_ssl
|
|
35
|
+
return unless ssl_request? && ie_request?
|
|
36
|
+
headers['Content-Description'] = 'File Transfer'
|
|
37
|
+
headers['Content-Transfer-Encoding'] = 'binary'
|
|
38
|
+
headers['Expires'] = '0'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# TODO: kept around from railspdf-- maybe not needed anymore? should check.
|
|
42
|
+
def set_pragma
|
|
43
|
+
if ssl_request? && ie_request?
|
|
44
|
+
@controller.headers['Pragma'] = 'public' # added to make ie ssl pdfs work (per naisayer)
|
|
45
|
+
else
|
|
46
|
+
@controller.headers['Pragma'] ||= ie_request? ? 'no-cache' : ''
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# TODO: kept around from railspdf-- maybe not needed anymore? should check.
|
|
51
|
+
def set_cache_control
|
|
52
|
+
if ssl_request? && ie_request?
|
|
53
|
+
@controller.headers['Cache-Control'] = 'maxage=1' # added to make ie ssl pdfs work (per naisayer)
|
|
54
|
+
else
|
|
55
|
+
@controller.headers['Cache-Control'] ||= ie_request? ? 'no-cache, must-revalidate' : ''
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def set_content_type
|
|
60
|
+
@controller.response.content_type ||= Mime::PDF
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def set_disposition
|
|
64
|
+
inline = options[:inline] ? 'inline' : 'attachment'
|
|
65
|
+
filename = options[:filename] ? "filename=\"#{options[:filename]}\"" : nil
|
|
66
|
+
@controller.headers["Content-Disposition"] = [inline,filename].compact.join(';')
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
data/lib/prawnto/railtie.rb
CHANGED
|
@@ -2,13 +2,18 @@ module Prawnto
|
|
|
2
2
|
class Railtie < Rails::Railtie
|
|
3
3
|
|
|
4
4
|
# This runs once during initialization.
|
|
5
|
+
# Register the MimeType and the two template handlers.
|
|
5
6
|
initializer "prawnto.register_handlers" do
|
|
6
|
-
|
|
7
|
+
Mime::Type.register("application/pdf", :pdf) unless Mime::Type.lookup_by_extension(:pdf)
|
|
8
|
+
ActionView::Template.register_template_handler 'prawn', Prawnto::TemplateHandlers::Base
|
|
9
|
+
ActionView::Template.register_template_handler 'prawn_dsl', Prawnto::TemplateHandlers::Dsl
|
|
7
10
|
end
|
|
8
11
|
|
|
9
12
|
# This will run it once in production and before each load in development.
|
|
13
|
+
# Include the mixins for ActionController and ActionView.
|
|
10
14
|
config.to_prepare do
|
|
11
|
-
Prawnto
|
|
15
|
+
ActionController::Base.send :include, Prawnto::ActionControllerMixin
|
|
16
|
+
ActionView::Base.send :include, Prawnto::ActionViewMixins::ActionViewMixin
|
|
12
17
|
end
|
|
13
18
|
|
|
14
19
|
end
|
data/lib/prawnto.rb
CHANGED
|
@@ -4,35 +4,15 @@ $:.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
|
-
|
|
8
7
|
autoload :ActionControllerMixin, 'prawnto/action_controller_mixin'
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
module ActionViewMixins
|
|
10
|
+
autoload :ActionViewMixin, 'prawnto/action_view_mixins/action_view_mixin'
|
|
11
|
+
autoload :CompileSupport, 'prawnto/action_view_mixins/compile_support'
|
|
12
|
+
end
|
|
13
|
+
|
|
10
14
|
module TemplateHandlers
|
|
11
15
|
autoload :Base, 'prawnto/template_handlers/base'
|
|
12
16
|
autoload :Dsl, 'prawnto/template_handlers/dsl'
|
|
13
17
|
end
|
|
14
|
-
|
|
15
|
-
class << self
|
|
16
|
-
|
|
17
|
-
# Register the MimeType and the two template handlers.
|
|
18
|
-
def on_init
|
|
19
|
-
Mime::Type.register "application/pdf", :pdf unless defined?(Mime::PDF)
|
|
20
|
-
ActionView::Template.register_template_handler 'prawn', Prawnto::TemplateHandlers::Base
|
|
21
|
-
ActionView::Template.register_template_handler 'prawn_dsl', Prawnto::TemplateHandlers::Dsl
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# Include the mixins for ActionController and ActionView.
|
|
25
|
-
def on_load
|
|
26
|
-
ActionController::Base.send :include, Prawnto::ActionControllerMixin
|
|
27
|
-
ActionView::Base.send :include, Prawnto::ActionViewMixin
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# Runs the registration and include methods. This is used for testing only as railtie.rb usually runs these individually.
|
|
31
|
-
def init_both
|
|
32
|
-
on_init
|
|
33
|
-
on_load
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
end
|
|
37
|
-
|
|
38
18
|
end
|
data/prawnto.gemspec
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
Gem::Specification.new do |s|
|
|
3
3
|
s.name = "prawnto_2"
|
|
4
|
-
s.version = '0.
|
|
4
|
+
s.version = '0.2.0.beta'
|
|
5
5
|
s.author = ["Forrest"]
|
|
6
6
|
s.email = ["development@forrestzeisler.com"]
|
|
7
7
|
s.date = Time.now.utc.strftime("%Y-%m-%d")
|
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
|
14
14
|
|
|
15
15
|
s.required_rubygems_version = ">= 1.3.6"
|
|
16
16
|
s.platform = Gem::Platform::RUBY
|
|
17
|
-
s.add_dependency('rails', '>=3.1')
|
|
17
|
+
s.add_dependency('rails', '>= 3.1')
|
|
18
18
|
s.add_dependency('prawn', '>= 0.12.0')
|
|
19
19
|
|
|
20
20
|
s.files = `git ls-files`.split("\n")
|
data/script/rails
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#!/usr/bin/env ruby
|
|
3
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
|
4
|
+
|
|
5
|
+
ENGINE_PATH = File.expand_path('../..', __FILE__)
|
|
6
|
+
load File.expand_path('../../spec/dummy/script/rails', __FILE__)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
%PDF-1.3
|
|
2
|
+
%����
|
|
3
|
+
1 0 obj
|
|
4
|
+
<< /Creator <feff0050007200610077006e>
|
|
5
|
+
/Producer <feff0050007200610077006e>
|
|
6
|
+
>>
|
|
7
|
+
endobj
|
|
8
|
+
2 0 obj
|
|
9
|
+
<< /Type /Catalog
|
|
10
|
+
/Pages 3 0 R
|
|
11
|
+
>>
|
|
12
|
+
endobj
|
|
13
|
+
3 0 obj
|
|
14
|
+
<< /Type /Pages
|
|
15
|
+
/Count 1
|
|
16
|
+
/Kids [5 0 R]
|
|
17
|
+
>>
|
|
18
|
+
endobj
|
|
19
|
+
4 0 obj
|
|
20
|
+
<< /Length 83
|
|
21
|
+
>>
|
|
22
|
+
stream
|
|
23
|
+
q
|
|
24
|
+
|
|
25
|
+
BT
|
|
26
|
+
36 747.384 Td
|
|
27
|
+
/F1.0 12 Tf
|
|
28
|
+
[<48656c6c6f2057> 30 <6f72> -15 <6c6421>] TJ
|
|
29
|
+
ET
|
|
30
|
+
|
|
31
|
+
Q
|
|
32
|
+
|
|
33
|
+
endstream
|
|
34
|
+
endobj
|
|
35
|
+
5 0 obj
|
|
36
|
+
<< /Type /Page
|
|
37
|
+
/Parent 3 0 R
|
|
38
|
+
/MediaBox [0 0 612.0 792.0]
|
|
39
|
+
/Contents 4 0 R
|
|
40
|
+
/Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
|
|
41
|
+
/Font << /F1.0 6 0 R
|
|
42
|
+
>>
|
|
43
|
+
>>
|
|
44
|
+
>>
|
|
45
|
+
endobj
|
|
46
|
+
6 0 obj
|
|
47
|
+
<< /Type /Font
|
|
48
|
+
/Subtype /Type1
|
|
49
|
+
/BaseFont /Helvetica
|
|
50
|
+
/Encoding /WinAnsiEncoding
|
|
51
|
+
>>
|
|
52
|
+
endobj
|
|
53
|
+
xref
|
|
54
|
+
0 7
|
|
55
|
+
0000000000 65535 f
|
|
56
|
+
0000000015 00000 n
|
|
57
|
+
0000000109 00000 n
|
|
58
|
+
0000000158 00000 n
|
|
59
|
+
0000000215 00000 n
|
|
60
|
+
0000000348 00000 n
|
|
61
|
+
0000000526 00000 n
|
|
62
|
+
trailer
|
|
63
|
+
<< /Size 7
|
|
64
|
+
/Root 2 0 R
|
|
65
|
+
/Info 1 0 R
|
|
66
|
+
>>
|
|
67
|
+
startxref
|
|
68
|
+
623
|
|
69
|
+
%%EOF
|
data/spec/dummy/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--colour
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/spec/dummy/Rakefile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
4
|
+
|
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
|
6
|
+
|
|
7
|
+
Dummy::Application.load_tasks
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
5
|
+
// the compiled file.
|
|
6
|
+
//
|
|
7
|
+
//= require jquery
|
|
8
|
+
//= require jquery-ui
|
|
9
|
+
//= require jquery_ujs
|
|
10
|
+
//= require_tree .
|