prawnto_2 0.2.0.beta → 0.2.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +52 -5
- data/lib/prawnto.rb +6 -0
- data/lib/prawnto/action_controller_mixin.rb +1 -1
- data/lib/prawnto/action_view_mixins/compile_support.rb +2 -2
- data/lib/prawnto/pretend_render.rb +18 -0
- data/lib/prawnto/railtie.rb +2 -1
- data/lib/prawnto/template_handlers/base.rb +2 -4
- data/lib/prawnto/template_handlers/renderer.rb +45 -0
- data/prawnto.gemspec +1 -1
- data/spec/assets/{hello_world.pdf → default_render.pdf} +18 -4
- data/spec/assets/dsl_render.pdf +83 -0
- data/spec/dummy/app/controllers/test_controller.rb +6 -0
- data/spec/dummy/app/helpers/application_helper.rb +3 -0
- data/spec/dummy/app/mailers/pdf_emailer.rb +14 -0
- data/spec/dummy/app/models/super_model.rb +8 -0
- data/spec/dummy/app/views/pdf_emailer/email_with_attachment.text.erb +1 -0
- data/spec/dummy/app/views/test/default_render.pdf.prawn +3 -1
- data/spec/dummy/app/views/test/dsl_render.pdf.prawn +3 -0
- data/spec/dummy/config/routes.rb +2 -0
- data/spec/integrations/pdf_emailer_spec.rb +21 -0
- data/spec/integrations/super_model_spec.rb +16 -0
- data/spec/integrations/test_controller_spec.rb +13 -2
- metadata +23 -10
- data/lib/prawnto/template_handlers/dsl.rb +0 -16
- data/spec/support/template_handler_test_mocks.rb +0 -72
data/README.rdoc
CHANGED
@@ -4,13 +4,17 @@ A rails plugin providing templating abilities for generating pdf files leveragin
|
|
4
4
|
|
5
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
|
+
|
8
|
+
<b>I could use some help with the wiki.</b> If you find this helpful, and aren't up for contributing to the code, I would appreciate some help getting the docs in order.
|
9
|
+
|
10
|
+
|
7
11
|
<b>Note:</b> It has not been tested with earlier versions of Rails.
|
8
12
|
|
9
|
-
== Installation in Rails 3.1
|
13
|
+
== Installation in Rails 3.1+
|
10
14
|
|
11
15
|
In your <code>Gemfile</code>:
|
12
16
|
|
13
|
-
gem "prawnto_2", "0.2.0.
|
17
|
+
gem "prawnto_2", "0.2.0.beta2", :require => "prawnto"
|
14
18
|
|
15
19
|
Then run:
|
16
20
|
|
@@ -18,16 +22,59 @@ Then run:
|
|
18
22
|
|
19
23
|
Now make a view:
|
20
24
|
|
21
|
-
<action name>.pdf.
|
25
|
+
<action name>.pdf.prawn
|
22
26
|
|
23
27
|
== Usage
|
24
28
|
|
25
|
-
|
29
|
+
More Details will be coming to {wiki}[http://github.com/forrest/prawnto/wiki].
|
30
|
+
|
31
|
+
=== As View in Controller
|
32
|
+
|
33
|
+
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).
|
34
|
+
|
35
|
+
=== As Attachment to Email
|
36
|
+
|
37
|
+
You can render PDF's as an attachment to an email very simply with Prawnto.
|
38
|
+
|
39
|
+
class PdfEmailer < ActionMailer::Base
|
40
|
+
default from: "from@example.com"
|
41
|
+
|
42
|
+
def email_with_attachment
|
43
|
+
@var1 = 1
|
44
|
+
attachments["hello_world.pdf"] = render("test/default_render", :format => :pdf)
|
45
|
+
mail :subject => "Hello", :to => "test@test.com" do |format|
|
46
|
+
format.text
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
26
50
|
|
27
|
-
|
51
|
+
If you need something more complicated, you may want to consider using the <code>Prawnto::Render.to_string</code> method listed next to create your attachment content.
|
52
|
+
|
53
|
+
<b>Gotcha:</b> Something odd happens to the default format handling. You have to include the format block at the bottom, and specify the text, html, etc formats you want included on the body.
|
54
|
+
|
55
|
+
=== From Model (or anywhere else)
|
56
|
+
|
57
|
+
Experimental!!!
|
58
|
+
|
59
|
+
Sometimes you need to be able to render a PDF from anywhere (Background process saving to the File, combining PDFs, etc), but you still want access to your helpers. This feature instantiates the most basic controller, and renders the template to a string for you to use. (more info coming to wiki soon)
|
60
|
+
|
61
|
+
class SuperModel
|
62
|
+
...
|
63
|
+
def to_pdf
|
64
|
+
@x = 1
|
65
|
+
Prawnto::Render.to_string "template_path", self
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
== Tips
|
71
|
+
|
72
|
+
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.
|
28
73
|
|
29
74
|
== Contributing & Reporting Issues
|
30
75
|
|
76
|
+
Obviously, all code contributions are greatly appreciated. We also need help with testing and the wiki.
|
77
|
+
|
31
78
|
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
79
|
|
33
80
|
---
|
data/lib/prawnto.rb
CHANGED
@@ -12,7 +12,13 @@ module Prawnto
|
|
12
12
|
end
|
13
13
|
|
14
14
|
module TemplateHandlers
|
15
|
+
autoload :Renderer, 'prawnto/template_handlers/renderer'
|
16
|
+
|
15
17
|
autoload :Base, 'prawnto/template_handlers/base'
|
16
18
|
autoload :Dsl, 'prawnto/template_handlers/dsl'
|
17
19
|
end
|
20
|
+
|
21
|
+
autoload :Render, 'prawnto/pretend_render'
|
22
|
+
|
23
|
+
|
18
24
|
end
|
@@ -14,13 +14,13 @@ module Prawnto
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def set_headers
|
17
|
-
|
17
|
+
unless defined?(ActionMailer) && defined?(ActionMailer::Base) && @controller.is_a?(ActionMailer::Base)
|
18
18
|
set_pragma
|
19
19
|
set_cache_control
|
20
20
|
set_content_type
|
21
21
|
set_disposition
|
22
22
|
set_other_headers_for_ie_ssl
|
23
|
-
|
23
|
+
end
|
24
24
|
end
|
25
25
|
|
26
26
|
def ie_request?
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Prawnto
|
2
|
+
module Render
|
3
|
+
# template : invoices/show.pdf
|
4
|
+
# instance_variables : {"@account" => account} - variables set in before filters
|
5
|
+
def self.to_string(template, calling_object = nil)
|
6
|
+
instance = ApplicationController.new
|
7
|
+
|
8
|
+
instance.request = ActionDispatch::Request.new({})
|
9
|
+
instance.response = ActionDispatch::Response.new()
|
10
|
+
|
11
|
+
instance_variables.each{|key, value|
|
12
|
+
instance.instance_variable_set(key, value)
|
13
|
+
}
|
14
|
+
|
15
|
+
return instance.render_to_string(template, :template => false).html_safe
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/prawnto/railtie.rb
CHANGED
@@ -6,13 +6,14 @@ module Prawnto
|
|
6
6
|
initializer "prawnto.register_handlers" do
|
7
7
|
Mime::Type.register("application/pdf", :pdf) unless Mime::Type.lookup_by_extension(:pdf)
|
8
8
|
ActionView::Template.register_template_handler 'prawn', Prawnto::TemplateHandlers::Base
|
9
|
-
ActionView::Template.register_template_handler 'prawn_dsl', Prawnto::TemplateHandlers::
|
9
|
+
ActionView::Template.register_template_handler 'prawn_dsl', Prawnto::TemplateHandlers::Base # for legacy systems
|
10
10
|
end
|
11
11
|
|
12
12
|
# This will run it once in production and before each load in development.
|
13
13
|
# Include the mixins for ActionController and ActionView.
|
14
14
|
config.to_prepare do
|
15
15
|
ActionController::Base.send :include, Prawnto::ActionControllerMixin
|
16
|
+
ActionMailer::Base.send :include, Prawnto::ActionControllerMixin
|
16
17
|
ActionView::Base.send :include, Prawnto::ActionViewMixins::ActionViewMixin
|
17
18
|
end
|
18
19
|
|
@@ -3,12 +3,10 @@ require "prawn"
|
|
3
3
|
module Prawnto
|
4
4
|
module TemplateHandlers
|
5
5
|
class Base
|
6
|
-
|
7
6
|
def self.call(template)
|
8
7
|
"_prawnto_compile_setup;" +
|
9
|
-
"
|
10
|
-
"#{template.source}\
|
11
|
-
"raw pdf.render;"
|
8
|
+
"renderer = Prawnto::TemplateHandlers::Renderer.new(self);"+
|
9
|
+
"renderer.to_pdf do; #{template.source}\nend;"
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Prawnto
|
2
|
+
module TemplateHandlers
|
3
|
+
class Renderer
|
4
|
+
def initialize(calling_object = nil)
|
5
|
+
@calling_object = calling_object
|
6
|
+
copy_instance_variables_from(@calling_object) if @calling_object
|
7
|
+
@pdf = Prawn::Document.new(@prawnto_options[:prawn]);
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_pdf(&block)
|
12
|
+
instance_eval(&block)
|
13
|
+
@pdf.render.html_safe
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def pdf
|
19
|
+
@pdf
|
20
|
+
end
|
21
|
+
|
22
|
+
# This was removed in Rails 3.1
|
23
|
+
def copy_instance_variables_from(object, exclude = [])
|
24
|
+
vars = object.instance_variables.map(&:to_s) - exclude.map(&:to_s)
|
25
|
+
vars.each { |name| instance_variable_set(name, object.instance_variable_get(name)) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing(m, *args)
|
29
|
+
begin
|
30
|
+
super
|
31
|
+
rescue
|
32
|
+
if pdf.respond_to?(m.to_s)
|
33
|
+
pdf.send(m, *args)
|
34
|
+
elsif @calling_object.respond_to?(m.to_s)
|
35
|
+
@calling_object.send(m, *args)
|
36
|
+
else
|
37
|
+
raise
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
data/prawnto.gemspec
CHANGED
@@ -17,7 +17,7 @@ endobj
|
|
17
17
|
>>
|
18
18
|
endobj
|
19
19
|
4 0 obj
|
20
|
-
<< /Length
|
20
|
+
<< /Length 343
|
21
21
|
>>
|
22
22
|
stream
|
23
23
|
q
|
@@ -28,6 +28,20 @@ BT
|
|
28
28
|
[<48656c6c6f2057> 30 <6f72> -15 <6c6421>] TJ
|
29
29
|
ET
|
30
30
|
|
31
|
+
|
32
|
+
BT
|
33
|
+
36 733.512 Td
|
34
|
+
/F1.0 12 Tf
|
35
|
+
[<696e7374616e63652076> 25 <6172> -15 <696162> 20 <6c65204078203d2031>] TJ
|
36
|
+
ET
|
37
|
+
|
38
|
+
|
39
|
+
BT
|
40
|
+
36 719.6399999999999 Td
|
41
|
+
/F1.0 12 Tf
|
42
|
+
[<68656c706572206d6574686f64732077> 10 <6f72> -15 <6b203a20746869732069732066726f6d20612068656c706572>] TJ
|
43
|
+
ET
|
44
|
+
|
31
45
|
Q
|
32
46
|
|
33
47
|
endstream
|
@@ -57,13 +71,13 @@ xref
|
|
57
71
|
0000000109 00000 n
|
58
72
|
0000000158 00000 n
|
59
73
|
0000000215 00000 n
|
60
|
-
|
61
|
-
|
74
|
+
0000000609 00000 n
|
75
|
+
0000000787 00000 n
|
62
76
|
trailer
|
63
77
|
<< /Size 7
|
64
78
|
/Root 2 0 R
|
65
79
|
/Info 1 0 R
|
66
80
|
>>
|
67
81
|
startxref
|
68
|
-
|
82
|
+
884
|
69
83
|
%%EOF
|
@@ -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 355
|
21
|
+
>>
|
22
|
+
stream
|
23
|
+
q
|
24
|
+
|
25
|
+
BT
|
26
|
+
36 747.384 Td
|
27
|
+
/F1.0 12 Tf
|
28
|
+
[<48656c6c6f2057> 30 <6f72> -15 <6c6421202d2044534c>] TJ
|
29
|
+
ET
|
30
|
+
|
31
|
+
|
32
|
+
BT
|
33
|
+
36 733.512 Td
|
34
|
+
/F1.0 12 Tf
|
35
|
+
[<696e7374616e63652076> 25 <6172> -15 <696162> 20 <6c65204078203d2031>] TJ
|
36
|
+
ET
|
37
|
+
|
38
|
+
|
39
|
+
BT
|
40
|
+
36 719.6399999999999 Td
|
41
|
+
/F1.0 12 Tf
|
42
|
+
[<68656c706572206d6574686f64732077> 10 <6f72> -15 <6b203a20746869732069732066726f6d20612068656c706572>] 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
|
+
0000000621 00000 n
|
75
|
+
0000000799 00000 n
|
76
|
+
trailer
|
77
|
+
<< /Size 7
|
78
|
+
/Root 2 0 R
|
79
|
+
/Info 1 0 R
|
80
|
+
>>
|
81
|
+
startxref
|
82
|
+
896
|
83
|
+
%%EOF
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class PdfEmailer < ActionMailer::Base
|
2
|
+
helper :application
|
3
|
+
default from: "from@example.com"
|
4
|
+
|
5
|
+
def email_with_attachment
|
6
|
+
@x = 1
|
7
|
+
|
8
|
+
attachments["hello_world.pdf"] = render("test/default_render", :format => :pdf)
|
9
|
+
mail :subject => "Hello", :to => "test@test.com" do |format|
|
10
|
+
format.text
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Please see attached PDF
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path("../spec_helper.rb", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe PdfEmailer do
|
4
|
+
describe "email_with_attachment" do
|
5
|
+
before(:all) do
|
6
|
+
@email = PdfEmailer.email_with_attachment.deliver
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have the plain text on the body" do
|
10
|
+
@email.encoded.should include "text\/plain"
|
11
|
+
@email.encoded.should include "Please see attached PDF"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have the PDF attached" do
|
15
|
+
@email.encoded.should include "application\/pdf"
|
16
|
+
@email.encoded.should include "Content-Disposition: attachment;"
|
17
|
+
@email.encoded.should include "filename=hello_world.pdf"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path("../spec_helper.rb", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe SuperModel do
|
4
|
+
|
5
|
+
describe "#to_pdf" do
|
6
|
+
before do
|
7
|
+
@model = SuperModel.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it do
|
11
|
+
asset_binary = File.open(TEST_ASSETS + "/default_render.pdf").read.bytes.to_a
|
12
|
+
@model.to_pdf.bytes.to_a.should == asset_binary
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -3,15 +3,26 @@ require File.expand_path("../spec_helper.rb", File.dirname(__FILE__))
|
|
3
3
|
describe TestController do
|
4
4
|
|
5
5
|
describe "GET default_render" do
|
6
|
-
it "returns
|
6
|
+
it "returns correct PDF" do
|
7
7
|
get "/default_render.pdf"
|
8
8
|
response.should be_success
|
9
9
|
|
10
|
-
asset_binary = File.open(TEST_ASSETS + "/
|
10
|
+
asset_binary = File.open(TEST_ASSETS + "/default_render.pdf").read.bytes.to_a
|
11
11
|
body_binary = response.body.bytes.to_a
|
12
12
|
body_binary.should == asset_binary
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
|
17
|
+
describe "GET dsl_render" do
|
18
|
+
it "returns correct PDF" do
|
19
|
+
get "/dsl_render.pdf"
|
20
|
+
response.should be_success
|
21
|
+
|
22
|
+
asset_binary = File.open(TEST_ASSETS + "/dsl_render.pdf").read.bytes.to_a
|
23
|
+
body_binary = response.body.bytes.to_a
|
24
|
+
body_binary.should == asset_binary
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
17
28
|
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.
|
4
|
+
version: 0.2.0.beta2
|
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: &
|
16
|
+
requirement: &70318788769400 !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: *70318788769400
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: prawn
|
27
|
-
requirement: &
|
27
|
+
requirement: &70318788768940 !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: *70318788768940
|
36
36
|
description: Simple PDF generation using the prawn library.
|
37
37
|
email:
|
38
38
|
- development@forrestzeisler.com
|
@@ -50,13 +50,15 @@ files:
|
|
50
50
|
- lib/prawnto/action_controller_mixin.rb
|
51
51
|
- lib/prawnto/action_view_mixins/action_view_mixin.rb
|
52
52
|
- lib/prawnto/action_view_mixins/compile_support.rb
|
53
|
+
- lib/prawnto/pretend_render.rb
|
53
54
|
- lib/prawnto/railtie.rb
|
54
55
|
- lib/prawnto/template_handlers/base.rb
|
55
|
-
- lib/prawnto/template_handlers/
|
56
|
+
- lib/prawnto/template_handlers/renderer.rb
|
56
57
|
- prawnto.gemspec
|
57
58
|
- rails/init.rb
|
58
59
|
- script/rails
|
59
|
-
- spec/assets/
|
60
|
+
- spec/assets/default_render.pdf
|
61
|
+
- spec/assets/dsl_render.pdf
|
60
62
|
- spec/dummy/.rspec
|
61
63
|
- spec/dummy/.sass-cache/387f7b3fde13680ae5a79212c089f81d2d418f1e/application.css.scssc
|
62
64
|
- spec/dummy/.sass-cache/6a18c557e07dbc07a14d0809be02d4f21f1dbe91/_shared.css.scssc
|
@@ -72,9 +74,13 @@ files:
|
|
72
74
|
- spec/dummy/app/controllers/test_controller.rb
|
73
75
|
- spec/dummy/app/helpers/application_helper.rb
|
74
76
|
- spec/dummy/app/mailers/.gitkeep
|
77
|
+
- spec/dummy/app/mailers/pdf_emailer.rb
|
75
78
|
- spec/dummy/app/models/.gitkeep
|
79
|
+
- spec/dummy/app/models/super_model.rb
|
76
80
|
- spec/dummy/app/views/layouts/application.html.erb
|
81
|
+
- spec/dummy/app/views/pdf_emailer/email_with_attachment.text.erb
|
77
82
|
- spec/dummy/app/views/test/default_render.pdf.prawn
|
83
|
+
- spec/dummy/app/views/test/dsl_render.pdf.prawn
|
78
84
|
- spec/dummy/config.ru
|
79
85
|
- spec/dummy/config/application.rb
|
80
86
|
- spec/dummy/config/boot.rb
|
@@ -98,9 +104,10 @@ files:
|
|
98
104
|
- spec/dummy/public/favicon.ico
|
99
105
|
- spec/dummy/script/delayed_job
|
100
106
|
- spec/dummy/script/rails
|
107
|
+
- spec/integrations/pdf_emailer_spec.rb
|
108
|
+
- spec/integrations/super_model_spec.rb
|
101
109
|
- spec/integrations/test_controller_spec.rb
|
102
110
|
- spec/spec_helper.rb
|
103
|
-
- spec/support/template_handler_test_mocks.rb
|
104
111
|
- spec/units/action_controller_spec.rb
|
105
112
|
- spec/units/compile_support_spec.rb
|
106
113
|
homepage:
|
@@ -129,7 +136,8 @@ specification_version: 3
|
|
129
136
|
summary: This gem allows you to use the PDF mime-type and the simple prawn syntax
|
130
137
|
to generate impressive looking PDFs.
|
131
138
|
test_files:
|
132
|
-
- spec/assets/
|
139
|
+
- spec/assets/default_render.pdf
|
140
|
+
- spec/assets/dsl_render.pdf
|
133
141
|
- spec/dummy/.rspec
|
134
142
|
- spec/dummy/.sass-cache/387f7b3fde13680ae5a79212c089f81d2d418f1e/application.css.scssc
|
135
143
|
- spec/dummy/.sass-cache/6a18c557e07dbc07a14d0809be02d4f21f1dbe91/_shared.css.scssc
|
@@ -145,9 +153,13 @@ test_files:
|
|
145
153
|
- spec/dummy/app/controllers/test_controller.rb
|
146
154
|
- spec/dummy/app/helpers/application_helper.rb
|
147
155
|
- spec/dummy/app/mailers/.gitkeep
|
156
|
+
- spec/dummy/app/mailers/pdf_emailer.rb
|
148
157
|
- spec/dummy/app/models/.gitkeep
|
158
|
+
- spec/dummy/app/models/super_model.rb
|
149
159
|
- spec/dummy/app/views/layouts/application.html.erb
|
160
|
+
- spec/dummy/app/views/pdf_emailer/email_with_attachment.text.erb
|
150
161
|
- spec/dummy/app/views/test/default_render.pdf.prawn
|
162
|
+
- spec/dummy/app/views/test/dsl_render.pdf.prawn
|
151
163
|
- spec/dummy/config.ru
|
152
164
|
- spec/dummy/config/application.rb
|
153
165
|
- spec/dummy/config/boot.rb
|
@@ -171,8 +183,9 @@ test_files:
|
|
171
183
|
- spec/dummy/public/favicon.ico
|
172
184
|
- spec/dummy/script/delayed_job
|
173
185
|
- spec/dummy/script/rails
|
186
|
+
- spec/integrations/pdf_emailer_spec.rb
|
187
|
+
- spec/integrations/super_model_spec.rb
|
174
188
|
- spec/integrations/test_controller_spec.rb
|
175
189
|
- spec/spec_helper.rb
|
176
|
-
- spec/support/template_handler_test_mocks.rb
|
177
190
|
- spec/units/action_controller_spec.rb
|
178
191
|
- spec/units/compile_support_spec.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Prawnto
|
2
|
-
module TemplateHandlers
|
3
|
-
class Dsl < Base
|
4
|
-
|
5
|
-
def self.call(template)
|
6
|
-
"_prawnto_compile_setup;" +
|
7
|
-
"pdf = Prawn::Document.new(@prawnto_options[:prawn]);" +
|
8
|
-
"pdf.instance_eval do; #{template.source}\nend;" +
|
9
|
-
"raw pdf.render;"
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
|
@@ -1,72 +0,0 @@
|
|
1
|
-
module TemplateHandlerTestMocks
|
2
|
-
#
|
3
|
-
# class Template
|
4
|
-
# attr_reader :source, :locals, :filename
|
5
|
-
#
|
6
|
-
# def initialize(source, locals={})
|
7
|
-
# @source = source
|
8
|
-
# @locals = locals
|
9
|
-
# @filename = "blah.pdf"
|
10
|
-
# end
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
|
14
|
-
|
15
|
-
class Request
|
16
|
-
def env
|
17
|
-
{}
|
18
|
-
end
|
19
|
-
|
20
|
-
def ssl?
|
21
|
-
false
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class ActionController
|
26
|
-
include Prawnto::ActionControllerMixin
|
27
|
-
|
28
|
-
def response
|
29
|
-
@response ||= ActionDispatch::TestResponse.new
|
30
|
-
end
|
31
|
-
|
32
|
-
def request
|
33
|
-
@request ||= Request.new
|
34
|
-
end
|
35
|
-
|
36
|
-
def headers
|
37
|
-
response.headers
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class ActionView
|
42
|
-
include Prawnto::ActionViewMixin
|
43
|
-
|
44
|
-
def controller
|
45
|
-
@controller ||= ActionController.new
|
46
|
-
end
|
47
|
-
|
48
|
-
def response
|
49
|
-
controller.response
|
50
|
-
end
|
51
|
-
|
52
|
-
def request
|
53
|
-
controller.request
|
54
|
-
end
|
55
|
-
|
56
|
-
def headers
|
57
|
-
controller.headers
|
58
|
-
end
|
59
|
-
|
60
|
-
def prawnto_options
|
61
|
-
controller.get_instance_variable(:@prawnto_options)
|
62
|
-
end
|
63
|
-
|
64
|
-
def public_prawnto_compile_setup
|
65
|
-
_prawnto_compile_setup
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
|