Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rails 3.0.0.beta3 support

  • Loading branch information...
commit c0e24fd936fa11095920d617a98e6597d5e580c2 1 parent 3c810b7
@galetahub galetahub authored
Showing with 256 additions and 404 deletions.
  1. +0 −20 MIT-LICENSE
  2. +0 −237 README
  3. +165 −0 README.rdoc
  4. +0 −2  Rakefile
  5. +0 −4 {lib → app/controllers}/simple_captcha_controller.rb
  6. +0 −3  {lib → app/models}/simple_captcha_data.rb
  7. +0 −16 assets/migrate/create_simple_captcha_data_less_than_2.0.rb
  8. +3 −0  config/routes.rb
  9. +1 −9 init.rb
  10. +0 −1  install.rb
  11. +4 −0 lib/generators/USAGE
  12. +22 −0 lib/generators/simple_captcha_generator.rb
  13. +0 −3  assets/views/simple_captcha/_simple_captcha.erb → lib/generators/templates/_partial.erb
  14. +2 −2 assets/migrate/create_simple_captcha_data.rb → lib/generators/templates/migration.rb
  15. +19 −0 lib/simple_captcha.rb
  16. +0 −6 lib/{simple_captcha_active_record.rb → simple_captcha/active_record.rb}
  17. +3 −5 lib/{simple_captcha_action_controller.rb → simple_captcha/controller.rb}
  18. +21 −0 lib/simple_captcha/form_builder.rb
  19. +11 −0 lib/simple_captcha/formtastic.rb
  20. +1 −4 lib/{simple_captcha_image.rb → simple_captcha/image.rb}
  21. +2 −8 lib/{simple_captcha_config.rb → simple_captcha/utils.rb}
  22. +2 −8 lib/{simple_captcha_action_view.rb → simple_captcha/view.rb}
  23. +0 −59 lib/simple_captcha_setup.rb
  24. +0 −15 tasks/simple_captcha_tasks.rake
  25. +0 −2  test/simple_captcha_test.rb
View
20 MIT-LICENSE
@@ -1,20 +0,0 @@
-Copyright (c) 2008 [Sur http://expressica.com]
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
237 README
@@ -1,237 +0,0 @@
-Copyright (c) 2008 [Sur http://expressica.com]
-
-SimpleCaptcha
-=========================================================================================
- Version: edge
- Author: Sur [http://expressica.com]
- Plugin Homepage: http://expressica.com/simple_captcha
- Contributors: http://vinsol.com/team, Kei Kusakari [http://d.hatena.ne.jp/kusakari/about]
- License: MIT
-
- Introduction:
- -------------
- SimpleCaptcha is the simplest and a robust captcha plugin. Its implementation requires
- adding up a single line in views and in controllers/models.
- SimpleCaptcha is available to be used with Rails2.0 or above and also it provides the
- backward compatibility with previous versions of Rails.
-
- Features:
- -----------
- -> Zero FileSystem usage(secret code moved to db-store and image storage removed).
- -> Provides various image styles.
- -> Provides three level of complexity of images.
- -> Works absolutely fine in distributed environment(session and db based implementation works
- fine in distributed environment).
- -> Implementation is as easy as just writing a single line in your view.
- "<%= show_simple_captcha %>" within the 'form' tags.
- -> Flexible DOM and CSS handling(There is a separate view partial for rednering SimpleCaptcha
- DOM elements).
- -> Automated removal of 1 hour old unmatched simple_captcha data.
-
-Pre-Requisite
-=========================================================================================
- RMagick should be installed on your machine to use this plugin.
- visit http://rmagick.rubyforge.org for more details.
-
-Installation
-=========================================================================================
- SimpleCaptcha plugin can be installed by running this command from the application root
-
- >> ruby script/plugin install svn://rubyforge.org/var/svn/expressica/plugins/simple_captcha
-
- OR
-
- SVN checkout the plugin as
- svn co svn://rubyforge.org/var/svn/expressica/plugins/simple_captcha simple_captcha
- Now put the directory simple_captcha in your application as /vendor/plugins/simple_captcha
-
-
-Setup
-=========================================================================================
- After installation, follow these simple steps to setup the plugin. The setup will depend
- on the version of rails your application is using.
-
- STEP 1
- ------
- for rails >= 2.0
- ---------------
- >> rake simple_captcha:setup
-
- for rails < 2.0
- ---------------
- >> rake simple_captcha:setup_old
-
- STEP 2
- ------
- >> rake db:migrate
-
- STEP 3
- ------
- add the following code in the file config/routes.rb
-
- ActionController::Routing::Routes.draw do |map|
- map.simple_captcha '/simple_captcha/:action', :controller => 'simple_captcha'
- end
-
- This is a mandatory route used for rendering the simple_captcha image on the fly without
- storing on the filesyste.
-
- STEP 4
- ------
- add the following line in the file app/controllers/application.rb
-
- ApplicationController < ActionController::Base
- include SimpleCaptcha::ControllerHelpers
- end
-
-Usage
-=========================================================================================
-
- Controller Based
- =======================================================================================
- In the view file within the form tags add this code
-
- <%= show_simple_captcha %>
-
- and in the controller's action authenticate it as
-
- if simple_captcha_valid?
- do this
- else
- do that
- end
-
-
- Model Based
- =======================================================================================
- In the view file within the form tags write this code
-
- <%= show_simple_captcha(:object=>"user") %>
-
- and in the model class add this code
-
- class User < ActiveRecord::Basse
- apply_simple_captcha
- end
-
- Validating with captcha
- ---------------------------------------------------------------------------------------
- @user.valid_with_captcha?
- NOTE: @user.valid? will still work as it should, it will not validate the captcha code.
-
- Saving with captcha
- ---------------------------------------------------------------------------------------
- @user.save_with_captcha
- NOTE: @user.save will still work as it should, it will not validate the captcha code.
-
-Options & Examples
-===========================================================================================
-
- View Options
- =========================================================================================
-
- :label
- ---------------------------------------------------------------------------------------
- provides the custom text b/w the image and the text field,
- the default is "type the code from the image"
-
- :image_style
- ---------------------------------------------------------------------------------------
- Provides the specific image style for the captcha image.
- There are eight different styles available with the plugin as...
- 1) simply_blue
- 2) simply_red
- 3) simply_green
- 4) charcoal_grey
- 5) embosed_silver
- 6) all_black
- 7) distorted_black
- 8) almost_invisible
-
- Default style is 'simply_blue'.
- You can also specify 'random' to select the random image style.
-
-
- :distortion
- ---------------------------------------------------------------------------------------
- Handles the complexity of the image. The :distortion can be set to 'low', 'medium'
- or 'high'. Default is 'low'.
-
- :object
- ---------------------------------------------------------------------------------------
- the name of the object of the model class, to implement the model based captcha.
-
-
- How to change the CSS for SimpleCaptcha DOM elements ?
- -----------------------------------------------------
- You can change the CSS of the SimpleCaptcha DOM elements as per your need in this file.
- For Rails >= 2.0 the file wiil reside as...
- "/app/views/simple_captcha/_simple_captcha.erb"
- For Rails < 2.0 the file will reside as...
- "/app/views/simple_captcha/_simple_captcha.rhtml"
-
-
- View's Examples
- =========================================================================================
-
- Controller Based Example
- ---------------------------------------------------------------------------------------
- example
- -------
- <%= show_simple_captcha(:label => "human authentication") %>
-
- example
- -------
- <%= show_simple_captcha(:label => "human authentication", :image_style => 'embosed_silver') %>
-
- example
- -------
- <%= show_simple_captcha(:label => "human authentication", :image_style => 'simply_red', :distortion => 'medium') %>
-
- Model Based Example
- ---------------------------------------------------------------------------------------
-
- example
- -------
- <%= show_simple_captcha(:object => 'user', :label => "human authentication") %>
-
-
-
- Model Options
- =========================================================================================
-
- :message
- ---------------------------------------------------------------------------------------
- provides the custom message on failure of captcha authentication
- the default is "Secret Code did not match with the Image"
-
- :add_to_base
- ---------------------------------------------------------------------------------------
- if set to true, appends the error message to the base.
-
- Model's Example
- =========================================================================================
-
- example
- -------
- class User < ActiveRecord::Base
- apply_simple_captcha
- end
-
- example
- -------
- class User < ActiveRecord::Base
- apply_simple_captcha :message => "The secret Image and code were different", :add_to_base => true
- end
-
-===========================================================================================
-
- Enjoy the simplest captcha implementation.
- Author: Sur
- Blog: http://expressica.com
- Contact: sur.max@gmail.com
- Plugin Homepage: http://expressica.com/simple_captcha
-
- Any feedback/comment/issue/donation is welcome!
-
-===========================================================================================
View
165 README.rdoc
@@ -0,0 +1,165 @@
+=SimpleCaptcha
+
+SimpleCaptcha is the simplest and a robust captcha plugin. Its implementation requires
+adding up a single line in views and in controllers/models.
+SimpleCaptcha is available to be used with Rails2.0 or above and also it provides the
+backward compatibility with previous versions of Rails.
+
+==Features
+
+* Zero FileSystem usage(secret code moved to db-store and image storage removed).
+* Provides various image styles.
+* Provides three level of complexity of images.
+* Works absolutely fine in distributed environment(session and db based implementation works fine in distributed environment).
+* Implementation is as easy as just writing a single line in your view. "<%= show_simple_captcha %>" within the 'form' tags.
+* Flexible DOM and CSS handling(There is a separate view partial for rednering SimpleCaptcha DOM elements).
+* Automated removal of 1 hour old unmatched simple_captcha data.
+
+==Requirements
+
+* {Ruby}[http://ruby-lang.org/] >= 1.8.7
+* {Rails}[http://github.com/rails/rails] >= 3
+* RMagick should be installed on your machine to use this plugin.
+ visit http://rmagick.rubyforge.org for more details.
+
+==Installation
+
+ rails plugin install git://github.com/galetahub/simple-captcha-mirror.git
+
+==Setup
+
+After installation, follow these simple steps to setup the plugin. The setup will depend
+on the version of rails your application is using.
+
+===STEP 1
+ rails generate simple_captcha
+
+===STEP 2
+ rake db:migrate
+
+===STEP 3
+
+Add the following line in the file "app/controllers/application.rb"
+
+ ApplicationController < ActionController::Base
+ include SimpleCaptcha::ControllerHelpers
+ end
+
+==Usage
+
+===Controller Based
+
+In the view file within the form tags add this code
+
+ <%= show_simple_captcha %>
+
+and in the controller's action authenticate it as
+
+ if simple_captcha_valid?
+ do this
+ else
+ do that
+ end
+
+===Model Based
+
+In the view file within the form tags write this code
+
+ <%= show_simple_captcha(:object=>"user") %>
+
+and in the model class add this code
+
+ class User < ActiveRecord::Basse
+ apply_simple_captcha
+ end
+
+====FormBuilder helper
+
+ <%= form_for @page do |form| -%>
+ ...
+ <%= form.simple_captcha :label => "Enter numbers..", :image_style => "simply_red" %>
+ ...
+ <% end -%>
+
+====Validating with captcha
+NOTE: @user.valid? will still work as it should, it will not validate the captcha code.
+
+ @user.valid_with_captcha?
+
+====Saving with captcha
+NOTE: @user.save will still work as it should, it will not validate the captcha code.
+
+ @user.save_with_captcha
+
+===Formtastic integration
+SimpleCaptcha detects if your use Formtastic and appends "SimpleCaptcha::CustomFormBuilder".
+
+ <%= form.input :captcha, :as => :simple_captcha %>
+
+==Options & Examples
+===View Options
+
+* *:label* - provides the custom text b/w the image and the text field, the default is "type the code from the image"
+
+* *:image_style* - provides the specific image style for the captcha image.
+There are eight different styles available with the plugin as...
+ 1) simply_blue
+ 2) simply_red
+ 3) simply_green
+ 4) charcoal_grey
+ 5) embosed_silver
+ 6) all_black
+ 7) distorted_black
+ 8) almost_invisible
+
+Default style is 'simply_blue'.
+You can also specify 'random' to select the random image style.
+
+* *:distortion* - handles the complexity of the image. The :distortion can be set to 'low', 'medium' or 'high'. Default is 'low'.
+
+* *:object* - the name of the object of the model class, to implement the model based captcha.
+
+
+===How to change the CSS for SimpleCaptcha DOM elements?
+You can change the CSS of the SimpleCaptcha DOM elements as per your need in this file.
+ /app/views/simple_captcha/_simple_captcha.erb
+
+===View's Examples
+====Controller Based Example
+
+ <%= show_simple_captcha(:label => "human authentication") %>
+
+ <%= show_simple_captcha(:label => "human authentication", :image_style => 'embosed_silver') %>
+
+ <%= show_simple_captcha(:label => "human authentication", :image_style => 'simply_red', :distortion => 'medium') %>
+
+====Model Based Example
+
+ <%= show_simple_captcha(:object => 'user', :label => "human authentication") %>
+
+====Model Options
+
+* *:message* - provides the custom message on failure of captcha authentication the default is "Secret Code did not match with the Image"
+
+* *:add_to_base* - if set to true, appends the error message to the base.
+
+
+=====Model's Example
+
+ class User < ActiveRecord::Base
+ apply_simple_captcha
+ end
+
+ class User < ActiveRecord::Base
+ apply_simple_captcha :message => "The secret Image and code were different", :add_to_base => true
+ end
+
+==Who's who?
+
+Enjoy the simplest captcha implementation.
+Author: Sur
+Blog: http://expressica.com
+Contact: sur.max@gmail.com
+Plugin Homepage: http://expressica.com/simple_captcha
+
+Any feedback/comment/issue/donation is welcome!
View
2  Rakefile
@@ -1,5 +1,3 @@
-# Copyright (c) 2008 [Sur http://expressica.com]
-
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
View
4 lib/simple_captcha_controller.rb → app/controllers/simple_captcha_controller.rb 100755 → 100644
@@ -1,7 +1,4 @@
-# Copyright (c) 2008 [Sur http://expressica.com]
-
class SimpleCaptchaController < ActionController::Base
-
include SimpleCaptcha::ImageHelpers
def simple_captcha #:nodoc
@@ -14,5 +11,4 @@ def simple_captcha #:nodoc
:disposition => 'inline',
:filename => 'simple_captcha.jpg')
end
-
end
View
3  lib/simple_captcha_data.rb → app/models/simple_captcha_data.rb 100755 → 100644
@@ -1,5 +1,3 @@
-# Copyright (c) 2008 [Sur http://expressica.com]
-
class SimpleCaptchaData < ActiveRecord::Base
set_table_name "simple_captcha_data"
@@ -19,5 +17,4 @@ def clear_old_data(time = 1.hour.ago)
destroy_all("updated_at < '#{time.to_s(:db)}'")
end
end
-
end
View
16 assets/migrate/create_simple_captcha_data_less_than_2.0.rb
@@ -1,16 +0,0 @@
-# Copyright (c) 2008 [Sur http://expressica.com]
-
-class CreateSimpleCaptchaData < ActiveRecord::Migration
- def self.up
- create_table :simple_captcha_data do |t|
- t.column :key, :string, :limit => 40
- t.column :value, :string, :limit => 6
- t.column :created_at, :datetime
- t.column :updated_at, :datetime
- end
- end
-
- def self.down
- drop_table :simple_captcha_data
- end
-end
View
3  config/routes.rb
@@ -0,0 +1,3 @@
+Rails.application.routes.draw do |map|
+ match '/simple_captcha/:action', :to => 'simple_captcha', :as => :simple_captcha
+end
View
10 init.rb
@@ -1,9 +1 @@
-# Copyright (c) 2008 [Sur http://expressica.com]
-
-require 'simple_captcha_setup'
-require 'simple_captcha_config'
-require 'simple_captcha_image'
-require 'simple_captcha_action_view'
-require 'simple_captcha_action_controller'
-require 'simple_captcha_active_record'
-require 'simple_captcha_controller'
+require 'simple_captcha'
View
1  install.rb
@@ -1 +0,0 @@
-
View
4 lib/generators/USAGE
@@ -0,0 +1,4 @@
+SimplaCaptcha
+=============
+# Generate migration and copy view partial
+ rails generate simple_captcha
View
22 lib/generators/simple_captcha_generator.rb
@@ -0,0 +1,22 @@
+require 'rails/generators'
+
+class SimpleCaptchaGenerator < Rails::Generators::Base
+ include Rails::Generators::Migration
+
+ def self.source_root
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates/'))
+ end
+
+ def self.next_migration_number(dirname)
+ Time.now.strftime("%Y%m%d%H%M%S")
+ end
+
+ def create_view
+ template "_simple_captcha.erb",
+ File.join('app/views', 'simple_captcha', "_simple_captcha.erb")
+ end
+
+ def create_migration
+ migration_template "migration.rb", File.join('db/migrate', "simple_captcha_data.rb")
+ end
+end
View
3  .../views/simple_captcha/_simple_captcha.erb → lib/generators/templates/_partial.erb 100755 → 100644
@@ -1,7 +1,4 @@
-<!-- Copyright (c) 2007 [Sur http://expressica.com] -->
-
<style type="text/CSS">
-
#simple_captcha{border: 1px solid #ccc; padding: 5px !important;}
#simple_captcha,
#simple_captcha div{display: table;}
View
4 assets/migrate/create_simple_captcha_data.rb → lib/generators/templates/migration.rb 100755 → 100644
@@ -1,5 +1,3 @@
-# Copyright (c) 2008 [Sur http://expressica.com]
-
class CreateSimpleCaptchaData < ActiveRecord::Migration
def self.up
create_table :simple_captcha_data do |t|
@@ -7,6 +5,8 @@ def self.up
t.string :value, :limit => 6
t.timestamps
end
+
+ add_index :simple_captcha_data, :key, :name => "idx_key"
end
def self.down
View
19 lib/simple_captcha.rb
@@ -0,0 +1,19 @@
+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::ViewHelpers)
+ ActionView::Helpers::FormBuilder.send(:include, SimpleCaptcha::FormBuilder)
+end
+
+if Object.const_defined?("ActiveRecord")
+ require 'simple_captcha/active_record'
+ ActiveRecord::Base.send(:extend, SimpleCaptcha::ModelHelpers::ClassMethods)
+end
+
+if Object.const_defined?("Formtastic")
+ require 'simple_captcha/formtastic'
+ Formtastic::SemanticFormHelper.builder = SimpleCaptcha::CustomFormBuilder
+end
View
6 lib/simple_captcha_active_record.rb → lib/simple_captcha/active_record.rb
@@ -1,5 +1,3 @@
-# Copyright (c) 2008 [Sur http://expressica.com]
-
module SimpleCaptcha #:nodoc
module ModelHelpers #:nodoc
@@ -83,7 +81,3 @@ def save(check_validations=true)
end
end
end
-
-ActiveRecord::Base.module_eval do
- extend SimpleCaptcha::ModelHelpers::ClassMethods
-end
View
8 lib/simple_captcha_action_controller.rb → lib/simple_captcha/controller.rb
@@ -1,9 +1,7 @@
-# Copyright (c) 2008 [Sur http://expressica.com]
-
module SimpleCaptcha #:nodoc
module ControllerHelpers #:nodoc
- include ConfigTasks
+ include SimpleCaptcha::Utils
# This method is to validate the simple captcha in controller.
# It means when the captcha is controller based i.e. :object has not been passed to the method show_simple_captcha.
@@ -19,7 +17,8 @@ module ControllerHelpers #:nodoc
# redirect_to :action => "myaction"
# end
def simple_captcha_valid?
- return true if RAILS_ENV == 'test'
+ return true if Rails.env.test?
+
if params[:captcha]
data = simple_captcha_value
result = data == params[:captcha].delete(" ").upcase
@@ -29,6 +28,5 @@ def simple_captcha_valid?
return false
end
end
-
end
end
View
21 lib/simple_captcha/form_builder.rb
@@ -0,0 +1,21 @@
+module SimpleCaptcha
+ module FormBuilder
+ def self.included(base)
+ base.send(:include, SimpleCaptcha::ViewHelper)
+ base.send(:include, SimpleCaptcha::FormBuilder::ClassMethods)
+ end
+
+ module ClassMethods
+ # Example:
+ # <% form_for :post, :url => posts_path do |form| %>
+ # ...
+ # <%= form.simple_captcha :label => "Enter numbers..", :image_style => "simply_red" %>
+ # <% end %>
+ #
+ def simple_captcha(options = {})
+ options.update :object => @object_name
+ show_simple_captcha(objectify_options(options))
+ end
+ end
+ end
+end
View
11 lib/simple_captcha/formtastic.rb
@@ -0,0 +1,11 @@
+module SimpleCaptcha
+ class CustomFormBuilder < Formtastic::SemanticFormBuilder
+
+ private
+
+ def simple_captcha_input(method, options)
+ options.update :object => sanitized_object_name
+ self.send(:show_simple_captcha, options)
+ end
+ end
+end
View
5 lib/simple_captcha_image.rb → lib/simple_captcha/image.rb
@@ -1,12 +1,10 @@
-# Copyright (c) 2008 [Sur http://expressica.com]
-
require 'rubygems'
require 'RMagick'
module SimpleCaptcha #:nodoc
module ImageHelpers #:nodoc
- include ConfigTasks
+ include SimpleCaptcha::Utils
IMAGE_STYLES = [
'embosed_silver',
@@ -103,6 +101,5 @@ def generate_simple_captcha_image(options={}) #:nodoc
set_simple_captcha_image_style
@image.implode(0.2).to_blob
end
-
end
end
View
10 lib/simple_captcha_config.rb → lib/simple_captcha/utils.rb
@@ -1,18 +1,12 @@
-# Copyright (c) 2008 [Sur http://expressica.com]
-
require 'digest/sha1'
module SimpleCaptcha #:nodoc
- module ConfigTasks #:nodoc
+ module Utils #:nodoc
private
- def simple_captcha_image_path #:nodoc
- "#{RAILS_ROOT}/vendor/plugins/simple_captcha/assets/images/simple_captcha/"
- end
-
def simple_captcha_key #:nodoc
- session[:simple_captcha] ||= Digest::SHA1.hexdigest(Time.now.to_s + request.session_options[:id].to_s)
+ session[:simple_captcha] ||= Digest::SHA1.hexdigest(Time.now.to_s + session[:id].to_s)
end
def simple_captcha_value(key = simple_captcha_key) #:nodoc
View
10 lib/simple_captcha_action_view.rb → lib/simple_captcha/view.rb
@@ -1,9 +1,7 @@
-# Copyright (c) 2008 [Sur http://expressica.com]
-
module SimpleCaptcha #:nodoc
- module ViewHelpers #:nodoc
+ module ViewHelper #:nodoc
- include ConfigTasks
+ include SimpleCaptcha::Utils
# Simple Captcha is a very simplified captcha.
#
@@ -118,7 +116,3 @@ def generate_simple_captcha_data(code)
end
end
-
-ActionView::Base.module_eval do
- include SimpleCaptcha::ViewHelpers
-end
View
59 lib/simple_captcha_setup.rb
@@ -1,59 +0,0 @@
-require 'fileutils'
-
-module SimpleCaptcha #:nodoc
- module SetupTasks #:nodoc
-
- def self.do_setup(version = :new)
- @version = version
-
- begin
- puts "STEP 1"
- generate_migration
- write_migration_content
- copy_view_file
- puts "Followup Steps"
- puts "STEP 2 -- run the task 'rake db:migrate'"
- puts "STEP 3 -- edit the file config/routes.rb to add the route \"map.simple_captcha '/simple_captcha/:action', :controller => 'simple_captcha'\""
- rescue StandardError => e
- p e
- end
- end
-
- private
-
- def self.generate_migration
- puts "==============================================================================="
- puts "ruby script/generate migration create_simple_captcha_data"
- puts %x{ruby script/generate migration create_simple_captcha_data}
- puts "================================DONE==========================================="
- end
-
- def self.migration_source_file
- @version == :old ?
- File.join(File.dirname(__FILE__), "../assets", "migrate", "create_simple_captcha_data_less_than_2.0.rb") :
- File.join(File.dirname(__FILE__), "../assets", "migrate", "create_simple_captcha_data.rb")
- end
-
- def self.write_migration_content
- copy_to_path = File.join(RAILS_ROOT, "db", "migrate")
- migration_filename =
- Dir.entries(copy_to_path).collect do |file|
- number, *name = file.split("_")
- file if name.join("_") == "create_simple_captcha_data.rb"
- end.compact.first
- migration_file = File.join(copy_to_path, migration_filename)
- File.open(migration_file, "wb"){|f| f.write(File.read(migration_source_file))}
- end
-
- def self.copy_view_file
- puts "Copying SimpleCaptcha view file."
- mkdir(File.join(RAILS_ROOT, "app/views/simple_captcha")) unless File.exist?(File.join(RAILS_ROOT, "app/views/simple_captcha"))
- view_file = @version == :old ? '_simple_captcha.rhtml' : '_simple_captcha.erb'
- FileUtils.cp_r(
- File.join(File.dirname(__FILE__), "../assets/views/simple_captcha/_simple_captcha.erb"),
- File.join(RAILS_ROOT, "app/views/simple_captcha/", view_file)
- )
- puts "================================DONE==========================================="
- end
- end
-end
View
15 tasks/simple_captcha_tasks.rake
@@ -1,15 +0,0 @@
-# Copyright (c) 2008 [Sur http://expressica.com]
-
-require 'fileutils'
-
-namespace :simple_captcha do
- desc "Set up the plugin SimpleCaptcha for rails < 2.0"
- task :setup_old => :environment do
- SimpleCaptcha::SetupTasks.do_setup(:old)
- end
-
- desc "Set up the plugin SimpleCaptcha for rails >= 2.0"
- task :setup => :environment do
- SimpleCaptcha::SetupTasks.do_setup
- end
-end
View
2  test/simple_captcha_test.rb
@@ -1,5 +1,3 @@
-# Copyright (c) 2008 [Sur http://expressica.com]
-
require 'test/unit'
class SimpleCaptchaTest < Test::Unit::TestCase
Please sign in to comment.
Something went wrong with that request. Please try again.