rucaptcha 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d38db9039dff4061dbd9e8b560dfe018b3d78a88
4
- data.tar.gz: 3576b082261e0ee0efedf5b0726da34a10bc0313
3
+ metadata.gz: 9d19351a61db05ab5f038cca14190d70473117a8
4
+ data.tar.gz: 17f368f3e963f2bc89597ea6489c61eb1013be94
5
5
  SHA512:
6
- metadata.gz: dd6d14a6ec291107206e2ff3cc21f53e515d885ed4872e9a96cef822dec000201827d39906e79071bf66af0f5cd8ef799727aa2b15078e9278c6f5e487928830
7
- data.tar.gz: 85dd5aac5b47060869a3fc23031dbf3801c9cb3cce605424a1dadf2604fbc195452acf73919d0894e533b1a01caff39b891605a2ce047e44e1e596fde7ecc9dc
6
+ metadata.gz: 1c92ef1378ecfba89ec2aca42e88336690cc23a8e24dde0e0dfeadfe9e9f60e9fd389f3921c3167f3f014b5dbbce9a0e1058a6d39c582ea36a2fc8b37767f1b9
7
+ data.tar.gz: b4f5acca22355975f074cc20d0ec6822c4960b8103993b9524e79ae2c4e696c83b34e755189d803a2ab6b91a0384e9840b234ae7f454a5b32223ca998afcb6cf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.4.5
2
+
3
+ - Removed `posix-spawn` dependency, used open3 instead (core funciontality), JRuby compatible (#24)
4
+
1
5
  0.4.4
2
6
 
3
7
  - Remove deprecated `width`, `height` config.
data/README.md CHANGED
@@ -2,16 +2,24 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/rucaptcha.svg)](https://badge.fury.io/rb/rucaptcha)
4
4
  [![Build Status](https://travis-ci.org/huacnlee/rucaptcha.svg)](https://travis-ci.org/huacnlee/rucaptcha)
5
+ [![Code Climate](https://codeclimate.com/github/huacnlee/rucaptcha/badges/gpa.svg)](https://codeclimate.com/github/huacnlee/rucaptcha)
5
6
 
6
- This is a Captcha gem for Rails Applications. It runs an ImageMagick command to draw Captcha image - so it has NO performance issues or memory leak issues.
7
+ This is a Captcha gem for Rails Applications. It runs an ImageMagick command to draw Captcha image - so it has NO performance issues or memory leak issues. **There is NO: RMagick**
7
8
 
8
- **There is NO: RMagick**
9
+ ## Example
10
+
11
+ ![1](https://cloud.githubusercontent.com/assets/5518/15423974/b186b0d6-1eb2-11e6-9c0e-4cc3a66f32c8.png)
12
+ ![2](https://cloud.githubusercontent.com/assets/5518/15423975/b1887b6e-1eb2-11e6-895f-5629f82697d3.png)
13
+ ![3](https://cloud.githubusercontent.com/assets/5518/15423978/b18f08ee-1eb2-11e6-9670-c21dba290e04.png)
14
+ ![4](https://cloud.githubusercontent.com/assets/5518/15423976/b18b6946-1eb2-11e6-8413-700ded157262.png)
15
+ ![5](https://cloud.githubusercontent.com/assets/5518/15423977/b18e7c62-1eb2-11e6-96f7-5bd6981d4185.png)
16
+ ![6](https://cloud.githubusercontent.com/assets/5518/15423979/b19175d4-1eb2-11e6-9417-7d496fb996b4.png)
17
+ ![7](https://cloud.githubusercontent.com/assets/5518/15423980/b1caf944-1eb2-11e6-862e-78c0a9360b43.png)
9
18
 
10
19
  Idea by: https://ruby-china.org/topics/20558#reply4
11
20
 
12
21
  [中文介绍和使用说明](https://ruby-china.org/topics/27832)
13
22
 
14
-
15
23
  ## Feature
16
24
 
17
25
  - Only need `ImageMagick`, No `RMagick`, No `mini_magick`;
@@ -35,10 +43,6 @@ sudo apt-get install imagemagick
35
43
  brew install imagemagick ghostscript
36
44
  ```
37
45
 
38
- ## Example
39
-
40
- ![1](https://cloud.githubusercontent.com/assets/5518/15423974/b186b0d6-1eb2-11e6-9c0e-4cc3a66f32c8.png) ![2](https://cloud.githubusercontent.com/assets/5518/15423975/b1887b6e-1eb2-11e6-895f-5629f82697d3.png) ![3](https://cloud.githubusercontent.com/assets/5518/15423978/b18f08ee-1eb2-11e6-9670-c21dba290e04.png) ![4](https://cloud.githubusercontent.com/assets/5518/15423976/b18b6946-1eb2-11e6-8413-700ded157262.png) ![5](https://cloud.githubusercontent.com/assets/5518/15423977/b18e7c62-1eb2-11e6-96f7-5bd6981d4185.png) ![6](https://cloud.githubusercontent.com/assets/5518/15423979/b19175d4-1eb2-11e6-9417-7d496fb996b4.png) ![7](https://cloud.githubusercontent.com/assets/5518/15423980/b1caf944-1eb2-11e6-862e-78c0a9360b43.png) ![8](https://cloud.githubusercontent.com/assets/5518/15423981/b1d26f12-1eb2-11e6-9201-56b8d3f14063.png)
41
-
42
46
  ## Usage
43
47
 
44
48
  Put rucaptcha in your `Gemfile`:
@@ -33,9 +33,7 @@ module RuCaptcha
33
33
  return @cache if defined?(@cache)
34
34
 
35
35
  cache_path = Rails.root.join('tmp', 'cache', 'rucaptcha')
36
- if !File.exists? cache_path
37
- FileUtils.mkdir_p(cache_path)
38
- end
36
+ FileUtils.mkdir_p(cache_path) unless File.exist? cache_path
39
37
  @cache = ActiveSupport::Cache::FileStore.new(cache_path)
40
38
  @cache.clear
41
39
  @cache
@@ -1,4 +1,4 @@
1
- require 'posix-spawn'
1
+ require 'open3'
2
2
 
3
3
  module RuCaptcha
4
4
  class Captcha
@@ -37,16 +37,13 @@ module RuCaptcha
37
37
  full_width = font_size * chars.size
38
38
  size = "#{full_width}x#{full_height}"
39
39
  half_width = full_width / 2
40
- full_height = full_height
41
- half_height = full_height / 2
42
40
  text_top = 0
43
41
  text_left = 0 - (font_size * 0.28).to_i
44
- stroke_width = (font_size * 0.05).to_i + 1
42
+ stroke_width = (font_size * 0.05).to_i + 1
45
43
  text_width = font_size + text_left
46
- label = "=#{' ' * (chars.size - 1)}="
44
+ text_opts = []
45
+ line_opts = []
47
46
 
48
- text_opts = []
49
- line_opts = []
50
47
  chars.each_with_index do |char, i|
51
48
  rgb = random_color
52
49
  text_color = "rgba(#{rgb.join(',')}, 1)"
@@ -76,15 +73,13 @@ module RuCaptcha
76
73
  command = "convert -size #{size} xc:White -gravity Center -weight 12 -pointsize 20 -annotate 0 \"#{code}\" -trim #{png_file_path}"
77
74
  require 'open3'
78
75
  _stdout_str, stderr_str = Open3.capture3(command)
79
- raise "RuCaptcha: #{stderr_str.strip}" if stderr_str != nil && stderr_str.length > 0
76
+ raise "RuCaptcha: #{stderr_str.strip}" if stderr_str.present?
80
77
  png_file_path
81
78
  else
82
79
  command.strip!
83
- pid, stdin, stdout, stderr = POSIX::Spawn.popen4(command)
84
- Process.waitpid(pid)
85
- err = stderr.read
86
- raise "RuCaptcha: #{err.strip}" if err != nil && err.length > 0
87
- stdout.read
80
+ out, err, st = Open3.capture3(command)
81
+ raise "RuCaptcha: #{err.strip}" if err.present?
82
+ out
88
83
  end
89
84
  end
90
85
  end
@@ -7,7 +7,7 @@ module RuCaptcha
7
7
  end
8
8
 
9
9
  def generate_rucaptcha
10
- session[:_rucaptcha] = RuCaptcha::Captcha.random_chars
10
+ session[:_rucaptcha] = RuCaptcha::Captcha.random_chars
11
11
  session[:_rucaptcha_at] = Time.now.to_i
12
12
 
13
13
  RuCaptcha::Captcha.create(session[:_rucaptcha])
@@ -1,3 +1,3 @@
1
1
  module RuCaptcha
2
- VERSION = '0.4.4'
2
+ VERSION = '0.4.5'
3
3
  end
@@ -1,13 +1,13 @@
1
1
  module RuCaptcha
2
2
  module ViewHelpers
3
3
  def rucaptcha_input_tag(opts = {})
4
- opts[:name] = '_rucaptcha'
5
- opts[:type] = 'text'
6
- opts[:autocorrect] = 'off'
4
+ opts[:name] = '_rucaptcha'
5
+ opts[:type] = 'text'
6
+ opts[:autocorrect] = 'off'
7
7
  opts[:autocapitalize] = 'off'
8
- opts[:pattern] = '[0-9a-z]*'
9
- opts[:maxlength] = RuCaptcha.config.len
10
- opts[:autocomplete] = 'off'
8
+ opts[:pattern] = '[0-9a-z]*'
9
+ opts[:maxlength] = RuCaptcha.config.len
10
+ opts[:autocomplete] = 'off'
11
11
  tag(:input, opts)
12
12
  end
13
13
 
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rucaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-20 00:00:00.000000000 Z
11
+ date: 2016-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: posix-spawn
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 0.3.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 0.3.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement