From 2e391bace68c3ce152b49021a512d81242ccff3a Mon Sep 17 00:00:00 2001 From: Stefan Schlott Date: Fri, 6 Sep 2013 08:17:52 +0200 Subject: [PATCH] Create flyer --- commands/create-flyer.rb | 73 +++++---- content/_data/flyer.svg | 318 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 358 insertions(+), 33 deletions(-) create mode 100644 content/_data/flyer.svg diff --git a/commands/create-flyer.rb b/commands/create-flyer.rb index ac2f7275..cda3081b 100644 --- a/commands/create-flyer.rb +++ b/commands/create-flyer.rb @@ -17,7 +17,7 @@ class CreateFlyer < ::Nanoc::CLI::CommandRunner end end - def getQR(data) + def get_qr(data) qr = nil size = 7 while (!qr) @@ -31,6 +31,26 @@ class CreateFlyer < ::Nanoc::CLI::CommandRunner qr end + def create_svg(template_name, output_name, data) + # Read template + file = File.open(template_name, "r:UTF-8") + template = file.read + file.close() + # Replace in template + template.gsub!('${title}', data[:title]) + template.gsub!('${date}', data[:date].strftime("%d.%m.%Y, %H:%M")) + template.gsub!('${speakers}', data[:speakers].join(', ')) + template.gsub!('${location.name}', data[:location_name].join(", ")) + template.gsub!('${location.address}', data[:location_address].join(", ")) + template.gsub!('${location.geo}', data[:location_geo]) + template.gsub!('${qrcode}', "#{data[:qr_img].to_data_url}") + for i in 0..5 do + template.gsub!("${calendar.#{i}}", data[:calendar][i] || "") + end + # Output + File.open(output_name, 'w:UTF-8') {|f| f.write(template) } + end + def run # Check arguments if arguments.length!=2 @@ -53,27 +73,28 @@ class CreateFlyer < ::Nanoc::CLI::CommandRunner 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] - speakers = event[:speakers].map { |s| if s[:affiliation] then "#{s[:name]} (#{s[:affiliation]})" else s[:name] end } + data = {} + data[:title] = event[:title] + data[:date] = event[:startdate] + data[:speakers] = event[:speakers].map { |s| if s[:affiliation] then "#{s[:name]} (#{s[:affiliation]})" else s[:name] end } text = Nokogiri::HTML(event.compiled_content) - text = text.content.gsub(/\n+/,"\n") - location_name = [event[:location][:name]] + data[:text] = text.content.gsub(/\n+/,"\n") + data[:location_name] = [event[:location][:name]] if (event[:location][:details]) - location_name << event[:location][:details] + data[:location_name] << event[:location][:details] end - location_address = [] + data[:location_address] = [] if (event[:location][:strasse]) - location_address << event[:location][:strasse] + data[:location_address] << event[:location][:strasse] end if (event[:location][:ort]) if (event[:location][:plz]) - location_address << "#{event[:location][:plz]} #{event[:location][:ort]}" + data[:location_address] << "#{event[:location][:plz]} #{event[:location][:ort]}" else - location_address << event[:location][:ort] + data[:location_address] << event[:location][:ort] end end - location_geo = if (event[:location][:lon]) + data[:location_geo] = if (event[:location][:lon]) "N #{event[:location][:lon]} E #{event[:location][:lat]}" else "" @@ -81,40 +102,26 @@ class CreateFlyer < ::Nanoc::CLI::CommandRunner calendar_items = self.site.items.select do |i| (i[:kind]=='event') && (i[:startdate].to_datetime>event[:startdate].to_datetime) && !i.identifier.start_with?('/_data/stammtisch/') end.sort { |a,b| a[:startdate].to_datetime <=> b[:startdate].to_datetime } - calendar = calendar_items[0..5].map do |i| + data[:calendar] = calendar_items[0..5].map do |i| if i[:startdate].instance_of?(Date) "#{i[:startdate].strftime("%d.%m.%Y")}: #{i[:title]}" else "#{i[:startdate].strftime("%d.%m.%Y, %H:%M")}h: #{i[:title]}" end end + # Generate qr code 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 << "LOCATION:#{data[: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 - file.close() - # Replace in template - template.gsub!('${title}', title) - template.gsub!('${date}', date.strftime("%d.%m.%Y, %H:%M")) - template.gsub!('${speakers}', speakers.join(', ')) - 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 - # Output - File.open("#{arguments[1]}/aushang.svg", 'w:UTF-8') {|f| f.write(template) } + data[:qr_img] = get_qr(vevent.join("\n")).to_img + # Write svgs + create_svg(self.site.items['/_data/aushang/'].raw_filename(), "#{arguments[1]}/aushang.svg", data) + create_svg(self.site.items['/_data/flyer/'].raw_filename(), "#{arguments[1]}/flyer.svg", data) end end diff --git a/content/_data/flyer.svg b/content/_data/flyer.svg new file mode 100644 index 00000000..899f5f0a --- /dev/null +++ b/content/_data/flyer.svg @@ -0,0 +1,318 @@ + + + +image/svg+xmlDer Chaos-Computer-Club Stuttgart und die Stadtbibliothek am Mailänder Platz präsentieren:Vortragsreihe des CCCS +VeranstalterChaos-Computer-Club Stuttgartwww.cccs.deV.i.S.d.P.: Hanno WagnerNeckarstraße 168b70190 Stuttgart${date}${speakers}: ${title}Ort${location.name}${location.address}${location.geo}Eintritt frei, um einen freiwilligen Unkostenbeitrag wird gebeten.Weitere Termine${calendar.0}${calendar.1}${calendar.2}${calendar.3}${calendar.4}${calendar.5}