@@ -17,27 +17,26 @@ defmodule EpochtalkServerWeb do
1717 and import those modules here.
1818 """
1919
20+ def static_paths , do: ~w( assets fonts images favicon.ico robots.txt)
21+
2022 def controller do
2123 quote do
22- use Phoenix.Controller , namespace: EpochtalkServerWeb
24+ use Phoenix.Controller ,
25+ formats: [ :html , :json , :js ] ,
26+ layouts: [ html: EpochtalkServerWeb.Layouts ]
2327
2428 import Plug.Conn
25- alias EpochtalkServerWeb.Router.Helpers , as: Routes
29+
30+ unquote ( verified_routes ( ) )
2631 end
2732 end
2833
29- def view do
34+ def js do
3035 quote do
31- use Phoenix.View ,
32- root: "lib/epochtalk_server_web/templates" ,
33- namespace: EpochtalkServerWeb
34-
35- # Import convenience functions from controllers
36- import Phoenix.Controller ,
37- only: [ get_flash: 1 , get_flash: 2 , view_module: 1 , view_template: 1 ]
36+ import EpochtalkServerWeb , only: [ embed_templates: 2 ]
3837
39- # Include shared imports and aliases for views
40- unquote ( view_helpers ( ) )
38+ # Routes generation with the ~p sigil
39+ unquote ( verified_routes ( ) )
4140 end
4241 end
4342
@@ -56,13 +55,12 @@ defmodule EpochtalkServerWeb do
5655 end
5756 end
5857
59- defp view_helpers do
58+ def verified_routes do
6059 quote do
61- # Import basic rendering functionality (render, render_layout, etc)
62- import Phoenix.View
63-
64- import EpochtalkServerWeb.ErrorHelpers
65- alias EpochtalkServerWeb.Router.Helpers , as: Routes
60+ use Phoenix.VerifiedRoutes ,
61+ endpoint: EpochtalkServerWeb.Endpoint ,
62+ router: EpochtalkServerWeb.Router ,
63+ statics: EpochtalkServerWeb . static_paths ( )
6664 end
6765 end
6866
@@ -72,4 +70,16 @@ defmodule EpochtalkServerWeb do
7270 defmacro __using__ ( which ) when is_atom ( which ) do
7371 apply ( __MODULE__ , which , [ ] )
7472 end
73+
74+ defmacro embed_templates ( pattern , opts ) do
75+ quote do
76+ require Phoenix.Template
77+
78+ Phoenix.Template . compile_all (
79+ & ( & 1 |> Path . basename ( ) |> Path . rootname ( ) |> Path . rootname ( ) ) ,
80+ Path . expand ( unquote ( opts ) [ :root ] || __DIR__ , __DIR__ ) ,
81+ unquote ( pattern ) <> unquote ( opts ) [ :ext ]
82+ )
83+ end
84+ end
7585end
0 commit comments