easy_captcha 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
data/easy_captcha.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{easy_captcha}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marco Scholl"]
12
- s.date = %q{2011-01-26}
12
+ s.date = %q{2011-01-27}
13
13
  s.description = %q{Captcha-Plugin for Rails}
14
14
  s.email = %q{develop@marco-scholl.de}
15
15
  s.extra_rdoc_files = [
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module EasyCaptcha
2
3
  # captcha generation class
3
4
  class Captcha
@@ -7,9 +8,9 @@ module EasyCaptcha
7
8
  attr_reader :image
8
9
 
9
10
  # generate captcha by code
10
- def initialize(code, file = nil)
11
+ def initialize code
11
12
  @code = code
12
- generate_captcha(file)
13
+ generate_captcha
13
14
  end
14
15
 
15
16
  def inspect #:nodoc:
@@ -18,8 +19,8 @@ module EasyCaptcha
18
19
 
19
20
  private
20
21
 
21
- def generate_captcha(file = nil) #:nodoc:
22
- @image = EasyCaptcha.generator.generate(@code, file)
22
+ def generate_captcha #:nodoc:
23
+ @image = EasyCaptcha.generator.generate(@code)
23
24
  end
24
25
  end
25
26
  end
@@ -11,8 +11,12 @@ module EasyCaptcha
11
11
  # generate captcha image and return it as blob
12
12
  def generate_captcha
13
13
  if EasyCaptcha.cache
14
+ # create cache dir
14
15
  FileUtils.mkdir_p(EasyCaptcha.cache_temp_dir)
16
+
17
+ # select all generated captchas from cache
15
18
  files = Dir.glob(EasyCaptcha.cache_temp_dir + "*")
19
+
16
20
  unless files.size < EasyCaptcha.cache_size
17
21
  file = File.open(files.at(Kernel.rand(files.size)))
18
22
  session[:captcha] = File.basename(file.path)
@@ -24,7 +28,13 @@ module EasyCaptcha
24
28
  end
25
29
  end
26
30
  generated_code = generate_captcha_code
27
- Captcha.new(generated_code, EasyCaptcha.cache_temp_dir + "#{generated_code}").image
31
+ image = Captcha.new(generated_code).image
32
+
33
+ # write captcha for caching
34
+ File.open(EasyCaptcha.cache_temp_dir + "#{generated_code}", 'w') { |f| f.write image }
35
+
36
+ # return image
37
+ image
28
38
  else
29
39
  Captcha.new(generate_captcha_code).image
30
40
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module EasyCaptcha
2
3
  module Generator
3
4
 
@@ -55,7 +56,7 @@ module EasyCaptcha
55
56
  end
56
57
 
57
58
  # generate image
58
- def generate(code, file = nil)
59
+ def generate(code)
59
60
  config = self
60
61
  canvas = Magick::Image.new(EasyCaptcha.image_width, EasyCaptcha.image_height) do |variable|
61
62
  self.background_color = config.image_background_color unless config.image_background_color.nil?
@@ -91,10 +92,11 @@ module EasyCaptcha
91
92
  # Crop image because to big after waveing
92
93
  canvas = canvas.crop(Magick::CenterGravity, EasyCaptcha.image_width, EasyCaptcha.image_height)
93
94
 
94
- unless file.nil?
95
- canvas.write(file) { self.format = 'PNG' }
96
- end
97
95
  image = canvas.to_blob { self.format = 'PNG' }
96
+
97
+ # ruby-1.9
98
+ image = image.force_encoding 'UTF-8' if image.respond_to? :force_encoding
99
+
98
100
  canvas.destroy!
99
101
  image
100
102
  end
@@ -3,7 +3,7 @@ module EasyCaptcha
3
3
  module ViewHelpers
4
4
  # generate an image_tag for captcha image
5
5
  def captcha_tag(*args)
6
- options = { :alt => 'captcha' }
6
+ options = { :alt => 'captcha', :width => EasyCaptcha.image_width, :height => EasyCaptcha.image_height }
7
7
  options.merge! args.extract_options!
8
8
  image_tag(captcha_path(:i => Time.now.to_i), options)
9
9
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 0
9
- version: 0.4.0
8
+ - 1
9
+ version: 0.4.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Marco Scholl
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-26 00:00:00 +01:00
17
+ date: 2011-01-27 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -164,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
164
  requirements:
165
165
  - - ">="
166
166
  - !ruby/object:Gem::Version
167
- hash: -88900623567721278
167
+ hash: 465524661579164899
168
168
  segments:
169
169
  - 0
170
170
  version: "0"