Closed pinx closed 6 years ago
This could be an additional package, but I don't want to have any support for Phoenix or any other library built in.
Once you have icalendar in your Phoenix app, It's really simple to implement returning ics. Not sure it requires anything more than addition to README under Usage.
Note I use the same pipeline as html and detect format rather than create a separate pipeline which has been overkill for my case.
# lib/your_app_web/router.ex
pipeline :browser do
plug :accepts, ["html", "ics"]
...
# corresponding controller action needs to use symbol for action in render call
# so that corresponding template for format is matched against `action.ics.eex`
def show(conn, %{"id" => id}) do
...
render(conn, :show, ...)
end
# you can then have an ics template, but doesn't make much sense
# so I use pattern matching to override the ics case in the corresponding view
def render("show.ics", %{conn: conn, ...}) do
event = %ICalendar.Event{...}
%ICalendar{events: [event]} |> ICalendar.to_ics |> String.replace(~r/\n/, "\r\n")
end
I experimented a bit, and made a PR to describe what it could look like: #22
After seeing the PR I think this would be a good addition. Thanks :)
I've released a new version with this new feature
I experimented a bit, and made a PR to describe what it could look like: #22
Yeah, small change that makes it even cleaner. Good work.
To create an ics feed, we could hook into https://hexdocs.pm/phoenix/views.html. Maybe the trick is to define a
format_encoder
for ics? https://hexdocs.pm/phoenix/Phoenix.Template.html#module-format-encoders