Skip to content

Instantly share code, notes, and snippets.

@hoffmanc

hoffmanc/en.yml

Last active Dec 20, 2015
Embed
What would you like to do?
Hand rolled ICS support
# locales/en.yml
en:
time:
formats:
ical: "%Y%m%dT%H%M%SZ"
# config/initializers/ics.rb
ActionView::Template.register_template_handler(:rb, :source.to_proc)
Mime::Type.register_alias "text/calendar", :ics
out = <<CAL
BEGIN:VCALENDAR
PRODID:-//I CAN HAZ COMPANY?//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
CAL
@appointments.each_with_index do |appt, idx|
out << <<CAL
BEGIN:VEVENT
DTSTART:#{l(appt.starts_at, format: :ical)}
DTEND:#{l(appt.ends_at, format: :ical)}
DTSTAMP:#{l(Time.now, format: :ical)}
UID:appointment#{appt.id}@#{request.host}
CREATED:#{l(appt.created_at, format: :ical)}
DESCRIPTION:#{appt.reason}
LAST-MODIFIED:#{l(appt.updated_at, format: :ical)}
LOCATION:
SEQUENCE:#{idx}
STATUS:#{appt.status_ical}
SUMMARY:#{appt.reason}
END:VEVENT
CAL
end
out << "END:VCALENDAR"
#...
def index
format.ics
end
#...
@hoffmanc

This comment has been minimized.

Copy link
Owner Author

@hoffmanc hoffmanc commented Aug 4, 2013

You'll need to be mindful of timezone.

@rapcal

This comment has been minimized.

Copy link

@rapcal rapcal commented May 31, 2014

Wonderful gist! Thanks a lot :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.