rqrcode-rails3-0.1.7/0000755000004100000410000000000012560075142014403 5ustar www-datawww-datarqrcode-rails3-0.1.7/Rakefile0000644000004100000410000000115612560075142016053 0ustar www-datawww-data# encoding: UTF-8 require 'rubygems' begin require 'bundler/setup' rescue LoadError puts 'You must `gem install bundler` and `bundle install` to run rake tasks' end require 'rake' require 'rdoc/task' require 'rake/testtask' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.libs << 'test' t.pattern = 'test/**/*_test.rb' t.verbose = false end task :default => :test Rake::RDocTask.new(:rdoc) do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = 'rqrcode-rails3' rdoc.options << '--line-numbers' << '--inline-source' rdoc.rdoc_files.include('README.rdoc') rdoc.rdoc_files.include('lib/**/*.rb') end rqrcode-rails3-0.1.7/Gemfile0000644000004100000410000000036612560075142015703 0ustar www-datawww-datasource "http://rubygems.org" gem "rails", ">= 3.0.0" gem "capybara", ">= 0.4.0" gem "sqlite3" gem "rqrcode" gem "mini_magick" # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+) # gem 'ruby-debug' # gem 'ruby-debug19' rqrcode-rails3-0.1.7/MIT-LICENSE0000644000004100000410000000203012560075142016032 0ustar www-datawww-dataCopyright 2011 YOURNAME Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. rqrcode-rails3-0.1.7/lib/0000755000004100000410000000000012560075142015151 5ustar www-datawww-datarqrcode-rails3-0.1.7/lib/rqrcode-rails3/0000755000004100000410000000000012560075142020003 5ustar www-datawww-datarqrcode-rails3-0.1.7/lib/rqrcode-rails3/size_calculator.rb0000644000004100000410000000225712560075142023521 0ustar www-datawww-datamodule RQRCode module SizeCalculator # size - seems to follow this logic # # | input | modules # | size | created #-------|-------|-------- # 1 | 7 | 21 # 2 | 14 | 25 (+4) # 3 | 24 | 29 - # 4 | 34 | 33 - # 5 | 44 | 37 - # 6 | 58 | 41 - # 7 | 64 | 45 - # 8 | 84 | 49 - # 9 | 98 | 53 - # 10 | 119 | 57 - # 11 | 137 | 61 - # 12 | 155 | 65 - # 13 | 177 | 69 - # 14 | 194 | 73 - QR_CHAR_SIZE_VS_SIZE = [7, 14, 24, 34, 44, 58, 64, 84, 98, 119, 137, 155, 177, 194] def minimum_qr_size_from_string(string) QR_CHAR_SIZE_VS_SIZE.each_with_index do |size, index| return (index + 1) if string.size < size end # If it's particularly big, we'll try and create codes until it accepts i = QR_CHAR_SIZE_VS_SIZE.size begin i += 1 RQRCode::QRCode.new(string, :size => i) return i rescue RQRCode::QRCodeRunTimeError retry end end end endrqrcode-rails3-0.1.7/lib/rqrcode-rails3/renderers/0000755000004100000410000000000012560075142021774 5ustar www-datawww-datarqrcode-rails3-0.1.7/lib/rqrcode-rails3/renderers/svg.rb0000644000004100000410000000335112560075142023122 0ustar www-datawww-datamodule RQRCode module Renderers class SVG class << self # Render the SVG from the qrcode string provided from the RQRCode gem # Options: # offset - Padding around the QR Code (e.g. 10) # unit - How many pixels per module (Default: 11) # fill - Background color (e.g "ffffff" or :white) # color - Foreground color for the code (e.g. "000000" or :black) def render(qrcode, options={}) offset = options[:offset].to_i || 0 color = options[:color] || "000" unit = options[:unit] || 11 # height and width dependent on offset and QR complexity dimension = (qrcode.module_count*unit) + (2*offset) xml_tag = %{} open_tag = %{} close_tag = "" result = [] qrcode.modules.each_index do |c| tmp = [] qrcode.modules.each_index do |r| y = c*unit + offset x = r*unit + offset next unless qrcode.is_dark(c, r) tmp << %{} end result << tmp.join end if options[:fill] result.unshift %{} end svg = [xml_tag, open_tag, result, close_tag].flatten.join("\n") end end end end end rqrcode-rails3-0.1.7/lib/rqrcode-rails3.rb0000644000004100000410000000240012560075142020324 0ustar www-datawww-datarequire 'action_controller' require 'rqrcode' require 'rqrcode-rails3/size_calculator.rb' require 'rqrcode-rails3/renderers/svg.rb' module RQRCode Mime::Type.register "image/svg+xml", :svg unless Mime::Type.lookup_by_extension(:svg) Mime::Type.register "image/png", :png unless Mime::Type.lookup_by_extension(:png) Mime::Type.register "image/jpeg", :jpeg unless Mime::Type.lookup_by_extension(:jpeg) Mime::Type.register "image/gif", :gif unless Mime::Type.lookup_by_extension(:gif) extend SizeCalculator def render_qrcode(string, format, options) size = options[:size] || RQRCode.minimum_qr_size_from_string(string) level = options[:level] || :h qrcode = RQRCode::QRCode.new(string, :size => size, :level => level) svg = RQRCode::Renderers::SVG::render(qrcode, options) if format && format == :svg svg else image = MiniMagick::Image.read(svg) { |i| i.format "svg" } image.format format image.to_blob end end module_function :render_qrcode ActionController::Renderers.add :qrcode do |string, options| format = self.request.format.symbol data = RQRCode.render_qrcode(string, format, options) self.response_body = render_to_string(:text => data, :template => nil) end end rqrcode-rails3-0.1.7/metadata.yml0000644000004100000410000000274312560075142016714 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: rqrcode-rails3 version: !ruby/object:Gem::Version version: 0.1.7 prerelease: platform: ruby authors: - Sam Vincent autorequire: bindir: bin cert_chain: [] date: 2013-11-20 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: rqrcode requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: 0.4.2 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: 0.4.2 description: Render QR codes with Rails 3 email: sam.vincent@mac.com executables: [] extensions: [] extra_rdoc_files: [] files: - lib/rqrcode-rails3/renderers/svg.rb - lib/rqrcode-rails3/size_calculator.rb - lib/rqrcode-rails3.rb - MIT-LICENSE - Rakefile - Gemfile - README.md homepage: http://github.com/samvincent/rqrcode-rails3 licenses: [] post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 1.8.25 signing_key: specification_version: 3 summary: Render QR codes with Rails 3 test_files: [] rqrcode-rails3-0.1.7/README.md0000644000004100000410000000350512560075142015665 0ustar www-datawww-data# Render QR codes easily from your Rails 3 application This gem supports rendering either SVG or PNG, JPEG, and GIF formats. 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. ## Installation Add the following to your `Gemfile`. gem 'rqrcode-rails3' If you want to use the PNG, JPEG or GIF format, you will have to have **ImageMagick** installed on your system. You will also want to add the **mini_magick** gem to your application's `Gemfile`. gem 'mini_magick' ## How to use In your controller actions, you could return a QR code that links to the current page like this: ```ruby respond_to do |format| format.html format.svg { render :qrcode => request.url, :level => :l, :unit => 10 } format.png { render :qrcode => request.url } format.gif { render :qrcode => request.url } format.jpeg { render :qrcode => request.url } end ``` #### Options: * `:size` – This controls how big the QR Code will be. Smallest size will be chosen by default. Set to maintain consistent size. * `:level` – The error correction level, can be: * Level `:l` 7% of code can be restored * Level `:m` 15% of code can be restored * Level `:q` 25% of code can be restored * Level `:h` 30% of code can be restored (default :h) * `:offset` – Padding around the QR Code (e.g. 10) * `:unit` – How many pixels per module (e.g. 11) * `:fill` – Background color (e.g "ffffff" or :white) * `:color` – Foreground color for the code (e.g. "000000" or :black) ## About This project was inspired by the first chapter in José Valim's book [Crafting Rails Applications](http://pragprog.com/titles/jvrails/crafting-rails-applications) QR codes are encoded by [rqrcode](https://github.com/whomwah/rqrcode)