rqrcode-rails3 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -0
- data/lib/rqrcode-rails3.rb +6 -2
- data/lib/rqrcode-rails3/size_calculator.rb +40 -0
- metadata +7 -6
data/README.rdoc
CHANGED
@@ -25,6 +25,13 @@ In your controller actions, you could return a QR code that links to the current
|
|
25
25
|
format.png { render :qrcode => request.url }
|
26
26
|
end
|
27
27
|
|
28
|
+
Options:
|
29
|
+
|
30
|
+
* +:size+ – This controls how big the QR Code will be. Smallest size will be chosen by default. Set to maintain consistent size.
|
31
|
+
* +:offset+ – Padding around the QR Code (e.g. 10)
|
32
|
+
* +:fill+ – Background color (e.g "ffffff" or :white)
|
33
|
+
* +:color+ – Foreground color for the code (e.g. "000000" or :black)
|
34
|
+
|
28
35
|
== About
|
29
36
|
|
30
37
|
This project was inspired by the first chapter in José Valim's book {Crafting Rails Applications}[http://pragprog.com/titles/jvrails/crafting-rails-applications]
|
data/lib/rqrcode-rails3.rb
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
require 'action_controller'
|
2
2
|
require 'rqrcode'
|
3
|
+
require 'rqrcode-rails3/size_calculator.rb'
|
3
4
|
require 'rqrcode-rails3/renderers/svg.rb'
|
4
5
|
|
5
6
|
module RQRCode
|
6
7
|
Mime::Type.register "image/svg+xml", :svg
|
7
|
-
Mime::Type.register "image/png", :png
|
8
|
+
Mime::Type.register "image/png", :png
|
9
|
+
|
10
|
+
extend SizeCalculator
|
8
11
|
|
9
12
|
ActionController::Renderers.add :qrcode do |string, options|
|
10
13
|
format = self.request.format.symbol
|
14
|
+
size = options[:size] || RQRCode.minimum_qr_size_from_string(string)
|
11
15
|
|
12
|
-
qrcode = RQRCode::QRCode.new(string)
|
16
|
+
qrcode = RQRCode::QRCode.new(string, :size => size)
|
13
17
|
svg = RQRCode::Renderers::SVG::render(qrcode, options)
|
14
18
|
|
15
19
|
data = \
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module RQRCode
|
2
|
+
module SizeCalculator
|
3
|
+
# size - seems to follow this logic
|
4
|
+
# # | input | modules
|
5
|
+
# | size | created
|
6
|
+
#-------|-------|--------
|
7
|
+
# 1 | 7 | 21
|
8
|
+
# 2 | 14 | 25 (+4)
|
9
|
+
# 3 | 24 | 29 -
|
10
|
+
# 4 | 34 | 33 -
|
11
|
+
# 5 | 44 | 37 -
|
12
|
+
# 6 | 58 | 41 -
|
13
|
+
# 7 | 64 | 45 -
|
14
|
+
# 8 | 84 | 49 -
|
15
|
+
# 9 | 98 | 53 -
|
16
|
+
# 10 | 119 | 57 -
|
17
|
+
# 11 | 137 | 61 -
|
18
|
+
# 12 | 155 | 65 -
|
19
|
+
# 13 | 177 | 69 -
|
20
|
+
# 14 | 194 | 73 -
|
21
|
+
|
22
|
+
QR_CHAR_SIZE_VS_SIZE = [7, 14, 24, 34, 44, 58, 64, 84, 98, 119, 137, 155, 177, 194]
|
23
|
+
|
24
|
+
def minimum_qr_size_from_string(string)
|
25
|
+
QR_CHAR_SIZE_VS_SIZE.each_with_index do |size, index|
|
26
|
+
return (index + 1) if string.size < size
|
27
|
+
end
|
28
|
+
|
29
|
+
# If it's particularly big, we'll try and create codes until it accepts
|
30
|
+
i = QR_CHAR_SIZE_VS_SIZE.size
|
31
|
+
begin
|
32
|
+
i += 1
|
33
|
+
RQRCode::QRCode.new(string, :size => i)
|
34
|
+
return i
|
35
|
+
rescue RQRCode::QRCodeRunTimeError
|
36
|
+
retry
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rqrcode-rails3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sam Vincent
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-07-11 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -44,6 +44,7 @@ extra_rdoc_files: []
|
|
44
44
|
|
45
45
|
files:
|
46
46
|
- lib/rqrcode-rails3/renderers/svg.rb
|
47
|
+
- lib/rqrcode-rails3/size_calculator.rb
|
47
48
|
- lib/rqrcode-rails3.rb
|
48
49
|
- MIT-LICENSE
|
49
50
|
- Rakefile
|
@@ -79,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
80
|
requirements: []
|
80
81
|
|
81
82
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.
|
83
|
+
rubygems_version: 1.6.2
|
83
84
|
signing_key:
|
84
85
|
specification_version: 3
|
85
86
|
summary: Render QR codes with Rails 3
|