Generate qr code for flyers
This commit is contained in:
parent
a563710a69
commit
a43bf169a0
5 changed files with 56 additions and 4 deletions
1
Gemfile
1
Gemfile
|
|
@ -12,4 +12,5 @@ gem 't'
|
||||||
gem 'nokogiri'
|
gem 'nokogiri'
|
||||||
gem 'feedzirra'
|
gem 'feedzirra'
|
||||||
gem 'ri_cal'
|
gem 'ri_cal'
|
||||||
|
gem 'rqrcode_png'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ GEM
|
||||||
adsf (1.0.1)
|
adsf (1.0.1)
|
||||||
rack (>= 1.0.0)
|
rack (>= 1.0.0)
|
||||||
builder (3.2.2)
|
builder (3.2.2)
|
||||||
|
chunky_png (1.2.8)
|
||||||
coderay (1.0.9)
|
coderay (1.0.9)
|
||||||
colored (1.2)
|
colored (1.2)
|
||||||
cookiejar (0.3.0)
|
cookiejar (0.3.0)
|
||||||
|
|
@ -95,6 +96,10 @@ GEM
|
||||||
json (~> 1.4)
|
json (~> 1.4)
|
||||||
retryable (1.3.2)
|
retryable (1.3.2)
|
||||||
ri_cal (0.8.8)
|
ri_cal (0.8.8)
|
||||||
|
rqrcode (0.4.2)
|
||||||
|
rqrcode_png (0.1.1)
|
||||||
|
chunky_png
|
||||||
|
rqrcode
|
||||||
sass (3.2.10)
|
sass (3.2.10)
|
||||||
sax-machine (0.1.0)
|
sax-machine (0.1.0)
|
||||||
nokogiri (> 0.0.0)
|
nokogiri (> 0.0.0)
|
||||||
|
|
@ -137,6 +142,7 @@ DEPENDENCIES
|
||||||
nokogiri
|
nokogiri
|
||||||
rdiscount
|
rdiscount
|
||||||
ri_cal
|
ri_cal
|
||||||
|
rqrcode_png
|
||||||
sass
|
sass
|
||||||
systemu
|
systemu
|
||||||
t
|
t
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,34 @@ aliases :cf
|
||||||
summary 'creates svg for flyer'
|
summary 'creates svg for flyer'
|
||||||
description 'Create SVG file with content of given event'
|
description 'Create SVG file with content of given event'
|
||||||
|
|
||||||
|
|
||||||
class CreateFlyer < ::Nanoc::CLI::CommandRunner
|
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
|
def run
|
||||||
# Check arguments
|
# Check arguments
|
||||||
if arguments.length!=2
|
if arguments.length!=2
|
||||||
|
|
@ -24,6 +51,7 @@ class CreateFlyer < ::Nanoc::CLI::CommandRunner
|
||||||
end
|
end
|
||||||
# Collect data
|
# Collect data
|
||||||
merge_item_location_data(event[:location], self.site.items['/_data/locations/'].attributes)
|
merge_item_location_data(event[:location], self.site.items['/_data/locations/'].attributes)
|
||||||
|
calculate_to_date(event)
|
||||||
self.site.compile
|
self.site.compile
|
||||||
title = event[:title]
|
title = event[:title]
|
||||||
date = event[:startdate]
|
date = event[:startdate]
|
||||||
|
|
@ -60,6 +88,16 @@ class CreateFlyer < ::Nanoc::CLI::CommandRunner
|
||||||
"#{i[:startdate].strftime("%d.%m.%Y, %H:%M")}h: #{i[:title]}"
|
"#{i[:startdate].strftime("%d.%m.%Y, %H:%M")}h: #{i[:title]}"
|
||||||
end
|
end
|
||||||
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
|
# Read template
|
||||||
file = File.open(self.site.items['/_data/aushang/'].raw_filename(), "r:UTF-8")
|
file = File.open(self.site.items['/_data/aushang/'].raw_filename(), "r:UTF-8")
|
||||||
template = file.read
|
template = file.read
|
||||||
|
|
@ -71,6 +109,7 @@ class CreateFlyer < ::Nanoc::CLI::CommandRunner
|
||||||
template.gsub!('${location.name}', location_name.join(", "))
|
template.gsub!('${location.name}', location_name.join(", "))
|
||||||
template.gsub!('${location.address}', location_address.join(", "))
|
template.gsub!('${location.address}', location_address.join(", "))
|
||||||
template.gsub!('${location.geo}', location_geo)
|
template.gsub!('${location.geo}', location_geo)
|
||||||
|
template.gsub!('${qrcode}', "#{qr_img.to_data_url}")
|
||||||
for i in 0..5 do
|
for i in 0..5 do
|
||||||
template.gsub!("${calendar.#{i}}", calendar[i] || "")
|
template.gsub!("${calendar.#{i}}", calendar[i] || "")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 24 KiB |
|
|
@ -26,8 +26,8 @@ def get_public_events()
|
||||||
items.select { |i| (i[:kind]=='event') && i[:public] }
|
items.select { |i| (i[:kind]=='event') && i[:public] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_to_dates()
|
def calculate_to_date(e)
|
||||||
items.select { |i| (i[:kind]=='event') && i[:duration] }.each do |e|
|
if e[:duration]
|
||||||
if e[:startdate].instance_of?(Date)
|
if e[:startdate].instance_of?(Date)
|
||||||
if e[:duration] =~ /(\d+)d/
|
if e[:duration] =~ /(\d+)d/
|
||||||
e[:enddate] = e[:startdate] + ($1.to_i - 1)
|
e[:enddate] = e[:startdate] + ($1.to_i - 1)
|
||||||
|
|
@ -43,6 +43,12 @@ def calculate_to_dates()
|
||||||
end
|
end
|
||||||
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)
|
def conv_tz(t)
|
||||||
if (t.utc?)
|
if (t.utc?)
|
||||||
Time.local(t.year, t.month, t.day, t.hour, t.min, t.sec)
|
Time.local(t.year, t.month, t.day, t.hour, t.min, t.sec)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue