zeus.ugent.be/lib/helpers/ical.rb

26 lines
674 B
Ruby
Raw Normal View History

2016-07-26 22:13:36 +00:00
module IcalHelper
def event_calendar
cal = Icalendar::Calendar.new
2020-01-13 13:34:12 +00:00
items.find_all('/events/*/*.md')
.select { |x| x[:soon] == nil }
.each {|i| cal.add_event(event_for(i)) }
2016-07-26 22:13:36 +00:00
cal.to_ical
end
2016-08-23 18:21:02 +00:00
def event_for(item)
2017-02-08 16:44:20 +00:00
tzid = 'Europe/Brussels'
2017-02-08 16:05:48 +00:00
e = Icalendar::Event.new
2017-02-08 16:44:20 +00:00
e.dtstart = Icalendar::Values::DateTime.new item[:time], 'tzid' => tzid
e.dtend = Icalendar::Values::DateTime.new item[:end], 'tzid' => tzid if item[:end]
2017-02-08 16:05:48 +00:00
e.summary = item[:title]
2017-10-03 12:07:39 +00:00
e.description = "#{item[:description]}\n\n#{item.reps[:text].compiled_content}"
2017-02-08 16:05:48 +00:00
e.location = item[:location]
e.url = @config[:base_url] + item.path
2016-07-26 22:13:36 +00:00
2017-02-08 16:05:48 +00:00
e
2016-07-26 22:13:36 +00:00
end
end