rqrcode-rails3 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +12 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +26 -0
- data/Rakefile +29 -0
- data/lib/rqrcode_rails3.rb +26 -0
- data/lib/rqrcode_rails3/renderers/svg.rb +37 -0
- metadata +72 -0
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "rails", ">= 3.0.0"
|
4
|
+
gem "capybara" #, ">= 0.4.0"
|
5
|
+
gem "sqlite3"
|
6
|
+
|
7
|
+
gem "rqrcode"
|
8
|
+
gem "mini_magick"
|
9
|
+
|
10
|
+
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
|
11
|
+
# gem 'ruby-debug'
|
12
|
+
# gem 'ruby-debug19'
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Render QR Codes easily from your Rails 3 controllers. This gem can return SVG and PNG files.
|
2
|
+
|
3
|
+
== Installation
|
4
|
+
|
5
|
+
Add the gem to your Gemfile
|
6
|
+
|
7
|
+
gem "rqrcode-rails3"
|
8
|
+
|
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 "mini_magick" gem to your Gemfile
|
11
|
+
|
12
|
+
gem "mini_magick"
|
13
|
+
|
14
|
+
== How to use
|
15
|
+
|
16
|
+
In your controller actions, you can return a QRCode that links to the current page like this:
|
17
|
+
|
18
|
+
respond_to do |format|
|
19
|
+
format.html
|
20
|
+
format.svg { render :qrcode => request.url }
|
21
|
+
format.png { render :qrcode => request.url }
|
22
|
+
end
|
23
|
+
|
24
|
+
----------------------------------------
|
25
|
+
|
26
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
|
12
|
+
require 'rake/testtask'
|
13
|
+
|
14
|
+
Rake::TestTask.new(:test) do |t|
|
15
|
+
t.libs << 'lib'
|
16
|
+
t.libs << 'test'
|
17
|
+
t.pattern = 'test/**/*_test.rb'
|
18
|
+
t.verbose = false
|
19
|
+
end
|
20
|
+
|
21
|
+
task :default => :test
|
22
|
+
|
23
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
24
|
+
rdoc.rdoc_dir = 'rdoc'
|
25
|
+
rdoc.title = 'Rqrcode-svg'
|
26
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
27
|
+
rdoc.rdoc_files.include('README.rdoc')
|
28
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "action_controller"
|
2
|
+
require 'rqrcode'
|
3
|
+
require 'rqrcode_rails3/renderers/svg.rb'
|
4
|
+
|
5
|
+
module RQRCode
|
6
|
+
Mime::Type.register "image/svg+xml", :svg
|
7
|
+
Mime::Type.register "image/png", :png
|
8
|
+
|
9
|
+
ActionController::Renderers.add :qrcode do |string, options|
|
10
|
+
format = self.request.format.symbol
|
11
|
+
|
12
|
+
qrcode = RQRCode::QRCode.new(string)
|
13
|
+
svg = RQRCode::Renderers::SVG::render(qrcode)
|
14
|
+
|
15
|
+
data = \
|
16
|
+
if format == :png
|
17
|
+
image = MiniMagick::Image.read(svg) { |i| i.format "svg" }
|
18
|
+
image.format "png"
|
19
|
+
png = image.to_blob
|
20
|
+
else
|
21
|
+
svg
|
22
|
+
end
|
23
|
+
|
24
|
+
self.response_body = render_to_string(:text => data, :template => nil)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module RQRCode
|
2
|
+
module Renderers
|
3
|
+
class SVG
|
4
|
+
class << self
|
5
|
+
def render(qrcode, options={})
|
6
|
+
# Padding around the qrcode
|
7
|
+
offset = options[:offset] || 0
|
8
|
+
|
9
|
+
# height and width dependent on offset and QR complexity
|
10
|
+
dimension = (qrcode.module_count*11) + (2*offset)
|
11
|
+
|
12
|
+
xml_tag = %{<?xml version="1.0" standalone="yes"?>}
|
13
|
+
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}">}
|
14
|
+
close_tag = "</svg>"
|
15
|
+
|
16
|
+
result = []
|
17
|
+
qrcode.modules.each_index do |c|
|
18
|
+
tmp = []
|
19
|
+
qrcode.modules.each_index do |r|
|
20
|
+
y = c*11 + offset
|
21
|
+
x = r*11 + offset
|
22
|
+
row = %{<rect width="11" height="11" x="#{x}" y="#{y}" style="fill:#000"/>}
|
23
|
+
col = options[:fill] ? %{<rect width="11" height="11" x="#{x}" y="#{y}" style="fill:#fff"/>} : ""
|
24
|
+
if qrcode.is_dark(c,r)
|
25
|
+
tmp << row
|
26
|
+
else
|
27
|
+
tmp << col
|
28
|
+
end
|
29
|
+
end
|
30
|
+
result << tmp.join
|
31
|
+
end
|
32
|
+
svg = [xml_tag, open_tag, result, close_tag].flatten.join("\n")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rqrcode-rails3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors: []
|
13
|
+
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-21 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Render QR Codes with Rails 3
|
23
|
+
email:
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/rqrcode_rails3/renderers/svg.rb
|
32
|
+
- lib/rqrcode_rails3.rb
|
33
|
+
- MIT-LICENSE
|
34
|
+
- Rakefile
|
35
|
+
- Gemfile
|
36
|
+
- README.rdoc
|
37
|
+
has_rdoc: true
|
38
|
+
homepage:
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
hash: 3
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.6.2
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Render QR Codes with Rails 3
|
71
|
+
test_files: []
|
72
|
+
|