Permalink
Browse files

Rails 3 support

  • Loading branch information...
1 parent 9ecf5f3 commit abf76a6b041138cdf737b55cfadd2fab1b684c12 @galetahub galetahub committed Sep 6, 2010
Showing with 38 additions and 22 deletions.
  1. +1 −1 config/routes.rb
  2. +2 −1 init.rb
  3. +11 −20 lib/simple_captcha.rb
  4. +24 −0 lib/simple_captcha/railtie.rb
View
@@ -1,3 +1,3 @@
-Rails.application.routes.draw do |map|
+Rails.application.routes.draw do
match '/simple_captcha/:id', :to => 'simple_captcha#show', :as => :simple_captcha
end
View
@@ -1 +1,2 @@
-require 'simple_captcha'
+# encoding: utf-8
+require File.join(File.dirname(__FILE__), "lib", "simple_captcha")
View
@@ -1,24 +1,13 @@
-require 'simple_captcha/utils'
-require 'simple_captcha/image'
-require 'simple_captcha/view'
-require 'simple_captcha/controller'
-
-if Object.const_defined?("ActionView")
- ActionView::Base.send(:include, SimpleCaptcha::ViewHelper)
- ActionView::Helpers::FormBuilder.send(:include, SimpleCaptcha::FormBuilder)
-end
-
-if Object.const_defined?("ActiveRecord")
- require 'simple_captcha/active_record'
- ActiveRecord::Base.send(:include, SimpleCaptcha::ModelHelpers)
-end
-
-if Object.const_defined?("Formtastic")
- require 'simple_captcha/formtastic'
- Formtastic::SemanticFormHelper.builder = SimpleCaptcha::CustomFormBuilder
-end
-
+# encoding: utf-8
module SimpleCaptcha
+ autoload :Utils, 'simple_captcha/utils'
+ autoload :ImageHelpers, 'simple_captcha/image'
+ autoload :ViewHelper, 'simple_captcha/view'
+ autoload :ControllerHelpers, 'simple_captcha/controller'
+
+ autoload :ModelHelpers, 'simple_captcha/active_record'
+ autoload :CustomFormBuilder, 'simple_captcha/formtastic'
+
mattr_accessor :image_size
@@image_size = "100x28"
@@ -49,3 +38,5 @@ def self.setup
yield self
end
end
+
+require 'simple_captcha/railtie'
@@ -0,0 +1,24 @@
+# encoding: utf-8
+require 'rails'
+require 'simple_captcha'
+
+module SimpleCaptcha
+ class Engine < ::Rails::Engine
+ config.before_initialize do
+ ActiveSupport.on_load :active_record do
+ ActiveRecord::Base.send(:include, SimpleCaptcha::ModelHelpers)
+ end
+ end
+
+ config.after_initialize do
+ ActionView::Base.send(:include, SimpleCaptcha::ViewHelper)
+ ActionView::Helpers::FormBuilder.send(:include, SimpleCaptcha::FormBuilder)
+
+ if Object.const_defined?("Formtastic")
+ Formtastic::SemanticFormHelper.builder = SimpleCaptcha::CustomFormBuilder
+ end
+ end
+ end
+end
+
+

0 comments on commit abf76a6

Please sign in to comment.