Last active
December 20, 2015 15:09
-
-
Save hoffmanc/6152405 to your computer and use it in GitHub Desktop.
Hand rolled ICS support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# locales/en.yml | |
en: | |
time: | |
formats: | |
ical: "%Y%m%dT%H%M%SZ" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/ics.rb | |
ActionView::Template.register_template_handler(:rb, :source.to_proc) | |
Mime::Type.register_alias "text/calendar", :ics |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#... | |
def index | |
format.ics | |
end | |
#... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You'll need to be mindful of timezone.