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.
Files changed (3) hide show
  1. data/README.md +33 -29
  2. data/lib/rqrcode-rails3.rb +14 -12
  3. metadata +10 -5
data/README.md CHANGED
@@ -1,45 +1,49 @@
1
- = Render QR codes easily from your Rails 3 application
1
+ # Render QR codes easily from your Rails 3 application
2
2
 
3
- This gem supports rendering either SVG or PNG format.
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
- == Installation
7
+ ## Installation
8
8
 
9
- Add the following to your +Gemfile+.
9
+ Add the following to your `Gemfile`.
10
10
 
11
- gem 'rqrcode-rails3'
11
+ gem 'rqrcode-rails3'
12
12
 
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+.
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
- gem 'mini_magick'
16
+ gem 'mini_magick'
17
17
 
18
- == How to use
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
- respond_to do |format|
23
- format.html
24
- format.svg { render :qrcode => request.url, :level => :l, :unit => 10 }
25
- format.png { render :qrcode => request.url }
26
- end
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
- * +: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)
36
- * +:offset+ – Padding around the QR Code (e.g. 10)
37
- * +:unit+ – How many pixels per module (e.g. 11)
38
- * +:fill+ – Background color (e.g "ffffff" or :white)
39
- * +:color+ – Foreground color for the code (e.g. "000000" or :black)
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
- == About
45
+ ## About
42
46
 
43
- This project was inspired by the first chapter in José Valim's book {Crafting Rails Applications}[http://pragprog.com/titles/jvrails/crafting-rails-applications]
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 {rqrcode}[https://github.com/whomwah/rqrcode]
49
+ QR codes are encoded by [rqrcode](https://github.com/whomwah/rqrcode)
@@ -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 unless Mime::Type.lookup_by_extension(:svg)
8
- Mime::Type.register "image/png", :png unless Mime::Type.lookup_by_extension(: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 == :png
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.5
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-02-10 00:00:00.000000000Z
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: &70360232287200 !ruby/object:Gem::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: *70360232287200
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.6
63
+ rubygems_version: 1.8.24
59
64
  signing_key:
60
65
  specification_version: 3
61
66
  summary: Render QR codes with Rails 3