Building the View DSL
Let’s first start by understanding what our view modules should look like. Let’s take a look at the following view module:
defmodule TasksWeb.TaskView do use Goldcrest.View def stringify_task(_task = {name, description}) do "#{name} - #{description}" end end
In the preceding module, we have defined a helper function that converts a task to a string, which can be further used in a template as shown in the following code snippet:
<h1>Listing Tasks</h1> <table> <thead> <tr> <th>Task</th> <th></th> </tr> </thead> <tbody> <%= for {task, index} <- Enum.with_index(@tasks) do %> <tr> ...