thesis v0.3.4 Thesis.View

Provides several view helper functions, including the primary content/4 function. Look at individual function documentation to learn more about them.

Typically, you'll add this to your web/web.ex file, under the view function:

def view do
  quote do
    use Thesis.View
    # ...
  end
end

If you'd prefer, you can remove it from web/web.ex and add it to your views yourself:

defmodule MyApp.MyView do
  use Thesis.View
  # ...

Link to this section Summary

Functions

Creates an editable content area in an eex template. Returns HTML-safe string if type is :html or just a string if :text

Returns the current page as a Thesis.Page{} struct

Creates a globally editable content area in an eex template. Returns HTML-safe string if type is :html or just a string if :text

Outputs the page title or a provided default

Outputs the page title or a provided default

Checks with the host app to see if the current page is editable by the current user, and then renders the editor, style tag, and bootstrap js

Link to this section Functions

Link to this function

content(conn, name, type, opts \\ [do: ""])
content(Plug.Conn.t(), String.t(), String.t(), list()) ::
  String.t() | {:safe, String.t()}

Creates an editable content area in an eex template. Returns HTML-safe string if type is :html or just a string if :text.

Examples

<%= content(@conn, "Title", :text, do: "Default Title") %>
<%= content(@conn, "Description", :html) do %>
  <p>Default description</p>
  <p>Another paragraph</p>
<% end %>
<%= content(@conn, "Description", :html, classes: "more classes") do %>
  <p>Default description</p>
<% end %>
Link to this function

content(conn, name, type, opts, list)
content(Plug.Conn.t(), String.t(), String.t(), list(), list()) ::
  String.t() | {:safe, String.t()}

Link to this function

current_page(conn)
current_page(Plug.Conn.t()) :: Thesis.Page.t()

Returns the current page as a Thesis.Page{} struct.

iex> Thesis.View.current_page(%Plug.Conn{request_path: "/test"})
%Thesis.Page{slug: "/test"}
Link to this function

global_content(conn, name, type, opts \\ [do: ""])
global_content(Plug.Conn.t(), String.t(), String.t(), list()) ::
  String.t() | {:safe, String.t()}

Creates a globally editable content area in an eex template. Returns HTML-safe string if type is :html or just a string if :text.

Examples

<%= global_content(@conn, "Title", :text, do: "Default Title") %>
<%= global_content(@conn, "Description", :html) do %>
  <p>Default description</p>
  <p>Another paragraph</p>
<% end %>
<%= global_content(@conn, "Description", :html, classes: "more classes") do %>
  <p>Default description</p>
<% end %>
Link to this function

global_content(conn, name, type, opts, list)
global_content(Plug.Conn.t(), String.t(), String.t(), list(), list()) ::
  String.t() | {:safe, String.t()}

Link to this function

page_description(conn, default)

Outputs the page title or a provided default.

Doctests:

iex> page = %Thesis.Page{description: "Test Description"}
iex> conn = %Plug.Conn{assigns: %{thesis_page: page}}
iex> Thesis.View.page_description(conn, "Default Description")
"Test Description"
iex> page = %Thesis.Page{}
iex> conn = %Plug.Conn{assigns: %{thesis_page: page}}
iex> Thesis.View.page_description(conn, "Default Description")
"Default Description"
Link to this function

page_title(conn, default)

Outputs the page title or a provided default.

Doctests:

iex> page = %Thesis.Page{title: "Test Title"}
iex> conn = %Plug.Conn{assigns: %{thesis_page: page}}
iex> Thesis.View.page_title(conn, "Default Title")
"Test Title"
iex> page = %Thesis.Page{}
iex> conn = %Plug.Conn{assigns: %{thesis_page: page}}
iex> Thesis.View.page_title(conn, "Default Title")
"Default Title"
Link to this function

thesis_editor(conn)
thesis_editor(Plug.Conn.t()) :: {:safe, String.t()}

Checks with the host app to see if the current page is editable by the current user, and then renders the editor, style tag, and bootstrap js.

If not editable, simply returns an empty string.

Doctests:

iex> {:safe, editor} = Thesis.View.thesis_editor(%Plug.Conn{assigns: %{thesis_editable: true}})
iex> String.contains?(editor, "/thesis/thesis.css")
true
iex> String.contains?(editor, "thesis-container")
true
iex> String.contains?(editor, "<script>")
true

iex> Thesis.View.thesis_editor(%Plug.Conn{assigns: %{thesis_editable: false}})
{:safe, ""}