3.3 KiB
Controller for static <%= @project_name_camel_case %>Web pages
phx.new
ships a default PageController
with a static welcome page on it, I usually just re-use this for my landing page content.
The controller is instantiated by the Router and calls are dispatched to functions within.
It uses the helpers from <%= @project_name_camel_case %>Web.
defmodule <%= @project_name_camel_case %>Web.PageController do
use <%= @project_name_camel_case %>Web, :controller
def index(conn, _params) do
render(conn, "index.html")
end
end
Index via GET /
def index(conn, _params) do
render(conn, "index.html")
end
View
This is a pretty simple module, it's mostly just going to dispatch to the template
defmodule <%= @project_name_camel_case %>Web.PageView do
use <%= @project_name_camel_case %>Web, :view
end
defmodule <%= @project_name_camel_case %>Web.PageViewTest do
use <%= @project_name_camel_case %>Web.ConnCase, async: true
end
Template
This is the default template. Someday I'll have something more interesting to say!
<section class="phx-hero">
<h1><%%= gettext "Welcome to %{name}!", name: "Phoenix" %></h1>
<p>A productive web framework that<br/>does not compromise speed or maintainability.</p>
</section>
<section class="row">
<article class="column">
<h2>Resources</h2>
<ul>
<li>
<a href="https://hexdocs.pm/phoenix/overview.html">Guides & Docs</a>
</li>
<li>
<a href="https://github.com/phoenixframework/phoenix">Source</a>
</li>
<li>
<a href="https://github.com/phoenixframework/phoenix/blob/v1.4/CHANGELOG.md">v1.4 Changelog</a>
</li>
</ul>
</article>
<article class="column">
<h2>Help</h2>
<ul>
<li>
<a href="https://elixirforum.com/c/phoenix-forum">Forum</a>
</li>
<li>
<a href="https://webchat.freenode.net/?channels=elixir-lang">#elixir-lang on Freenode IRC</a>
</li>
<li>
<a href="https://twitter.com/elixirphoenix">Twitter @elixirphoenix</a>
</li>
</ul>
</article>
</section>
Tests
This is the default test, it's important for me to explain test well, I have the power of text and interlinking and I want to show that I can tell compelling stories with this programming methodology. These tests could and should be interspersed in the functionality itself.
defmodule <%= @project_name_camel_case %>Web.PageControllerTest do
use <%= @project_name_camel_case %>Web.ConnCase
test "GET /", %{conn: conn} do
conn = get(conn, "/")
assert html_response(conn, 200) =~ "Welcome to Phoenix!"
end
end