Skip to content

Commit b3e9db6

Browse files
committed
add phoenix hook for rendering xls templates
1 parent 6f5608a commit b3e9db6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/excelerator/phoenix.ex

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
defmodule Excelerator.Phoenix do
2+
defmacro __using__(options) do
3+
quote do
4+
def xls(conn, template, data, opts \\ []) do
5+
excel_data = view_module(conn).render(template, data)
6+
7+
default_filename = Phoenix.Naming.resource_name(__MODULE__, "Controller") <> ".xls"
8+
filename = Keyword.get(opts, :filename, default_filename)
9+
10+
conn
11+
|> put_resp_content_type("application/vnd.ms-excel")
12+
|> put_resp_header("content-disposition", "attachment; filename=#{ filename }")
13+
|> send_resp(conn.status || 200, excel_data)
14+
end
15+
end
16+
end
17+
end

0 commit comments

Comments
 (0)