Skip to content

Commit

Permalink
reworking of railspdf to transition to prawn and prawn_view
Browse files Browse the repository at this point in the history
  • Loading branch information
thorny_sun committed Jul 1, 2008
1 parent 74c998a commit 236ba0a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 66 deletions.
4 changes: 2 additions & 2 deletions init.rb
@@ -1,3 +1,3 @@
require 'railspdf'
require 'prawn'

ActionView::Template.register_template_handler 'rpdf', RailsPDF::PDFRender
ActionView::Template.register_template_handler 'prawn', PrawnView::PrawnView
49 changes: 49 additions & 0 deletions lib/prawn_view.rb
@@ -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)

59 changes: 0 additions & 59 deletions lib/railspdf.rb

This file was deleted.

6 changes: 3 additions & 3 deletions test/railspdf_test.rb → test/prawn_view_test.rb
Expand Up @@ -3,10 +3,10 @@
class SomeController; end
module SomeHelper; end

class RailsPDF::PDFRenderTest < Test::Unit::TestCase
class PrawnView::PrawnViewTest < Test::Unit::TestCase
def test_should_not_be_compilable
view = stub(:controller => SomeController.new)
pdf = RailsPDF::PDFRender.new(view)
assert !pdf.compilable?
prawn_view = PrawnView::PrawnView.new(view)
assert !prawn_view.compilable?
end
end
4 changes: 2 additions & 2 deletions test/test_helper.rb
Expand Up @@ -5,5 +5,5 @@
module ApplicationHelper; end

$LOAD_PATH << File.dirname(__FILE__) + '/../lib'
require 'railspdf'
require 'mocha'
require 'prawn'
require 'mocha'

0 comments on commit 236ba0a

Please sign in to comment.