rqrcode-rails3 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc
CHANGED
@@ -1,19 +1,23 @@
|
|
1
|
-
Render QR
|
1
|
+
= Render QR codes easily from your Rails 3 application
|
2
|
+
|
3
|
+
This gem supports rendering either SVG or PNG format.
|
4
|
+
|
5
|
+
SVG, because of it's vector nature, will scale easily when intended for print. Offering QR endpoints enables others to integrate with your service in possibly interesting ways.
|
2
6
|
|
3
7
|
== Installation
|
4
8
|
|
5
|
-
Add the
|
9
|
+
Add the following to your +Gemfile+.
|
6
10
|
|
7
|
-
gem
|
11
|
+
gem 'rqrcode-rails3'
|
8
12
|
|
9
|
-
If you want to use the PNG format, you will have to have ImageMagick installed on your system.
|
10
|
-
You will also want to add the
|
13
|
+
If you want to use the PNG format, you will have to have *ImageMagick* installed on your system.
|
14
|
+
You will also want to add the *mini_magick* gem to your application's +Gemfile+.
|
11
15
|
|
12
|
-
gem
|
16
|
+
gem 'mini_magick'
|
13
17
|
|
14
18
|
== How to use
|
15
19
|
|
16
|
-
In your controller actions, you
|
20
|
+
In your controller actions, you could return a QR code that links to the current page like this:
|
17
21
|
|
18
22
|
respond_to do |format|
|
19
23
|
format.html
|
@@ -21,11 +25,8 @@ In your controller actions, you can return a QRCode that links to the current pa
|
|
21
25
|
format.png { render :qrcode => request.url }
|
22
26
|
end
|
23
27
|
|
24
|
-
|
25
|
-
|
26
|
-
This project was inspired by the first chapter in José Valim's book "Crafting Rails Applications."
|
27
|
-
QR Codes are encoded by 'rqrcode' [https://github.com/whomwah/rqrcode]
|
28
|
+
== About
|
28
29
|
|
29
|
-
|
30
|
+
This project was inspired by the first chapter in José Valim's book {Crafting Rails Applications}[http://pragprog.com/titles/jvrails/crafting-rails-applications]
|
30
31
|
|
31
|
-
|
32
|
+
QR codes are encoded by {rqrcode}[https://github.com/whomwah/rqrcode]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'action_controller'
|
2
2
|
require 'rqrcode'
|
3
|
-
require '
|
3
|
+
require 'rqrcode-rails3/renderers/svg.rb'
|
4
4
|
|
5
5
|
module RQRCode
|
6
6
|
Mime::Type.register "image/svg+xml", :svg
|
@@ -10,7 +10,7 @@ module RQRCode
|
|
10
10
|
format = self.request.format.symbol
|
11
11
|
|
12
12
|
qrcode = RQRCode::QRCode.new(string)
|
13
|
-
svg = RQRCode::Renderers::SVG::render(qrcode)
|
13
|
+
svg = RQRCode::Renderers::SVG::render(qrcode, options)
|
14
14
|
|
15
15
|
data = \
|
16
16
|
if format == :png
|
@@ -2,9 +2,15 @@ module RQRCode
|
|
2
2
|
module Renderers
|
3
3
|
class SVG
|
4
4
|
class << self
|
5
|
+
# Render the SVG from the qrcode string provided from the RQRCode gem
|
6
|
+
# Options:
|
7
|
+
# offset - Padding around the QR Code (e.g. 10)
|
8
|
+
# fill - Background color (e.g "ffffff" or :white)
|
9
|
+
# color - Foreground color for the code (e.g. "000000" or :black)
|
10
|
+
|
5
11
|
def render(qrcode, options={})
|
6
|
-
|
7
|
-
|
12
|
+
offset = options[:offset].to_i || 0
|
13
|
+
color = options[:color] || "000"
|
8
14
|
|
9
15
|
# height and width dependent on offset and QR complexity
|
10
16
|
dimension = (qrcode.module_count*11) + (2*offset)
|
@@ -20,13 +26,16 @@ module RQRCode
|
|
20
26
|
y = c*11 + offset
|
21
27
|
x = r*11 + offset
|
22
28
|
|
23
|
-
next unless qrcode.is_dark(c, r)
|
24
|
-
|
25
|
-
color = qrcode.is_dark(c, r) ? "000" : "fff"
|
29
|
+
next unless qrcode.is_dark(c, r)
|
26
30
|
tmp << %{<rect width="11" height="11" x="#{x}" y="#{y}" style="fill:##{color}"/>}
|
27
31
|
end
|
28
32
|
result << tmp.join
|
29
33
|
end
|
34
|
+
|
35
|
+
if options[:fill]
|
36
|
+
result.unshift %{<rect width="#{dimension}" height="#{dimension}" x="0" y="0" style="fill:##{options[:fill]}"/>}
|
37
|
+
end
|
38
|
+
|
30
39
|
svg = [xml_tag, open_tag, result, close_tag].flatten.join("\n")
|
31
40
|
end
|
32
41
|
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: 31
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
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-06-08 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
version: 0.3.3
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
|
-
description: Render QR
|
37
|
+
description: Render QR codes with Rails 3
|
38
38
|
email: sam.vincent@mac.com
|
39
39
|
executables: []
|
40
40
|
|
@@ -43,8 +43,8 @@ extensions: []
|
|
43
43
|
extra_rdoc_files: []
|
44
44
|
|
45
45
|
files:
|
46
|
-
- lib/
|
47
|
-
- lib/
|
46
|
+
- lib/rqrcode-rails3/renderers/svg.rb
|
47
|
+
- lib/rqrcode-rails3.rb
|
48
48
|
- MIT-LICENSE
|
49
49
|
- Rakefile
|
50
50
|
- Gemfile
|
@@ -79,9 +79,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements: []
|
80
80
|
|
81
81
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.
|
82
|
+
rubygems_version: 1.3.7
|
83
83
|
signing_key:
|
84
84
|
specification_version: 3
|
85
|
-
summary: Render QR
|
85
|
+
summary: Render QR codes with Rails 3
|
86
86
|
test_files: []
|
87
87
|
|