Skip to content

Commit

Permalink
Added support for Rails 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Bondarev committed Nov 10, 2010
1 parent bee0f69 commit 24b0f8a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@
**/*.swp
pkg/*
reference_pdfs
.idea
60 changes: 31 additions & 29 deletions lib/prawnto.rb
@@ -1,29 +1,31 @@
$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))

module Prawnto
VERSION='0.0.3'
autoload :ActionControllerMixin, 'prawnto/action_controller_mixin'
autoload :ActionViewMixin, 'prawnto/action_view_mixin'
module TemplateHandlers
autoload :Base, 'prawnto/template_handlers/base'
autoload :Dsl, 'prawnto/template_handlers/dsl'
autoload :Raw, 'prawnto/template_handlers/raw'
end

module TemplateHandler
autoload :CompileSupport, 'prawnto/template_handler/compile_support'
end

class << self
def enable
ActionController::Base.send :include, Prawnto::ActionControllerMixin
ActionView::Base.send :include, Prawnto::ActionViewMixin
Mime::Type.register "application/pdf", :pdf
ActionView::Template.register_template_handler 'prawn', Prawnto::TemplateHandlers::Base
ActionView::Template.register_template_handler 'prawn_dsl', Prawnto::TemplateHandlers::Dsl
ActionView::Template.register_template_handler 'prawn_xxx', Prawnto::TemplateHandlers::Raw
end
end
end

$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))

module Prawnto
VERSION='0.0.4'
autoload :ActionControllerMixin, 'prawnto/action_controller_mixin'
autoload :ActionViewMixin, 'prawnto/action_view_mixin'
module TemplateHandlers
autoload :Base, 'prawnto/template_handlers/base'
autoload :Dsl, 'prawnto/template_handlers/dsl'
autoload :Raw, 'prawnto/template_handlers/raw'
end

module TemplateHandler
autoload :CompileSupport, 'prawnto/template_handler/compile_support'
end

class << self
def enable
ActionController::Base.send :include, Prawnto::ActionControllerMixin
ActionView::Base.send :include, Prawnto::ActionViewMixin
Mime::Type.register "application/pdf", :pdf
ActionView::Template.register_template_handler 'prawn', Prawnto::TemplateHandlers::Base
ActionView::Template.register_template_handler 'prawn_dsl', Prawnto::TemplateHandlers::Dsl
ActionView::Template.register_template_handler 'prawn_xxx', Prawnto::TemplateHandlers::Raw
end
end

require "prawnto/railtie"
end

9 changes: 9 additions & 0 deletions lib/prawnto/railtie.rb
@@ -0,0 +1,9 @@
if defined?(Rails) && defined?(Rails::Railtie)
module Prawnto
class Railtie < Rails::Railtie
initializer 'prawnto.init_config' do
Prawnto.enable
end
end
end
end
4 changes: 1 addition & 3 deletions rails/init.rb
@@ -1,6 +1,4 @@
require 'prawnto'
if defined? Rails && defined? RAILS_ROOT && defined? Prawn
if defined?(Rails) && defined?(Rails.root) && defined?(Prawn)
Prawnto.enable
else
throw "Should be enabled only if Rails && Prawn are both defined"
end

0 comments on commit 24b0f8a

Please sign in to comment.