prawnto_2 0.2.0.beta2 → 0.2.0.beta3

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/README.rdoc CHANGED
@@ -14,7 +14,7 @@ This is my attempt to merge the various forks of the prawnto gem, and <b>update
14
14
 
15
15
  In your <code>Gemfile</code>:
16
16
 
17
- gem "prawnto_2", "0.2.0.beta2", :require => "prawnto"
17
+ gem "prawnto_2", "0.2.0.beta3", :require => "prawnto"
18
18
 
19
19
  Then run:
20
20
 
@@ -62,7 +62,7 @@ Sometimes you need to be able to render a PDF from anywhere (Background process
62
62
  ...
63
63
  def to_pdf
64
64
  @x = 1
65
- Prawnto::Render.to_string "template_path", self
65
+ Prawnto::ModelRenderer.to_string "test/default_render", self
66
66
  end
67
67
  end
68
68
 
data/lib/prawnto.rb CHANGED
@@ -5,11 +5,9 @@ require 'prawnto/railtie' if defined?(Rails)
5
5
 
6
6
  module Prawnto
7
7
  autoload :ActionControllerMixin, 'prawnto/action_controller_mixin'
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
8
+ autoload :ActionViewMixin, 'prawnto/action_view_mixin'
9
+ autoload :CompileSupport, 'prawnto/compile_support'
10
+
13
11
 
14
12
  module TemplateHandlers
15
13
  autoload :Renderer, 'prawnto/template_handlers/renderer'
@@ -18,7 +16,6 @@ module Prawnto
18
16
  autoload :Dsl, 'prawnto/template_handlers/dsl'
19
17
  end
20
18
 
21
- autoload :Render, 'prawnto/pretend_render'
22
-
19
+ autoload :ModelRenderer, 'prawnto/model_renderer'
23
20
 
24
21
  end
@@ -0,0 +1,13 @@
1
+ module Prawnto
2
+ module ActionViewMixin
3
+
4
+ private
5
+
6
+ def _prawnto_compile_setup
7
+ compile_support = CompileSupport.new(controller)
8
+ @prawnto_options = compile_support.options
9
+ end
10
+
11
+ end
12
+ end
13
+
@@ -0,0 +1,72 @@
1
+ module Prawnto
2
+ class CompileSupport
3
+ attr_reader :options
4
+
5
+ def initialize(controller)
6
+ @controller = controller
7
+ @options = pull_options
8
+ set_headers
9
+ end
10
+
11
+ def pull_options
12
+ @controller.send :compute_prawnto_options || {}
13
+ end
14
+
15
+ def set_headers
16
+ unless defined?(ActionMailer) && defined?(ActionMailer::Base) && @controller.is_a?(ActionMailer::Base)
17
+ set_pragma
18
+ set_cache_control
19
+ set_content_type
20
+ set_disposition
21
+ set_other_headers_for_ie_ssl
22
+ end
23
+ end
24
+
25
+ def ie_request?
26
+ @controller.request.env['HTTP_USER_AGENT'] =~ /msie/i
27
+ end
28
+
29
+ def ssl_request?
30
+ @controller.request.ssl?
31
+ end
32
+
33
+ def set_other_headers_for_ie_ssl
34
+ return unless ssl_request? && ie_request?
35
+ headers['Content-Description'] = 'File Transfer'
36
+ headers['Content-Transfer-Encoding'] = 'binary'
37
+ headers['Expires'] = '0'
38
+ end
39
+
40
+ # TODO: kept around from railspdf-- maybe not needed anymore? should check.
41
+ def set_pragma
42
+ if ssl_request? && ie_request?
43
+ @controller.headers['Pragma'] = 'public' # added to make ie ssl pdfs work (per naisayer)
44
+ else
45
+ @controller.headers['Pragma'] ||= ie_request? ? 'no-cache' : ''
46
+ end
47
+ end
48
+
49
+ # TODO: kept around from railspdf-- maybe not needed anymore? should check.
50
+ def set_cache_control
51
+ if ssl_request? && ie_request?
52
+ @controller.headers['Cache-Control'] = 'maxage=1' # added to make ie ssl pdfs work (per naisayer)
53
+ else
54
+ @controller.headers['Cache-Control'] ||= ie_request? ? 'no-cache, must-revalidate' : ''
55
+ end
56
+ end
57
+
58
+ def set_content_type
59
+ @controller.response.content_type ||= Mime::PDF
60
+ end
61
+
62
+ def set_disposition
63
+ inline = options[:inline] ? 'inline' : 'attachment'
64
+ filename = options[:filename] ? "filename=\"#{options[:filename]}\"" : nil
65
+ @controller.headers["Content-Disposition"] = [inline,filename].compact.join(';')
66
+ end
67
+
68
+ end
69
+ end
70
+
71
+
72
+
@@ -1,16 +1,15 @@
1
1
  module Prawnto
2
- module Render
2
+ module ModelRenderer
3
3
  # template : invoices/show.pdf
4
4
  # instance_variables : {"@account" => account} - variables set in before filters
5
5
  def self.to_string(template, calling_object = nil)
6
6
  instance = ApplicationController.new
7
-
8
7
  instance.request = ActionDispatch::Request.new({})
9
8
  instance.response = ActionDispatch::Response.new()
10
9
 
11
- instance_variables.each{|key, value|
12
- instance.instance_variable_set(key, value)
13
- }
10
+ if calling_object
11
+ instance.prawnto :inline => true, :instance_variables_from => calling_object
12
+ end
14
13
 
15
14
  return instance.render_to_string(template, :template => false).html_safe
16
15
  end
@@ -14,7 +14,7 @@ module Prawnto
14
14
  config.to_prepare do
15
15
  ActionController::Base.send :include, Prawnto::ActionControllerMixin
16
16
  ActionMailer::Base.send :include, Prawnto::ActionControllerMixin
17
- ActionView::Base.send :include, Prawnto::ActionViewMixins::ActionViewMixin
17
+ ActionView::Base.send :include, Prawnto::ActionViewMixin
18
18
  end
19
19
 
20
20
  end
@@ -1,11 +1,11 @@
1
1
  module Prawnto
2
2
  module TemplateHandlers
3
3
  class Renderer
4
- def initialize(calling_object = nil)
4
+ def initialize(view_context, calling_object = nil)
5
+ @view_context = view_context
5
6
  @calling_object = calling_object
6
- copy_instance_variables_from(@calling_object) if @calling_object
7
+ set_instance_variables
7
8
  @pdf = Prawn::Document.new(@prawnto_options[:prawn]);
8
- self
9
9
  end
10
10
 
11
11
  def to_pdf(&block)
@@ -15,6 +15,15 @@ module Prawnto
15
15
 
16
16
  private
17
17
 
18
+ def set_instance_variables
19
+ @calling_object ||= @view_context
20
+ copy_instance_variables_from @calling_object
21
+
22
+ if @prawnto_options[:instance_variables_from]
23
+ copy_instance_variables_from @prawnto_options[:instance_variables_from]
24
+ end
25
+ end
26
+
18
27
  def pdf
19
28
  @pdf
20
29
  end
@@ -33,6 +42,8 @@ module Prawnto
33
42
  pdf.send(m, *args)
34
43
  elsif @calling_object.respond_to?(m.to_s)
35
44
  @calling_object.send(m, *args)
45
+ elsif @calling_object != @view_context and @view_context.respond_to?(m.to_s)
46
+ @view_context.send(m, *args)
36
47
  else
37
48
  raise
38
49
  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.2.0.beta2'
4
+ s.version = '0.2.0.beta3'
5
5
  s.author = ["Forrest"]
6
6
  s.email = ["development@forrestzeisler.com"]
7
7
  s.date = Time.now.utc.strftime("%Y-%m-%d")
@@ -2,7 +2,7 @@ class SuperModel
2
2
 
3
3
  def to_pdf
4
4
  @x = 1
5
- Prawnto::Render.to_string "test/default_render", self
5
+ Prawnto::ModelRenderer.to_string "test/default_render", self
6
6
  end
7
7
 
8
8
  end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path("../spec_helper.rb", File.dirname(__FILE__))
2
2
 
3
- describe Prawnto::ActionViewMixins::CompileSupport do
3
+ describe Prawnto::CompileSupport do
4
4
 
5
5
  before do
6
6
  @request = mock()
@@ -14,26 +14,26 @@ describe Prawnto::ActionViewMixins::CompileSupport do
14
14
 
15
15
  describe "#set_disposition" do
16
16
  before do
17
- Prawnto::ActionViewMixins::CompileSupport.any_instance.stubs(:set_pragma).returns(true)
18
- Prawnto::ActionViewMixins::CompileSupport.any_instance.stubs(:set_cache_control).returns(true)
19
- Prawnto::ActionViewMixins::CompileSupport.any_instance.stubs(:set_content_type).returns(Mime::PDF)
17
+ Prawnto::CompileSupport.any_instance.stubs(:set_pragma).returns(true)
18
+ Prawnto::CompileSupport.any_instance.stubs(:set_cache_control).returns(true)
19
+ Prawnto::CompileSupport.any_instance.stubs(:set_content_type).returns(Mime::PDF)
20
20
  end
21
21
 
22
22
  it "default" do
23
23
  @headers.expects("[]=").with("Content-Disposition", "inline").once
24
- Prawnto::ActionViewMixins::CompileSupport.new(@controller)
24
+ Prawnto::CompileSupport.new(@controller)
25
25
  end
26
26
 
27
27
  it "inline with filename" do
28
28
  @controller.stubs(:compute_prawnto_options).returns({:filename => "xxx.pdf", :inline => true})
29
29
  @headers.expects("[]=").with("Content-Disposition", "inline;filename=\"xxx.pdf\"").once
30
- Prawnto::ActionViewMixins::CompileSupport.new(@controller)
30
+ Prawnto::CompileSupport.new(@controller)
31
31
  end
32
32
 
33
33
  it "attachment with filename" do
34
34
  @controller.stubs(:compute_prawnto_options).returns({:filename => "xxx.pdf", :inline => false})
35
35
  @headers.expects("[]=").with("Content-Disposition", "attachment;filename=\"xxx.pdf\"").once
36
- Prawnto::ActionViewMixins::CompileSupport.new(@controller)
36
+ Prawnto::CompileSupport.new(@controller)
37
37
  end
38
38
 
39
39
  end
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.2.0.beta2
4
+ version: 0.2.0.beta3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70318788769400 !ruby/object:Gem::Requirement
16
+ requirement: &70321925128560 !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: *70318788769400
24
+ version_requirements: *70321925128560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: prawn
27
- requirement: &70318788768940 !ruby/object:Gem::Requirement
27
+ requirement: &70321925128100 !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: *70318788768940
35
+ version_requirements: *70321925128100
36
36
  description: Simple PDF generation using the prawn library.
37
37
  email:
38
38
  - development@forrestzeisler.com
@@ -48,9 +48,9 @@ files:
48
48
  - Rakefile
49
49
  - lib/prawnto.rb
50
50
  - lib/prawnto/action_controller_mixin.rb
51
- - lib/prawnto/action_view_mixins/action_view_mixin.rb
52
- - lib/prawnto/action_view_mixins/compile_support.rb
53
- - lib/prawnto/pretend_render.rb
51
+ - lib/prawnto/action_view_mixin.rb
52
+ - lib/prawnto/compile_support.rb
53
+ - lib/prawnto/model_renderer.rb
54
54
  - lib/prawnto/railtie.rb
55
55
  - lib/prawnto/template_handlers/base.rb
56
56
  - lib/prawnto/template_handlers/renderer.rb
@@ -1,15 +0,0 @@
1
- module Prawnto
2
- module ActionViewMixins
3
- module ActionViewMixin
4
-
5
- private
6
-
7
- def _prawnto_compile_setup
8
- compile_support = CompileSupport.new(controller)
9
- @prawnto_options = compile_support.options
10
- end
11
-
12
- end
13
- end
14
- end
15
-
@@ -1,74 +0,0 @@
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) && @controller.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
-