prawnto_2 0.2.3 → 0.2.4.beta

Sign up to get free protection for your applications and to get access to all the features.
data/Appraisals CHANGED
@@ -4,4 +4,4 @@ end
4
4
 
5
5
  appraise "prawn0.6.3" do
6
6
  gem "prawn", '0.6.3'
7
- end
7
+ end
data/Gemfile CHANGED
@@ -7,3 +7,7 @@ gem "spork", ">= 0.9.0"
7
7
  gem "rspec-rails"
8
8
  gem "mocha"
9
9
  gem "appraisal"
10
+
11
+ gem "guard"
12
+ gem "guard-spork"
13
+ gem "guard-rspec"
@@ -0,0 +1,15 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
5
+ watch('Gemfile')
6
+ watch('Gemfile.lock')
7
+ watch('spec/spec_helper.rb') { :rspec }
8
+ end
9
+
10
+ guard 'rspec', :cli => "--drb", :all_after_pass => false, :version => 2 do
11
+ watch(%r{^spec/.+_spec\.rb$})
12
+ watch(%r{^lib/prawnto/(.+)\.rb$}) { |m| "spec/units/#{m[1]}_spec.rb" }
13
+ watch('spec/spec_helper.rb') { "spec" }
14
+ end
15
+
@@ -19,15 +19,15 @@ In your <code>Gemfile</code>:
19
19
  gem "prawnto_2", :require => "prawnto"
20
20
 
21
21
  Then run:
22
-
22
+
23
23
  bundle install
24
24
 
25
25
  Now make a view:
26
26
 
27
27
  <action name>.pdf.prawn
28
-
28
+
29
29
  ---
30
-
30
+
31
31
  = Usage
32
32
 
33
33
  More Details will be coming to {wiki}[http://github.com/forrest/prawnto/wiki].
@@ -35,11 +35,11 @@ More Details will be coming to {wiki}[http://github.com/forrest/prawnto/wiki].
35
35
  === As View in Controller
36
36
 
37
37
  Simply create additional views that end with <code>.pdf.prawn</code> and rails will use the Prawnto template handler to render it properly. The beta has combined the regular <code>.prawn</code> and <code>.prawn_dsl</code> extensions. Now you won't get tired of typing <code>pdf.method</code>, but instance variables get used. There are a number of options available which are detailed in the wiki (or will be soon).
38
-
38
+
39
39
  === As Attachment to Email
40
40
 
41
41
  You can render PDF's as an attachment to an email very simply with Prawnto.
42
-
42
+
43
43
  class PdfEmailer < ActionMailer::Base
44
44
  default from: "from@example.com"
45
45
 
@@ -76,16 +76,18 @@ Sometimes you need to be able to render a PDF from anywhere (Background process
76
76
 
77
77
  == Tips & Tricks
78
78
 
79
- While layouts and partials aren't yet supported, helper methods can be called from within the PDF views. To help keep PDF's DRY, I would recommend creating a <code>PdfHelper</code> class for complex functionality. Don't forget to add this helper to your emailer if you generate PDF's as attachments.
79
+ Helper methods can be called from within the PDF views. To help keep PDF's DRY, I would recommend creating a <code>PdfHelper</code> class for complex functionality. Don't forget to add this helper to your emailer if you generate PDF's as attachments.
80
+
81
+ Limited partial support is available. Check out the wiki for details.
80
82
 
81
83
  == Testing
82
84
 
83
85
  prawnto uses appraisal to run tests for different versions of prawn. In order to
84
86
  run the specs you first need to install the dependencies for each appraisal:
85
-
87
+
86
88
  rake appraisal:install
87
89
 
88
- Then you can run the tests for a specifc version of prawn (only 0.12.0 and
90
+ Then you can run the tests for a specifc version of prawn (only 0.12.0 and
89
91
  0.6.3, but you can add your own version) or all versions:
90
92
 
91
93
  rake appraisal:prawn0.12.0 spec
@@ -11,11 +11,11 @@ module Prawnto
11
11
 
12
12
  module TemplateHandlers
13
13
  autoload :Renderer, 'prawnto/template_handlers/renderer'
14
-
14
+
15
15
  autoload :Base, 'prawnto/template_handlers/base'
16
16
  autoload :Dsl, 'prawnto/template_handlers/dsl'
17
17
  end
18
-
18
+
19
19
  autoload :ModelRenderer, 'prawnto/model_renderer'
20
-
20
+
21
21
  end
@@ -1,7 +1,7 @@
1
1
  module Prawnto
2
2
  module ActionControllerMixin
3
3
  DEFAULT_PRAWNTO_OPTIONS = {:inline=>true}
4
-
4
+
5
5
  def self.included(base)
6
6
  base.send :attr_reader, :prawnto_options
7
7
  base.class_attribute :prawn_hash, :prawnto_hash
@@ -11,14 +11,14 @@ module Prawnto
11
11
  end
12
12
 
13
13
  module ClassMethods
14
-
14
+
15
15
  # This is the class setter. It lets you set default options for all prawn actions within a controller.
16
16
  def prawnto(options)
17
17
  prawn_options, prawnto_options = breakdown_prawnto_options options
18
18
  self.prawn_hash = prawn_options
19
19
  self.prawnto_hash = DEFAULT_PRAWNTO_OPTIONS.dup.merge(prawnto_options)
20
20
  end
21
-
21
+
22
22
  private
23
23
 
24
24
  # splits the :prawn key out into a seperate hash
@@ -28,7 +28,7 @@ module Prawnto
28
28
  [prawn_options, prawnto_options]
29
29
  end
30
30
  end
31
-
31
+
32
32
  # Sets the prawn options. Use in the controller method.
33
33
  #
34
34
  # respond_to {|format|
@@ -1,6 +1,6 @@
1
1
  module Prawnto
2
2
  module ModelRenderer
3
-
3
+
4
4
  class CustomController < ApplicationController
5
5
  def initialize
6
6
  super
@@ -9,7 +9,7 @@ module Prawnto
9
9
  self.params = {:format => :pdf}
10
10
  end
11
11
  end
12
-
12
+
13
13
  # template : invoices/show.pdf
14
14
  # instance_variables : {"@account" => account} - variables set in before filters
15
15
  def self.to_string(template, calling_object = nil)
@@ -18,9 +18,9 @@ module Prawnto
18
18
  if calling_object
19
19
  instance.prawnto :inline => true, :instance_variables_from => calling_object
20
20
  end
21
-
21
+
22
22
  return instance.render_to_string(:action => template, :template => false, :formats => [:pdf]).html_safe
23
23
  end
24
24
 
25
25
  end
26
- end
26
+ end
@@ -5,10 +5,13 @@ module Prawnto
5
5
  # Register the MimeType and the two template handlers.
6
6
  initializer "prawnto.register_handlers" do
7
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::Base # for legacy systems
8
+
9
+ ActiveSupport.on_load(:action_view) do
10
+ ActionView::Template.register_template_handler :prawn, Prawnto::TemplateHandlers::Base
11
+ ActionView::Template.register_template_handler :prawn_dsl, Prawnto::TemplateHandlers::Base # for legacy systems
12
+ end
10
13
  end
11
-
14
+
12
15
  # This will run it once in production and before each load in development.
13
16
  # Include the mixins for ActionController and ActionView.
14
17
  config.to_prepare do
@@ -16,6 +19,6 @@ module Prawnto
16
19
  ActionMailer::Base.send :include, Prawnto::ActionControllerMixin
17
20
  ActionView::Base.send :include, Prawnto::ActionViewMixin
18
21
  end
19
-
22
+
20
23
  end
21
- end
24
+ end
@@ -8,7 +8,7 @@ module Prawnto
8
8
 
9
9
  "_prawnto_compile_setup;" +
10
10
  "renderer = Prawnto::TemplateHandlers::Renderer.new(self);"+
11
- "renderer.to_pdf do; #{template.source}\nend;"
11
+ "renderer.to_pdf(self) do; #{template.source}\nend;"
12
12
  end
13
13
 
14
14
  private
@@ -0,0 +1,43 @@
1
+ module Prawnto
2
+ module TemplateHandlers
3
+ module Partials
4
+
5
+ # Can be called within a prawn template to render a partial below it.
6
+ # :partial_name - Current has to be the entire path from the views folder. Doesn't recognize the folder of the
7
+ # current template.
8
+ # :prawn_object - The object to use for the pdf object in the partial.
9
+ # Defaults to the pdf document, but can take a paramenter to render within a prawn object. This
10
+ # is good for items like tables, text_blocks, etc.
11
+ def partial!(partial_name, prawn_object = pdf)
12
+ @pdf_stack ||= []
13
+ @pdf_stack.push @pdf
14
+ @pdf = prawn_object
15
+ instance_eval partial_source(partial_name)
16
+ @pdf = @pdf_stack.pop
17
+ end
18
+
19
+ private
20
+
21
+ def partial_source(partial_name)
22
+ #todo: implement some caching
23
+ File.open( get_file_path(partial_name)).read
24
+ end
25
+
26
+ def get_file_path(partial_name)
27
+ root_path = Rails.root
28
+ view_path = File.join(root_path, "app/views/")
29
+ partial_path = cleaned_path(partial_name)
30
+
31
+ file_path = Dir[File.join(view_path, partial_path + ".{*.}prawn")].first
32
+ file_path
33
+ end
34
+
35
+ def cleaned_path(provided_partial_path)
36
+ *provided_path, file_name = provided_partial_path.split("/")
37
+ file_name = "_"+file_name unless file_name[0] == "_"
38
+ File.join(provided_path, file_name)
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -1,44 +1,49 @@
1
+ require "prawnto/template_handlers/partials"
2
+
1
3
  module Prawnto
2
4
  module TemplateHandlers
3
5
  class Renderer
6
+ include Partials
7
+
4
8
  def initialize(view_context, calling_object = nil)
5
9
  @view_context = view_context
6
10
  @calling_object = calling_object
7
11
  set_instance_variables
8
12
  @pdf = Prawn::Document.new(@prawnto_options[:prawn]);
9
13
  end
10
-
11
- def to_pdf(&block)
14
+
15
+ def to_pdf(scope = false, &block)
16
+ @_scope = scope
12
17
  instance_eval(&block)
13
18
  @pdf.render.html_safe
14
19
  end
15
-
20
+
16
21
  private
17
-
22
+
18
23
  def set_instance_variables
19
24
  @calling_object ||= @view_context
20
25
  copy_instance_variables_from @calling_object
21
-
26
+
22
27
  if @prawnto_options[:instance_variables_from]
23
28
  copy_instance_variables_from @prawnto_options[:instance_variables_from]
24
29
  end
25
30
  end
26
-
31
+
27
32
  def pdf
28
33
  @pdf
29
34
  end
30
-
35
+
31
36
  # This was removed in Rails 3.1
32
37
  def copy_instance_variables_from(object, exclude = [])
33
38
  vars = object.instance_variables.map(&:to_s) - exclude.map(&:to_s)
34
39
  vars.each { |name| instance_variable_set(name, object.instance_variable_get(name)) }
35
40
  end
36
-
41
+
37
42
  def push_instance_variables_to(object, exclude = [])
38
43
  vars = instance_variables.map(&:to_s) - exclude.map(&:to_s)
39
44
  vars.each { |name| object.instance_variable_set(name, instance_variable_get(name)) }
40
45
  end
41
-
46
+
42
47
  # This method is a little hacky with pushing the instance variables back. I would prefer to use bindings, but wasn't having much luck.
43
48
  def method_missing(m, *args, &block)
44
49
  begin
@@ -61,8 +66,8 @@ module Prawnto
61
66
  end
62
67
  end
63
68
  end
64
-
69
+
65
70
  end
66
71
  end
67
72
  end
68
-
73
+
@@ -1,7 +1,6 @@
1
-
2
1
  Gem::Specification.new do |s|
3
2
  s.name = "prawnto_2"
4
- s.version = '0.2.3'
3
+ s.version = '0.2.4.beta'
5
4
  s.author = ["Forrest"]
6
5
  s.email = ["development@forrestzeisler.com"]
7
6
  s.date = Time.now.utc.strftime("%Y-%m-%d")
@@ -0,0 +1,83 @@
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 249
21
+ >>
22
+ stream
23
+ q
24
+
25
+ BT
26
+ 36 747.384 Td
27
+ /F1.0 12 Tf
28
+ [<626566> 30 <6f726520706172> -40 <7469616c>] TJ
29
+ ET
30
+
31
+
32
+ BT
33
+ 36 733.512 Td
34
+ /F1.0 12 Tf
35
+ [<696e7369646520706172> -40 <7469616c>] TJ
36
+ ET
37
+
38
+
39
+ BT
40
+ 36 719.6399999999999 Td
41
+ /F1.0 12 Tf
42
+ [<616674657220706172> -40 <7469616c>] TJ
43
+ ET
44
+
45
+ Q
46
+
47
+ endstream
48
+ endobj
49
+ 5 0 obj
50
+ << /Type /Page
51
+ /Parent 3 0 R
52
+ /MediaBox [0 0 612.0 792.0]
53
+ /Contents 4 0 R
54
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
55
+ /Font << /F1.0 6 0 R
56
+ >>
57
+ >>
58
+ >>
59
+ endobj
60
+ 6 0 obj
61
+ << /Type /Font
62
+ /Subtype /Type1
63
+ /BaseFont /Helvetica
64
+ /Encoding /WinAnsiEncoding
65
+ >>
66
+ endobj
67
+ xref
68
+ 0 7
69
+ 0000000000 65535 f
70
+ 0000000015 00000 n
71
+ 0000000109 00000 n
72
+ 0000000158 00000 n
73
+ 0000000215 00000 n
74
+ 0000000515 00000 n
75
+ 0000000693 00000 n
76
+ trailer
77
+ << /Size 7
78
+ /Root 2 0 R
79
+ /Info 1 0 R
80
+ >>
81
+ startxref
82
+ 790
83
+ %%EOF
@@ -0,0 +1,85 @@
1
+ %PDF-1.3
2
+ %����
3
+ 1 0 obj
4
+ << /Creator (Prawn)
5
+ /Producer (Prawn)
6
+ >>
7
+ endobj
8
+ 2 0 obj
9
+ << /Type /Pages
10
+ /Count 1
11
+ /Kids [5 0 R]
12
+ >>
13
+ endobj
14
+ 3 0 obj
15
+ << /Type /Catalog
16
+ /Pages 2 0 R
17
+ >>
18
+ endobj
19
+ 4 0 obj
20
+ << /Length 301
21
+ >>
22
+ stream
23
+ 0.000 0.000 0.000 rg
24
+ 0.000 0.000 0.000 RG
25
+ q
26
+
27
+ BT
28
+ 36 747.384 Td
29
+ /F1.0 12 Tf
30
+ [<626566> 30 <6f726520706172> -40 <7469616c>] TJ
31
+ ET
32
+
33
+
34
+ BT
35
+ 36 733.5120000000001 Td
36
+ /F1.0 12 Tf
37
+ [<696e7369646520706172> -40 <7469616c>] TJ
38
+ ET
39
+
40
+
41
+ BT
42
+ 36 719.6400000000001 Td
43
+ /F1.0 12 Tf
44
+ [<616674657220706172> -40 <7469616c>] TJ
45
+ ET
46
+
47
+ Q
48
+
49
+ endstream
50
+ endobj
51
+ 5 0 obj
52
+ << /Type /Page
53
+ /Parent 2 0 R
54
+ /MediaBox [0 0 612.0 792.0]
55
+ /Contents 4 0 R
56
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
57
+ /Font << /F1.0 6 0 R
58
+ >>
59
+ >>
60
+ >>
61
+ endobj
62
+ 6 0 obj
63
+ << /Type /Font
64
+ /Subtype /Type1
65
+ /BaseFont /Helvetica
66
+ /Encoding /WinAnsiEncoding
67
+ >>
68
+ endobj
69
+ xref
70
+ 0 7
71
+ 0000000000 65535 f
72
+ 0000000015 00000 n
73
+ 0000000071 00000 n
74
+ 0000000128 00000 n
75
+ 0000000177 00000 n
76
+ 0000000529 00000 n
77
+ 0000000707 00000 n
78
+ trailer
79
+ << /Size 7
80
+ /Root 3 0 R
81
+ /Info 1 0 R
82
+ >>
83
+ startxref
84
+ 804
85
+ %%EOF
@@ -4,19 +4,24 @@ class TestController < ApplicationController
4
4
  @x = 1
5
5
  render :action => "default_render"
6
6
  end
7
-
7
+
8
8
  def dsl_render
9
9
  @x = 1
10
10
  render :action => "dsl_render"
11
11
  end
12
-
12
+
13
13
  def instance_var_test
14
14
  @x = 1
15
15
  render :action => "instance_var_test"
16
16
  end
17
-
17
+
18
18
  def yield_block_in_helper_test
19
19
  render :action => "yield_block_in_helper_test"
20
20
  end
21
-
21
+
22
+ def partial_render
23
+ @x = 1
24
+ render :action => "partial_render"
25
+ end
26
+
22
27
  end
@@ -0,0 +1 @@
1
+ text "inside partial"
@@ -0,0 +1,3 @@
1
+ text "before partial"
2
+ partial! "test/simple_partial"
3
+ text "after partial"
@@ -1,8 +1,9 @@
1
1
  Rails.application.routes.draw do
2
2
  get "/default_render" => "test#default_render"
3
+ get "/partial_render" => "test#partial_render"
3
4
  get "/dsl_render" => "test#dsl_render"
4
5
  get "/instance_var_test" => "test#instance_var_test"
5
6
  get "/yield_block_in_helper_test" => "test#yield_block_in_helper_test"
6
-
7
+
7
8
  root :to => "test#default_render"
8
9
  end
@@ -1,22 +1,22 @@
1
1
  require File.expand_path("../spec_helper.rb", File.dirname(__FILE__))
2
2
 
3
3
  describe TestController do
4
-
4
+
5
5
  describe "simple" do
6
6
  it "returns correct PDF" do
7
7
  get "/default_render.pdf"
8
8
  response.should be_success
9
-
9
+
10
10
  asset_binary = File.open(asset_path("default_render")).read.bytes.to_a
11
11
  body_binary = response.body.bytes.to_a
12
12
  body_binary.should == asset_binary
13
13
  end
14
-
15
-
14
+
15
+
16
16
  it "shares values/changes of instance vars between view and helpers" do
17
17
  expect { get "/instance_var_test.pdf" }.should_not raise_error
18
18
  end
19
-
19
+
20
20
  it "should render items in a block passed to a helper" do
21
21
  get "/yield_block_in_helper_test.pdf"
22
22
  asset_binary = File.open(asset_path("yield_block_in_helper_test")).read.bytes.to_a
@@ -24,17 +24,28 @@ describe TestController do
24
24
  body_binary.should == asset_binary
25
25
  end
26
26
  end
27
-
28
-
27
+
28
+
29
29
  describe "dsl" do
30
30
  it "returns correct PDF" do
31
31
  get "/dsl_render.pdf"
32
32
  response.should be_success
33
-
33
+
34
34
  asset_binary = File.open(asset_path("dsl_render")).read.bytes.to_a
35
35
  body_binary = response.body.bytes.to_a
36
36
  body_binary.should == asset_binary
37
37
  end
38
38
  end
39
39
 
40
+ describe "partials" do
41
+ it "renders partials" do
42
+ get "/partial_render.pdf"
43
+ response.should be_success
44
+
45
+ asset_binary = File.open(asset_path("partial_render")).read.bytes.to_a
46
+ body_binary = response.body.bytes.to_a
47
+ body_binary.should == asset_binary
48
+ end
49
+ end
50
+
40
51
  end
@@ -10,22 +10,17 @@ Spork.prefork do
10
10
 
11
11
  Rails.backtrace_cleaner.remove_silencers!
12
12
 
13
- # Load support files
14
- # Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
15
-
16
13
  RSpec.configure do |config|
17
14
  config.mock_with :mocha
18
15
 
19
16
  config.infer_base_class_for_anonymous_controllers = false
20
17
  end
21
-
22
- TEST_ASSETS = File.expand_path("assets", File.dirname(__FILE__)).to_s
23
18
 
19
+ TEST_ASSETS = File.expand_path("assets", File.dirname(__FILE__)).to_s
24
20
  end
25
21
 
26
22
  Spork.each_run do
27
23
  # This code will be run each time you run your specs.
28
-
29
24
  end
30
25
 
31
26
  # Helper to provide asset path given the "base name" of the file.
@@ -1,11 +1,11 @@
1
- require File.expand_path("../spec_helper.rb", File.dirname(__FILE__))
1
+ require "spec_helper"
2
2
 
3
3
  describe TestController do
4
-
4
+
5
5
  class PrawntoControllerWithInlineTrue < TestController
6
6
  prawnto :inline=>true, :prawn=>{:page_orientation=>:landscape}
7
7
  end
8
-
8
+
9
9
  it "Controller should start with the defaults" do
10
10
  @controller = TestController.new
11
11
  @controller.send(:compute_prawnto_options).should == {:inline=>true, :prawn => {}}
@@ -15,22 +15,22 @@ describe TestController do
15
15
  it "should store prawn_hash" do
16
16
  PrawntoControllerWithInlineTrue.prawn_hash.should == {:page_orientation=>:landscape}
17
17
  end
18
-
18
+
19
19
  it "should store prawnto_hash" do
20
20
  PrawntoControllerWithInlineTrue.prawnto_hash.should == {:inline=>true}
21
21
  end
22
22
  end
23
-
23
+
24
24
  describe "#prawnto" do
25
25
  before do
26
26
  @controller = TestController.new
27
27
  @controller.send(:prawnto, {:inline=>false})
28
28
  end
29
-
29
+
30
30
  it "should affect that controller" do
31
31
  @controller.send(:compute_prawnto_options).should == {:inline=>false, :prawn => {}}
32
32
  end
33
-
33
+
34
34
  it "should not affect the controller class" do
35
35
  PrawntoControllerWithInlineTrue.new.send(:compute_prawnto_options).should == {:inline=>true, :prawn=>{:page_orientation=>:landscape}}
36
36
  end
@@ -1,7 +1,7 @@
1
- require File.expand_path("../spec_helper.rb", File.dirname(__FILE__))
1
+ require "spec_helper"
2
2
 
3
3
  describe Prawnto::CompileSupport do
4
-
4
+
5
5
  before do
6
6
  @request = mock()
7
7
  @request.stubs(:ssl?).returns(false)
@@ -18,7 +18,7 @@ describe Prawnto::CompileSupport do
18
18
  Prawnto::CompileSupport.any_instance.stubs(:set_cache_control).returns(true)
19
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
24
  Prawnto::CompileSupport.new(@controller)
@@ -29,7 +29,7 @@ describe Prawnto::CompileSupport do
29
29
  @headers.expects("[]=").with("Content-Disposition", "inline;filename=\"xxx.pdf\"").once
30
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
@@ -37,11 +37,11 @@ describe Prawnto::CompileSupport do
37
37
  end
38
38
 
39
39
  end
40
-
40
+
41
41
  describe "#set_pragma" do
42
42
  pending
43
43
  end
44
-
44
+
45
45
  describe "#set_cache_control" do
46
46
  pending
47
47
  end
@@ -0,0 +1,68 @@
1
+ require "spec_helper"
2
+ require "prawnto/template_handlers/partials.rb"
3
+
4
+ class PartialTester
5
+ attr_accessor :pdf
6
+ include Prawnto::TemplateHandlers::Partials
7
+ end
8
+ describe "Prawnto::TemplateHandlers::Partials" do
9
+ subject do
10
+ PartialTester.new
11
+ end
12
+
13
+ describe "#get_file_path" do
14
+ before { Rails.stubs(:root).returns("") }
15
+
16
+ it "should find partial in the same folder" do
17
+ Dir.expects("[]").with("/app/views/test/_p1.{*.}prawn").returns("some/path")
18
+ path = subject.send :get_file_path, "test/p1"
19
+ end
20
+
21
+ it "won't insert underscore if provided" do
22
+ Dir.expects("[]").with("/app/views/test/_p1.{*.}prawn").returns("some/path")
23
+ path = subject.send :get_file_path, "test/_p1"
24
+ end
25
+
26
+ it "should look in the current folder first"
27
+ end
28
+
29
+ describe "#partial_source" do
30
+ end
31
+
32
+ describe "#render_partial" do
33
+ let(:prawn_object) { mock("prawn_object") }
34
+ let(:nested_prawn_object) { mock("nested_prawn_object") }
35
+ let(:prawn_document) {mock("prawn_document") }
36
+ before {
37
+ subject.stubs(:partial_source).returns("pdf.prawn_method")
38
+ subject.pdf = prawn_document
39
+ }
40
+
41
+ it "should default to rendering off the prawn document" do
42
+ prawn_document.expects(:prawn_method)
43
+ subject.partial! "some/path"
44
+ end
45
+
46
+ it "should default to rendering off the prawn document" do
47
+ prawn_object.expects(:prawn_method)
48
+ subject.partial! "some/path", prawn_object
49
+ end
50
+
51
+ it "should return to the original pdf object upon completion" do
52
+ prawn_object.stubs(:prawn_method)
53
+ subject.partial! "some/path", prawn_object
54
+ subject.pdf.should == prawn_document
55
+ end
56
+
57
+ it "should handle nested partials" do
58
+ subject.stubs(:nested_prawn_object).returns(nested_prawn_object)
59
+ subject.stubs(:partial_source).with("partial1").returns("partial! 'partial2', nested_prawn_object")
60
+ subject.stubs(:partial_source).with("partial2").returns("pdf.nested_prawn_method")
61
+
62
+ nested_prawn_object.expects("nested_prawn_method")
63
+ subject.partial! "partial1", prawn_object
64
+ subject.pdf.should == prawn_document
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+
3
+ describe Prawnto::TemplateHandlers::Renderer do
4
+ end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawnto_2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
5
- prerelease:
4
+ version: 0.2.4.beta
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Forrest
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-23 00:00:00.000000000Z
12
+ date: 2012-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70147047516520 !ruby/object:Gem::Requirement
16
+ requirement: &70333529399900 !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: *70147047516520
24
+ version_requirements: *70333529399900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: prawn
27
- requirement: &70147047515880 !ruby/object:Gem::Requirement
27
+ requirement: &70333529846720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 0.6.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70147047515880
35
+ version_requirements: *70333529846720
36
36
  description: Simple PDF generation using the prawn library.
37
37
  email:
38
38
  - development@forrestzeisler.com
@@ -45,6 +45,7 @@ files:
45
45
  - .travis.yml
46
46
  - Appraisals
47
47
  - Gemfile
48
+ - Guardfile
48
49
  - MIT-LICENSE
49
50
  - README.rdoc
50
51
  - Rakefile
@@ -55,6 +56,7 @@ files:
55
56
  - lib/prawnto/model_renderer.rb
56
57
  - lib/prawnto/railtie.rb
57
58
  - lib/prawnto/template_handlers/base.rb
59
+ - lib/prawnto/template_handlers/partials.rb
58
60
  - lib/prawnto/template_handlers/renderer.rb
59
61
  - prawnto.gemspec
60
62
  - rails/init.rb
@@ -63,6 +65,8 @@ files:
63
65
  - spec/assets/default_render-0.6.3.pdf
64
66
  - spec/assets/dsl_render-0.12.0.pdf
65
67
  - spec/assets/dsl_render-0.6.3.pdf
68
+ - spec/assets/partial_render-0.12.0.pdf
69
+ - spec/assets/partial_render-0.6.3.pdf
66
70
  - spec/assets/yield_block_in_helper_test-0.12.0.pdf
67
71
  - spec/assets/yield_block_in_helper_test-0.6.3.pdf
68
72
  - spec/dummy/.rspec
@@ -85,9 +89,11 @@ files:
85
89
  - spec/dummy/app/models/super_model.rb
86
90
  - spec/dummy/app/views/layouts/application.html.erb
87
91
  - spec/dummy/app/views/pdf_emailer/email_with_attachment.text.erb
92
+ - spec/dummy/app/views/test/_simple_partial.pdf.prawn
88
93
  - spec/dummy/app/views/test/default_render.pdf.prawn
89
94
  - spec/dummy/app/views/test/dsl_render.pdf.prawn
90
95
  - spec/dummy/app/views/test/instance_var_test.pdf.prawn
96
+ - spec/dummy/app/views/test/partial_render.pdf.prawn
91
97
  - spec/dummy/app/views/test/yield_block_in_helper_test.pdf.prawn
92
98
  - spec/dummy/config.ru
93
99
  - spec/dummy/config/application.rb
@@ -116,8 +122,10 @@ files:
116
122
  - spec/integrations/super_model_spec.rb
117
123
  - spec/integrations/test_controller_spec.rb
118
124
  - spec/spec_helper.rb
119
- - spec/units/action_controller_spec.rb
125
+ - spec/units/action_controller_mixin_spec.rb
120
126
  - spec/units/compile_support_spec.rb
127
+ - spec/units/template_handlers/partials_spec.rb
128
+ - spec/units/template_handlers/renderer_spec.rb
121
129
  homepage:
122
130
  licenses: []
123
131
  post_install_message:
@@ -138,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
146
  version: 1.3.6
139
147
  requirements: []
140
148
  rubyforge_project:
141
- rubygems_version: 1.8.10
149
+ rubygems_version: 1.8.17
142
150
  signing_key:
143
151
  specification_version: 3
144
152
  summary: This gem allows you to use the PDF mime-type and the simple prawn syntax
@@ -148,6 +156,8 @@ test_files:
148
156
  - spec/assets/default_render-0.6.3.pdf
149
157
  - spec/assets/dsl_render-0.12.0.pdf
150
158
  - spec/assets/dsl_render-0.6.3.pdf
159
+ - spec/assets/partial_render-0.12.0.pdf
160
+ - spec/assets/partial_render-0.6.3.pdf
151
161
  - spec/assets/yield_block_in_helper_test-0.12.0.pdf
152
162
  - spec/assets/yield_block_in_helper_test-0.6.3.pdf
153
163
  - spec/dummy/.rspec
@@ -170,9 +180,11 @@ test_files:
170
180
  - spec/dummy/app/models/super_model.rb
171
181
  - spec/dummy/app/views/layouts/application.html.erb
172
182
  - spec/dummy/app/views/pdf_emailer/email_with_attachment.text.erb
183
+ - spec/dummy/app/views/test/_simple_partial.pdf.prawn
173
184
  - spec/dummy/app/views/test/default_render.pdf.prawn
174
185
  - spec/dummy/app/views/test/dsl_render.pdf.prawn
175
186
  - spec/dummy/app/views/test/instance_var_test.pdf.prawn
187
+ - spec/dummy/app/views/test/partial_render.pdf.prawn
176
188
  - spec/dummy/app/views/test/yield_block_in_helper_test.pdf.prawn
177
189
  - spec/dummy/config.ru
178
190
  - spec/dummy/config/application.rb
@@ -201,5 +213,7 @@ test_files:
201
213
  - spec/integrations/super_model_spec.rb
202
214
  - spec/integrations/test_controller_spec.rb
203
215
  - spec/spec_helper.rb
204
- - spec/units/action_controller_spec.rb
216
+ - spec/units/action_controller_mixin_spec.rb
205
217
  - spec/units/compile_support_spec.rb
218
+ - spec/units/template_handlers/partials_spec.rb
219
+ - spec/units/template_handlers/renderer_spec.rb