Generate qr code for flyers

This commit is contained in:
Stefan Schlott 2013-09-05 16:49:22 +02:00
parent a563710a69
commit a43bf169a0
5 changed files with 56 additions and 4 deletions

View file

@ -12,4 +12,5 @@ gem 't'
gem 'nokogiri'
gem 'feedzirra'
gem 'ri_cal'
gem 'rqrcode_png'

View file

@ -8,6 +8,7 @@ GEM
adsf (1.0.1)
rack (>= 1.0.0)
builder (3.2.2)
chunky_png (1.2.8)
coderay (1.0.9)
colored (1.2)
cookiejar (0.3.0)
@ -95,6 +96,10 @@ GEM
json (~> 1.4)
retryable (1.3.2)
ri_cal (0.8.8)
rqrcode (0.4.2)
rqrcode_png (0.1.1)
chunky_png
rqrcode
sass (3.2.10)
sax-machine (0.1.0)
nokogiri (> 0.0.0)
@ -137,6 +142,7 @@ DEPENDENCIES
nokogiri
rdiscount
ri_cal
rqrcode_png
sass
systemu
t

View file

@ -3,7 +3,34 @@ aliases :cf
summary 'creates svg for flyer'
description 'Create SVG file with content of given event'
class CreateFlyer < ::Nanoc::CLI::CommandRunner
require 'rqrcode_png'
# Monkey-patch qr generator
module RQRCodePNG
class Sequence
def border_width()
# No boundary around image
0
end
end
end
def getQR(data)
qr = nil
size = 7
while (!qr)
begin
qr = RQRCode::QRCode.new(data, :size => size, :level => :l)
rescue RQRCode::QRCodeRunTimeError
qr = nil
size = size + 1
end
end
qr
end
def run
# Check arguments
if arguments.length!=2
@ -24,6 +51,7 @@ class CreateFlyer < ::Nanoc::CLI::CommandRunner
end
# Collect data
merge_item_location_data(event[:location], self.site.items['/_data/locations/'].attributes)
calculate_to_date(event)
self.site.compile
title = event[:title]
date = event[:startdate]
@ -60,6 +88,16 @@ class CreateFlyer < ::Nanoc::CLI::CommandRunner
"#{i[:startdate].strftime("%d.%m.%Y, %H:%M")}h: #{i[:title]}"
end
end
vevent = []
vevent << "BEGIN:VEVENT"
vevent << "SUMMARY:#{event[:title]}"
vevent << "DTSTART:#{event[:startdate].getutc.strftime("%Y%m%dT%H%M%SZ")}"
vevent << "DTEND:#{event[:enddate].getutc.strftime("%Y%m%dT%H%M%SZ")}"
vevent << "LOCATION:#{location_name.join(", ")}"
vevent << "DESCRIPTION:Weitere Infos: #{site.config[:base_url]}#{event.path()}"
vevent << "END:VEVENT"
# Generate qr code
qr_img = getQR(vevent.join("\n")).to_img
# Read template
file = File.open(self.site.items['/_data/aushang/'].raw_filename(), "r:UTF-8")
template = file.read
@ -71,6 +109,7 @@ class CreateFlyer < ::Nanoc::CLI::CommandRunner
template.gsub!('${location.name}', location_name.join(", "))
template.gsub!('${location.address}', location_address.join(", "))
template.gsub!('${location.geo}', location_geo)
template.gsub!('${qrcode}', "#{qr_img.to_data_url}")
for i in 0..5 do
template.gsub!("${calendar.#{i}}", calendar[i] || "")
end

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Before After
Before After

View file

@ -26,8 +26,8 @@ def get_public_events()
items.select { |i| (i[:kind]=='event') && i[:public] }
end
def calculate_to_dates()
items.select { |i| (i[:kind]=='event') && i[:duration] }.each do |e|
def calculate_to_date(e)
if e[:duration]
if e[:startdate].instance_of?(Date)
if e[:duration] =~ /(\d+)d/
e[:enddate] = e[:startdate] + ($1.to_i - 1)
@ -43,6 +43,12 @@ def calculate_to_dates()
end
end
def calculate_to_dates()
items.select { |i| (i[:kind]=='event') && i[:duration] }.each do |e|
calculate_to_date(e)
end
end
def conv_tz(t)
if (t.utc?)
Time.local(t.year, t.month, t.day, t.hour, t.min, t.sec)