kaptcha 0.0.3.8 → 0.0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ en:
2
+ view:
3
+ captcha:
4
+ human_line: "Please tell us: %{num_a} %{operation} %{num_b} ?"
5
+ error_code: "Please check antispam code."
6
+ operations:
7
+ plus: "plus"
8
+ minus: "minus"
9
+ multiply_by: "multiply by"
10
+
11
+
@@ -10,13 +10,13 @@ module Captcha
10
10
 
11
11
  def has_captcha
12
12
  send(:include, InstanceMethods)
13
+ send(:after_find, :initialize_kaptcha)
13
14
  end
14
15
 
15
16
  end
16
17
 
17
18
  module InstanceMethods
18
19
 
19
-
20
20
  # @comment.human_captcha_desc
21
21
  # %input{:type => 'text', :name => 'comment[captcha_form_result]', :autocomplete => :off, :style => 'width: 50px; display: inline;'}
22
22
  # = f.hidden_field :captcha_code, :value => @comment.captcha_desc
@@ -32,7 +32,7 @@ module Captcha
32
32
  OPERATIONS = ['+', '-', '*']
33
33
 
34
34
  def captcha_code
35
- @@captcha_code.to_s ||= raise 'Undefined error.'
35
+ @@captcha_code.to_s ||= raise 'Captcha undefined error.'
36
36
  end
37
37
 
38
38
  def initialize(params={}, &block)
@@ -40,24 +40,20 @@ module Captcha
40
40
  super(params, &block)
41
41
  end
42
42
 
43
- def after_initialize
44
- initialize_kaptcha unless captcha_desc || human_captcha_desc
45
- end
46
-
47
43
  def validate
48
44
  unless captcha_form_result == captcha_code
49
45
  initialize_kaptcha
50
- return errors.add(:captcha_code, 'Пожалуйста, проверьте контрольный вопрос.')
46
+ errors.add(:captcha_code, I18n.t('view.captcha.error_code'))
51
47
  end
52
48
  true
53
49
  end
54
50
 
55
51
  def captcha_desc
56
- @@captcha_desc rescue nil
52
+ @@captcha_desc
57
53
  end
58
54
 
59
55
  def human_captcha_desc
60
- @@human_captcha_desc rescue nil
56
+ @@human_captcha_desc
61
57
  end
62
58
 
63
59
  private
@@ -83,15 +79,15 @@ module Captcha
83
79
 
84
80
  case captcha_operation.to_s
85
81
  when '-'
86
- @@human_captcha_operation = 'минус'
82
+ human_captcha_operation = I18n.t('view.captcha.operations.minus')
87
83
  when '+'
88
- @@human_captcha_operation = 'плюс'
84
+ human_captcha_operation = I18n.t('view.captcha.operations.plus')
89
85
  when '*'
90
- @@human_captcha_operation = 'умножить на'
86
+ human_captcha_operation = I18n.t('view.captcha.operations.multiply_by')
91
87
  end
92
88
 
93
89
  @@captcha_desc = "#{captcha_a} #{captcha_operation} #{captcha_b}"
94
- @@human_captcha_desc = "Скажите, сколько будет #{captcha_a} #{@@human_captcha_operation} #{captcha_b} ?"
90
+ @@human_captcha_desc = I18n.t('view.captcha.human_line', :num_a => captcha_a, :operation => human_captcha_operation, :num_b => captcha_b)
95
91
 
96
92
  @@captcha_code = captcha_a.send(captcha_operation, captcha_b)
97
93
  end
@@ -5,3 +5,8 @@ require File.join(File.dirname(__FILE__), 'core/kaptcha')
5
5
  if defined?(ActiveRecord::Base)
6
6
  ActiveRecord::Base.send :include, Captcha
7
7
  end
8
+
9
+ if defined? I18n
10
+ I18n.load_path += Dir.glob(File.expand_path('../../config/locales/kaptcha.en.yml', __FILE__))
11
+ end
12
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.8
4
+ version: 0.0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-14 00:00:00.000000000 Z
12
+ date: 2012-01-15 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Form protection with simple captcha calculations.
15
15
  email:
@@ -19,6 +19,7 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - lib/core/kaptcha.rb
21
21
  - lib/kaptcha.rb
22
+ - config/locales/kaptcha.en.yml
22
23
  - Rakefile
23
24
  - Gemfile
24
25
  - README.rdoc