Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make schedule available in iCal-format

  • Loading branch information...
commit 0c4919f1bfc8027c096ec83076db2f2af86b5c0a 1 parent 313493c
@kronn kronn authored
View
2  Gemfile
@@ -27,3 +27,5 @@ gem 'heroku_san', '3.0.2'
gem 'rack-contrib'
gem 'rack-rewrite'
+
+gem 'icalendar'
View
2  Gemfile.lock
@@ -57,6 +57,7 @@ GEM
rack (>= 1.0.0)
url_mount (~> 0.2.1)
i18n (0.6.0)
+ icalendar (1.1.6)
launchy (2.1.0)
addressable (~> 2.2.6)
listen (0.4.7)
@@ -165,6 +166,7 @@ DEPENDENCIES
heroku (= 2.26.6)
heroku_san (= 3.0.2)
html5-boilerplate!
+ icalendar
middleman (~> 3.0.0)
middleman-blog (~> 3.0.0)
nokogiri
View
2  config.rb
@@ -3,6 +3,7 @@
require 'active_support/core_ext/string'
require 'app/helpers/html5_boilerplate_helper'
+require 'icalendar'
set :markdown_engine, :redcarpet
@@ -49,6 +50,7 @@ def published?
end
page "/feed.xml", :layout => false
+page "/schedule.ics", :layout => false
###
# Compass
View
23 lib/custom_tag_helpers.rb
@@ -85,6 +85,29 @@ def nav(items, attrs = {})
end
end
+ def ics_schedule_for(items, options, &block)
+ schedule_start = Time.utc 2012, options[:month], options[:day], options[:start], 0, 0
+
+ first_start_h, first_start_min = items.first.start.to_s.split('.')
+ first_start_time = Time.utc 2012, options[:month], options[:day], first_start_h, first_start_min, 0
+
+ items.each_with_index do |item, index|
+ start = item.start
+ stop = item.end || items[index + 1].start
+
+ start_h, start_min = start.to_s.split('.')
+ stop_h, stop_min = stop.to_s.split('.')
+
+ start_min = start_min.ljust(2, '0')
+ stop_min = stop_min.ljust(2, '0')
+
+ start_time = Time.utc 2012, options[:month], options[:day], start_h, start_min, 0
+ stop_time = Time.utc 2012, options[:month], options[:day], stop_h, stop_min, 0
+
+ yield item, start_time, stop_time
+ end
+ end
+
def schedule_for(items, options, &block)
schedule_start = Time.utc 2012, 1, 1, options[:start], 0, 0
View
24 source/schedule.ics.erb
@@ -0,0 +1,24 @@
+<%
+cal = Icalendar::Calendar.new
+event = lambda { |item, start, ending|
+ cal.event do
+ dtstart start.strftime('%Y%m%dT%H%M%S')
+ dtend ending.strftime('%Y%m%dT%H%M%S')
+ summary item.title
+ description "#{"%0.2f" % item.start}: #{item.speaker} / #{item.title}"
+ klass "PUBLIC"
+ end
+}
+
+%w(Friday Saturday Sunday).zip((17..19)).each do |(day, date)|
+ multi_track_sessions = data.schedule[day.downcase]["multi_track"] rescue false
+
+ if multi_track_sessions
+ multi_track_sessions.each do |track|
+ ics_schedule_for track.sessions, :start => 8, :day => date, :month => 8, &event
+ end
+ else
+ ics_schedule_for data.schedule[day.downcase], :start => 8, :day => date, :month => 8, &event
+ end
+end
+%><%= cal.to_ical.to_s %>
Please sign in to comment.
Something went wrong with that request. Please try again.