rqrcode-rails3 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +33 -29
- data/lib/rqrcode-rails3.rb +14 -12
- metadata +10 -5
data/README.md
CHANGED
@@ -1,45 +1,49 @@
|
|
1
|
-
|
1
|
+
# Render QR codes easily from your Rails 3 application
|
2
2
|
|
3
|
-
This gem supports rendering either SVG or PNG
|
3
|
+
This gem supports rendering either SVG or PNG, JPEG, and GIF formats.
|
4
4
|
|
5
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.
|
6
6
|
|
7
|
-
|
7
|
+
## Installation
|
8
8
|
|
9
|
-
Add the following to your
|
9
|
+
Add the following to your `Gemfile`.
|
10
10
|
|
11
|
-
|
11
|
+
gem 'rqrcode-rails3'
|
12
12
|
|
13
|
-
If you want to use the PNG format, you will have to have
|
14
|
-
You will also want to add the
|
13
|
+
If you want to use the PNG, JPEG or GIF 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`.
|
15
15
|
|
16
|
-
|
16
|
+
gem 'mini_magick'
|
17
17
|
|
18
|
-
|
18
|
+
## How to use
|
19
19
|
|
20
20
|
In your controller actions, you could return a QR code that links to the current page like this:
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
```ruby
|
23
|
+
respond_to do |format|
|
24
|
+
format.html
|
25
|
+
format.svg { render :qrcode => request.url, :level => :l, :unit => 10 }
|
26
|
+
format.png { render :qrcode => request.url }
|
27
|
+
format.gif { render :qrcode => request.url }
|
28
|
+
format.jpeg { render :qrcode => request.url }
|
29
|
+
end
|
30
|
+
```
|
27
31
|
|
28
|
-
Options:
|
29
|
-
|
30
|
-
*
|
31
|
-
*
|
32
|
-
* Level
|
33
|
-
* Level
|
34
|
-
* Level
|
35
|
-
* Level
|
36
|
-
*
|
37
|
-
*
|
38
|
-
*
|
39
|
-
*
|
32
|
+
#### Options:
|
33
|
+
|
34
|
+
* `:size` – This controls how big the QR Code will be. Smallest size will be chosen by default. Set to maintain consistent size.
|
35
|
+
* `:level` – The error correction level, can be:
|
36
|
+
* Level `:l` 7% of code can be restored
|
37
|
+
* Level `:m` 15% of code can be restored
|
38
|
+
* Level `:q` 25% of code can be restored
|
39
|
+
* Level `:h` 30% of code can be restored (default :h)
|
40
|
+
* `:offset` – Padding around the QR Code (e.g. 10)
|
41
|
+
* `:unit` – How many pixels per module (e.g. 11)
|
42
|
+
* `:fill` – Background color (e.g "ffffff" or :white)
|
43
|
+
* `:color` – Foreground color for the code (e.g. "000000" or :black)
|
40
44
|
|
41
|
-
|
45
|
+
## About
|
42
46
|
|
43
|
-
This project was inspired by the first chapter in José Valim's book
|
47
|
+
This project was inspired by the first chapter in José Valim's book [Crafting Rails Applications](http://pragprog.com/titles/jvrails/crafting-rails-applications)
|
44
48
|
|
45
|
-
QR codes are encoded by
|
49
|
+
QR codes are encoded by [rqrcode](https://github.com/whomwah/rqrcode)
|
data/lib/rqrcode-rails3.rb
CHANGED
@@ -4,28 +4,30 @@ require 'rqrcode-rails3/size_calculator.rb'
|
|
4
4
|
require 'rqrcode-rails3/renderers/svg.rb'
|
5
5
|
|
6
6
|
module RQRCode
|
7
|
-
Mime::Type.register "image/svg+xml", :svg
|
8
|
-
Mime::Type.register "image/png", :png
|
9
|
-
|
7
|
+
Mime::Type.register "image/svg+xml", :svg unless Mime::Type.lookup_by_extension(:svg)
|
8
|
+
Mime::Type.register "image/png", :png unless Mime::Type.lookup_by_extension(:png)
|
9
|
+
Mime::Type.register "image/jpeg", :jpeg unless Mime::Type.lookup_by_extension(:jpeg)
|
10
|
+
Mime::Type.register "image/gif", :gif unless Mime::Type.lookup_by_extension(:gif)
|
11
|
+
|
10
12
|
extend SizeCalculator
|
11
|
-
|
13
|
+
|
12
14
|
ActionController::Renderers.add :qrcode do |string, options|
|
13
15
|
format = self.request.format.symbol
|
14
16
|
size = options[:size] || RQRCode.minimum_qr_size_from_string(string)
|
15
17
|
level = options[:level] || :h
|
16
|
-
|
18
|
+
|
17
19
|
qrcode = RQRCode::QRCode.new(string, :size => size, :level => level)
|
18
20
|
svg = RQRCode::Renderers::SVG::render(qrcode, options)
|
19
|
-
|
21
|
+
|
20
22
|
data = \
|
21
|
-
if format == :
|
22
|
-
image = MiniMagick::Image.read(svg) { |i| i.format "svg" }
|
23
|
-
image.format "png"
|
24
|
-
png = image.to_blob
|
25
|
-
else
|
23
|
+
if format && format == :svg
|
26
24
|
svg
|
25
|
+
else
|
26
|
+
image = MiniMagick::Image.read(svg) { |i| i.format "svg" }
|
27
|
+
image.format format
|
28
|
+
image.to_blob
|
27
29
|
end
|
28
|
-
|
30
|
+
|
29
31
|
self.response_body = render_to_string(:text => data, :template => nil)
|
30
32
|
end
|
31
33
|
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.6
|
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-
|
12
|
+
date: 2012-12-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rqrcode
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: 0.4.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.4.2
|
25
30
|
description: Render QR codes with Rails 3
|
26
31
|
email: sam.vincent@mac.com
|
27
32
|
executables: []
|
@@ -55,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
60
|
version: '0'
|
56
61
|
requirements: []
|
57
62
|
rubyforge_project:
|
58
|
-
rubygems_version: 1.8.
|
63
|
+
rubygems_version: 1.8.24
|
59
64
|
signing_key:
|
60
65
|
specification_version: 3
|
61
66
|
summary: Render QR codes with Rails 3
|