Permalink
Browse files

first stab at qr codes w/ ascii armor

  • Loading branch information...
1 parent 7d1c360 commit 9f589b42c4fea0c78e882cd19bc99255ff5be234 @erikh erikh committed Apr 19, 2012
Showing with 71 additions and 4 deletions.
  1. +16 −4 app.rb
  2. +32 −0 public/css/ascii.css
  3. +10 −0 views/ascii_index.haml
  4. +13 −0 views/ascii_qrcode.haml
View
20 app.rb
@@ -1,10 +1,22 @@
+require 'bundler/setup'
require 'sinatra'
require 'rqrcode'
-get '/' do
- haml :index
+set :public_folder, File.dirname(__FILE__) + '/public'
+
+MAX_KEY_LENGTH = 4096
+QRCODE_SIZE = 40
+QRCODE_LEVEL = :m
+
+get '/ascii' do
+ haml :ascii_index
end
-post '/' do
- haml :qrcode
+post '/ascii' do
+ qrcode = params[:qrcode]
+ raise "too long" if qrcode.length > MAX_KEY_LENGTH
+
+ @qr = RQRCode::QRCode.new(qrcode, :size => QRCODE_SIZE, :level => QRCODE_LEVEL)
+
+ haml :ascii_qrcode
end
View
@@ -0,0 +1,32 @@
+#submit {
+ margin-left: 2.5%;
+}
+
+textarea {
+ position: relative;
+ width: 95%;
+ height: 90%;
+ margin-left: 2.5%;
+ margin-right: 2.5%;
+}
+
+table {
+ border-width: 0;
+ border-style: none;
+ border-color: #0000ff;
+ border-collapse: collapse;
+}
+
+td {
+ border-width: 0;
+ border-style: none;
+ border-color: #0000ff;
+ border-collapse: collapse;
+ padding: 0;
+ margin: 0;
+ width: 4px;
+ height: 4px;
+}
+
+td.black { background-color: #000; }
+td.white { background-color: #fff; }
View
@@ -0,0 +1,10 @@
+%html
+ %head
+ %title Input ASCII-armored PGP Key
+ %link{:rel => "stylesheet", :type => "text/css", :href => "/css/ascii.css"}
+ %body
+ #main
+ %form{:action => "/ascii", :method => "POST"}
+ %textarea{:name => "qrcode"}
+ #submit
+ %input{:type => "submit", :value => "Show QR Code"}
View
@@ -0,0 +1,13 @@
+%html
+ %head
+ %title Input ASCII-armored PGP Key
+ %link{:rel => "stylesheet", :type => "text/css", :href => "/css/ascii.css"}
+ %body
+ %table
+ - @qr.modules.each_index do |x|
+ %tr
+ - @qr.modules.each_index do |y|
+ - if @qr.dark?(x,y)
+ %td.black
+ - else
+ %td.white

0 comments on commit 9f589b4

Please sign in to comment.