Browse Source

use settings

main
Inhji Y. 9 months ago
parent
commit
fbeb74ef9a
  1. 6
      lib/mirage/settings.ex
  2. 7
      lib/mirage_web/live/page_live.ex
  3. 4
      lib/mirage_web/live/page_live.html.leex
  4. 7
      lib/mirage_web/router.ex
  5. 2
      lib/mirage_web/templates/layout/_footer.html.eex

6
lib/mirage/settings.ex

@ -21,6 +21,12 @@ defmodule Mirage.Settings do
Repo.all(Setting)
end
def list_settings_as_map do
Repo.all(Setting)
|> Enum.map(fn s -> {String.to_atom(s.name), s.value} end)
|> Map.new()
end
@doc """
Gets a single setting.

7
lib/mirage_web/live/page_live.ex

@ -2,9 +2,8 @@ defmodule MirageWeb.PageLive do
use MirageWeb, :live_view
@impl true
def mount(_params, _session, socket) do
tagline = Mirage.Settings.get_setting_by_name!("user_tagline")
{:ok, assign(socket, tagline: tagline.value)}
def mount(params, session, socket) do
settings = Mirage.Settings.list_settings_as_map()
{:ok, assign(socket, _settings: settings)}
end
end

4
lib/mirage_web/live/page_live.html.leex

@ -1,6 +1,6 @@
<section class="hero">
<h1><%= gettext "Hello my name is %{name}!", name: "Inhji" %></h1>
<p><%= raw @tagline %></p>
<h1><%= raw @_settings.user_title %></h1>
<p><%= raw @_settings.user_tagline %></p>
</section>
<section class="grid">

7
lib/mirage_web/router.ex

@ -3,9 +3,16 @@ defmodule MirageWeb.Router do
import MirageWeb.UserAuth
def fetch_settings(conn, _opts) do
settings = Mirage.Settings.list_settings_as_map()
IO.inspect(settings)
assign(conn, :_settings, settings)
end
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_settings
plug :fetch_live_flash
plug :put_root_layout, {MirageWeb.LayoutView, :root}
plug :protect_from_forgery

2
lib/mirage_web/templates/layout/_footer.html.eex

@ -1,3 +1,3 @@
<footer>
2020 was a fucking crazy time
<%= raw @_settings.footer_text %>
</footer>
Loading…
Cancel
Save