Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reworking of railspdf to transition to prawn and prawn_view
- Loading branch information
thorny_sun
committed
Jul 1, 2008
1 parent
74c998a
commit 236ba0a
Showing
5 changed files
with
56 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
require 'railspdf' | ||
require 'prawn' | ||
|
||
ActionView::Template.register_template_handler 'rpdf', RailsPDF::PDFRender | ||
ActionView::Template.register_template_handler 'prawn', PrawnView::PrawnView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'prawn' | ||
|
||
module PrawnView | ||
|
||
class PrawnView < ActionView::Base | ||
include ApplicationHelper | ||
|
||
def initialize(action_view) | ||
@action_view = action_view | ||
|
||
# include controller's helper | ||
prefix = action_view.controller.class.to_s.gsub(/Controller/, '') | ||
self.class.send(:include, "#{prefix}Helper".constantize) | ||
end | ||
|
||
def render(template, local_assigns = {}) | ||
controller = @action_view.controller | ||
headers = controller.headers | ||
|
||
#get the instance variables setup | ||
controller.instance_variables.each do |v| | ||
instance_variable_set(v, controller.instance_variable_get(v)) | ||
end | ||
|
||
pragma = 'no-cache' | ||
cache_control = 'no-cache, must-revalidate' | ||
pragma = cache_control = '' if controller.request.env['HTTP_USER_AGENT'] =~ /msie/i #keep ie happy (from railspdf-- no personal knowledge of these issues) | ||
|
||
headers['Pragma'] ||= pragma | ||
headers['Cache-Control'] ||= cache_control | ||
headers["Content-Type"] ||= 'application/pdf' | ||
headers["Content-Disposition"] ||= "attachment; filename=#{@filename}" if @filename #specify @filename in controller otherwise will be inline -- is this true? | ||
|
||
prawn = Prawn::Document.new | ||
eval template.source, prawn, "#{@action_view.base_path}/#{@action_view.first_render}.#{@action_view.finder.pick_template_extension(@action_view.first_render)}" | ||
prawn.render | ||
end | ||
|
||
def compilable? | ||
false | ||
end | ||
|
||
end | ||
end | ||
|
||
module Prawn | ||
class Document | ||
def set_options(options) | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters