Add page titles

This commit is contained in:
Shadowfacts 2021-08-28 11:58:22 -04:00
parent 5c8baa2057
commit 71a23faa90
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
9 changed files with 84 additions and 2 deletions

View File

@ -3,6 +3,10 @@ defmodule FrenzyWeb.EditPipelineLive do
use Phoenix.HTML use Phoenix.HTML
alias Frenzy.{Repo, Pipeline} alias Frenzy.{Repo, Pipeline}
def title(%{pipeline: %Pipeline{name: name}}) do
"Edit #{name}"
end
@stages [ @stages [
{"Filter Stage", "Frenzy.Pipeline.FilterStage"}, {"Filter Stage", "Frenzy.Pipeline.FilterStage"},
{"Scrape Stage", "Frenzy.Pipeline.ScrapeStage"}, {"Scrape Stage", "Frenzy.Pipeline.ScrapeStage"},

View File

@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<title>Frenzy</title> <title><%= title(assigns) %></title>
<%= csrf_meta_tag() %> <%= csrf_meta_tag() %>

View File

@ -1,3 +1,7 @@
defmodule FrenzyWeb.AccountView do defmodule FrenzyWeb.AccountView do
use FrenzyWeb, :view use FrenzyWeb, :view
def title(:show, _) do
"Account Settings"
end
end end

View File

@ -10,4 +10,12 @@ defmodule FrenzyWeb.FeedView do
def feed_site_url(%Feed{feed_url: feed_url}) do def feed_site_url(%Feed{feed_url: feed_url}) do
URI.merge(feed_url, "/") |> to_string() URI.merge(feed_url, "/") |> to_string()
end end
def title(:show, %{feed: %Feed{title: title}}) do
title
end
def title(:edit, %{feed: %Feed{title: title}}) do
"Edit #{title}"
end
end end

View File

@ -1,3 +1,19 @@
defmodule FrenzyWeb.GroupView do defmodule FrenzyWeb.GroupView do
use FrenzyWeb, :view use FrenzyWeb, :view
def title(:index, _) do
"Groups"
end
def title(:show, %{group: %Frenzy.Group{title: title}}) do
title
end
def title(:edit, %{group: %Frenzy.Group{title: title}}) do
"Edit #{title}"
end
def title(:read, %{group: %Frenzy.Group{title: title}}) do
"Read #{title}"
end
end end

View File

@ -1,3 +1,7 @@
defmodule FrenzyWeb.ItemView do defmodule FrenzyWeb.ItemView do
use FrenzyWeb, :view use FrenzyWeb, :view
def title(:show, %{item: %Frenzy.Item{title: title}, feed: %Frenzy.Feed{title: feed}}) do
"#{title} | #{feed}"
end
end end

View File

@ -6,4 +6,30 @@ defmodule FrenzyWeb.LayoutView do
def user_groups(user) do def user_groups(user) do
Repo.all(from g in Group, where: g.user_id == ^user.id, preload: [:feeds]) Repo.all(from g in Group, where: g.user_id == ^user.id, preload: [:feeds])
end end
def title(%{live_module: module} = assigns) do
try do
"#{module.title(assigns)} | Frenzy"
rescue
_ ->
"Frenzy"
end
end
def title(assigns) do
vm = Phoenix.Controller.view_module(assigns[:conn])
if function_exported?(vm, :title, 2) do
action = Phoenix.Controller.action_name(assigns[:conn])
try do
"#{vm.title(action, assigns)} | Frenzy"
rescue
_ ->
"Frenzy"
end
else
"Frenzy"
end
end
end end

View File

@ -1,3 +1,7 @@
defmodule FrenzyWeb.LoginView do defmodule FrenzyWeb.LoginView do
use FrenzyWeb, :view use FrenzyWeb, :view
def title(_, _) do
"Login"
end
end end

View File

@ -1,3 +1,19 @@
defmodule FrenzyWeb.PipelineView do defmodule FrenzyWeb.PipelineView do
use FrenzyWeb, :view use FrenzyWeb, :view
def title(:index, _) do
"Pipelines"
end
def title(:new, _) do
"Add Pipeline"
end
def title(:show, %{pipeline: %Frenzy.Pipeline{name: name}}) do
name
end
def title(:edit, %{pipeline: %Frenzy.Pipeline{name: name}}) do
"Edit #{name}"
end
end end