Skip to content
This repository has been archived by the owner on Mar 10, 2021. It is now read-only.

Fix View.content and View.global_content when options are passed #157

Merged
merged 1 commit into from
Jan 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/thesis/view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,22 @@ defmodule Thesis.View do
<p>Default description</p>
<p>Another paragraph</p>
<% end %>
<%= content(@conn, "Description", :html, classes: "more classes") do %>
<p>Default description</p>
<% end %>
"""
@spec content(Plug.Conn.t, String.t, String.t, list) :: String.t | {:safe, String.t}
def content(conn, name, type, opts \\ [do: ""]) do
page = current_page(conn)
render_content(conn, page.id, name, type, opts)
end

@spec content(Plug.Conn.t, String.t, String.t, list, list) :: String.t | {:safe, String.t}
def content(conn, name, type, opts, [do: block]) do
page = current_page(conn)
render_content(conn, page.id, name, type, Keyword.put(opts, :do, block))
end

@doc """
Creates a globally editable content area in an eex template. Returns HTML-safe
string if type is `:html` or just a string if `:text`.
Expand All @@ -58,13 +67,22 @@ defmodule Thesis.View do
<p>Default description</p>
<p>Another paragraph</p>
<% end %>
<%= global_content(@conn, "Description", :html, classes: "more classes") do %>
<p>Default description</p>
<% end %>
"""
@spec global_content(Plug.Conn.t, String.t, String.t, list) :: String.t | {:safe, String.t}
def global_content(conn, name, type, opts \\ [do: ""]) do
opts = Keyword.put(opts, :global, true)
render_content(conn, nil, name, type, opts)
end

@spec global_content(Plug.Conn.t, String.t, String.t, list, list) :: String.t | {:safe, String.t}
def global_content(conn, name, type, opts, [do: block]) do
opts = Keyword.put(opts, :global, true)
render_content(conn, nil, name, type, Keyword.put(opts, :do, block))
end

defp render_content(conn, page_id, name, type, opts) do
all_content = conn.assigns[:thesis_content]
if all_content do
Expand Down