Skip to content

Instantly share code, notes, and snippets.

@hoffmanc
Last active December 20, 2015 15:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoffmanc/6152405 to your computer and use it in GitHub Desktop.
Save hoffmanc/6152405 to your computer and use it in GitHub Desktop.
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
Copy link
Author

hoffmanc commented Aug 4, 2013

You'll need to be mindful of timezone.

@rapcal
Copy link

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