rqrcode-rails3 0.1.4 → 0.1.5
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.
- data/{README.rdoc → README.md} +7 -1
- data/lib/rqrcode-rails3.rb +3 -2
- data/lib/rqrcode-rails3/renderers/svg.rb +6 -4
- metadata +5 -5
data/{README.rdoc → README.md}
RENAMED
@@ -21,14 +21,20 @@ In your controller actions, you could return a QR code that links to the current
|
|
21
21
|
|
22
22
|
respond_to do |format|
|
23
23
|
format.html
|
24
|
-
format.svg { render :qrcode => request.url }
|
24
|
+
format.svg { render :qrcode => request.url, :level => :l, :unit => 10 }
|
25
25
|
format.png { render :qrcode => request.url }
|
26
26
|
end
|
27
27
|
|
28
28
|
Options:
|
29
29
|
|
30
30
|
* +:size+ – This controls how big the QR Code will be. Smallest size will be chosen by default. Set to maintain consistent size.
|
31
|
+
* +:level* – The error correction level, can be:
|
32
|
+
* Level :l 7% of code can be restored
|
33
|
+
* Level :m 15% of code can be restored
|
34
|
+
* Level :q 25% of code can be restored
|
35
|
+
* Level :h 30% of code can be restored (default :h)
|
31
36
|
* +:offset+ – Padding around the QR Code (e.g. 10)
|
37
|
+
* +:unit+ – How many pixels per module (e.g. 11)
|
32
38
|
* +:fill+ – Background color (e.g "ffffff" or :white)
|
33
39
|
* +:color+ – Foreground color for the code (e.g. "000000" or :black)
|
34
40
|
|
data/lib/rqrcode-rails3.rb
CHANGED
@@ -11,9 +11,10 @@ module RQRCode
|
|
11
11
|
|
12
12
|
ActionController::Renderers.add :qrcode do |string, options|
|
13
13
|
format = self.request.format.symbol
|
14
|
-
size = options[:size]
|
14
|
+
size = options[:size] || RQRCode.minimum_qr_size_from_string(string)
|
15
|
+
level = options[:level] || :h
|
15
16
|
|
16
|
-
qrcode = RQRCode::QRCode.new(string, :size => size)
|
17
|
+
qrcode = RQRCode::QRCode.new(string, :size => size, :level => level)
|
17
18
|
svg = RQRCode::Renderers::SVG::render(qrcode, options)
|
18
19
|
|
19
20
|
data = \
|
@@ -5,15 +5,17 @@ module RQRCode
|
|
5
5
|
# Render the SVG from the qrcode string provided from the RQRCode gem
|
6
6
|
# Options:
|
7
7
|
# offset - Padding around the QR Code (e.g. 10)
|
8
|
+
# unit - How many pixels per module (Default: 11)
|
8
9
|
# fill - Background color (e.g "ffffff" or :white)
|
9
10
|
# color - Foreground color for the code (e.g. "000000" or :black)
|
10
11
|
|
11
12
|
def render(qrcode, options={})
|
12
13
|
offset = options[:offset].to_i || 0
|
13
14
|
color = options[:color] || "000"
|
15
|
+
unit = options[:unit] || 11
|
14
16
|
|
15
17
|
# height and width dependent on offset and QR complexity
|
16
|
-
dimension = (qrcode.module_count*
|
18
|
+
dimension = (qrcode.module_count*unit) + (2*offset)
|
17
19
|
|
18
20
|
xml_tag = %{<?xml version="1.0" standalone="yes"?>}
|
19
21
|
open_tag = %{<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" width="#{dimension}" height="#{dimension}">}
|
@@ -23,11 +25,11 @@ module RQRCode
|
|
23
25
|
qrcode.modules.each_index do |c|
|
24
26
|
tmp = []
|
25
27
|
qrcode.modules.each_index do |r|
|
26
|
-
y = c*
|
27
|
-
x = r*
|
28
|
+
y = c*unit + offset
|
29
|
+
x = r*unit + offset
|
28
30
|
|
29
31
|
next unless qrcode.is_dark(c, r)
|
30
|
-
tmp << %{<rect width="
|
32
|
+
tmp << %{<rect width="#{unit}" height="#{unit}" x="#{x}" y="#{y}" style="fill:##{color}"/>}
|
31
33
|
end
|
32
34
|
result << tmp.join
|
33
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rqrcode-rails3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-10 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rqrcode
|
16
|
-
requirement: &
|
16
|
+
requirement: &70360232287200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 0.4.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70360232287200
|
25
25
|
description: Render QR codes with Rails 3
|
26
26
|
email: sam.vincent@mac.com
|
27
27
|
executables: []
|
@@ -34,7 +34,7 @@ files:
|
|
34
34
|
- MIT-LICENSE
|
35
35
|
- Rakefile
|
36
36
|
- Gemfile
|
37
|
-
- README.
|
37
|
+
- README.md
|
38
38
|
homepage: http://github.com/samvincent/rqrcode-rails3
|
39
39
|
licenses: []
|
40
40
|
post_install_message:
|