agenda-libre-ruby/app/views/events/index.ics.haml

43 lines
1.5 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

:ruby
require 'icalendar/tzinfo'
# Create a calendar with an event (standard method)
cal = Icalendar::Calendar.new
@events.each do |event|
tzid = event.region.tzid
use_timezone = true
if cal.timezones.none? { |t| tzid == t.tzid }
# Only add this zone once
begin
tz = TZInfo::Timezone.get tzid
timezone = tz.ical_timezone event.start_time
cal.add_timezone timezone
rescue TZInfo::InvalidTimezoneIdentifier
# No need to add this tz
use_timezone = false
end
end
cal.event do |e|
if use_timezone
e.dtstamp = Icalendar::Values::DateTime.new event.decision_time, tzid: tzid
e.dtstart = Icalendar::Values::DateTime.new event.start_time, tzid: tzid
e.dtend = Icalendar::Values::DateTime.new event.end_time, tzid: tzid
else
e.dtstamp = Icalendar::Values::DateTime.new event.decision_time.localtime
e.dtstart = Icalendar::Values::DateTime.new event.start_time.localtime
e.dtend = Icalendar::Values::DateTime.new event.end_time.localtime
end
e.uid = "#{event.id}@#{request.domain}"
e.summary = event.title
e.description = to_markdown event.description.tr '\'', ''
e.location = event.full_address.tr '\'', ''
e.organizer = "mailto:#{event.contact}"
e.x_alt_desc = Icalendar::Values::Text.new event.description, FMTTYPE: 'text/html'
end
end
cal.publish
= cal.to_ical