Building a view interface
In order to build a view interface, let’s first start with the example_server_html_eex
app that we built in the previous chapter. In this app, we made the controller module responsible for both capturing a request from a router and rendering the final HTML. In this section, we will start by moving the rendering responsibility to Goldcrest.View
.
We can start by defining the Goldcrest.View
module that can house the render/3
function, which evaluates the EEx
template and calls the render
function in the Goldcrest.Controller
module.
Let’s create a new file in the goldcrest
package:
lib/goldcrest/view.ex
defmodule Goldcrest.View do require EEx alias Goldcrest.Controller def render(conn, file, assigns) do contents = file |> html_file_path() |> EEx.eval_file(assigns...