summaryrefslogtreecommitdiff
path: root/lib/nola_web/views
diff options
context:
space:
mode:
authorJordan Bracco <href@random.sh>2022-12-20 00:21:54 +0000
committerJordan Bracco <href@random.sh>2022-12-20 19:29:41 +0100
commit2d83df8b32bff7f0028923bb5b64dc0b55f20d03 (patch)
tree1207e67b5b15f540963db05e7be89f3ca950e724 /lib/nola_web/views
parentNola rename, the end. pt 6. Refs T77. (diff)
Nola rename: The Big Move, Refs T77
Diffstat (limited to 'lib/nola_web/views')
-rw-r--r--lib/nola_web/views/alcoolog_view.ex6
-rw-r--r--lib/nola_web/views/error_helpers.ex40
-rw-r--r--lib/nola_web/views/error_view.ex17
-rw-r--r--lib/nola_web/views/irc_view.ex3
-rw-r--r--lib/nola_web/views/layout_view.ex81
-rw-r--r--lib/nola_web/views/network_view.ex4
-rw-r--r--lib/nola_web/views/open_id_view.ex4
-rw-r--r--lib/nola_web/views/page_view.ex3
8 files changed, 158 insertions, 0 deletions
diff --git a/lib/nola_web/views/alcoolog_view.ex b/lib/nola_web/views/alcoolog_view.ex
new file mode 100644
index 0000000..ad52472
--- /dev/null
+++ b/lib/nola_web/views/alcoolog_view.ex
@@ -0,0 +1,6 @@
+defmodule NolaWeb.AlcoologView do
+ use NolaWeb, :view
+ require Integer
+
+end
+
diff --git a/lib/nola_web/views/error_helpers.ex b/lib/nola_web/views/error_helpers.ex
new file mode 100644
index 0000000..25214bd
--- /dev/null
+++ b/lib/nola_web/views/error_helpers.ex
@@ -0,0 +1,40 @@
+defmodule NolaWeb.ErrorHelpers do
+ @moduledoc """
+ Conveniences for translating and building error messages.
+ """
+
+ use Phoenix.HTML
+
+ @doc """
+ Generates tag for inlined form input errors.
+ """
+ def error_tag(form, field) do
+ Enum.map(Keyword.get_values(form.errors, field), fn (error) ->
+ content_tag :span, translate_error(error), class: "help-block"
+ end)
+ end
+
+ @doc """
+ Translates an error message using gettext.
+ """
+ def translate_error({msg, opts}) do
+ # Because error messages were defined within Ecto, we must
+ # call the Gettext module passing our Gettext backend. We
+ # also use the "errors" domain as translations are placed
+ # in the errors.po file.
+ # Ecto will pass the :count keyword if the error message is
+ # meant to be pluralized.
+ # On your own code and templates, depending on whether you
+ # need the message to be pluralized or not, this could be
+ # written simply as:
+ #
+ # dngettext "errors", "1 file", "%{count} files", count
+ # dgettext "errors", "is invalid"
+ #
+ if count = opts[:count] do
+ Gettext.dngettext(NolaWeb.Gettext, "errors", msg, msg, count, opts)
+ else
+ Gettext.dgettext(NolaWeb.Gettext, "errors", msg, opts)
+ end
+ end
+end
diff --git a/lib/nola_web/views/error_view.ex b/lib/nola_web/views/error_view.ex
new file mode 100644
index 0000000..5cad939
--- /dev/null
+++ b/lib/nola_web/views/error_view.ex
@@ -0,0 +1,17 @@
+defmodule NolaWeb.ErrorView do
+ use NolaWeb, :view
+
+ def render("404.html", _assigns) do
+ "Page not found"
+ end
+
+ def render("500.html", _assigns) do
+ "Internal server error"
+ end
+
+ # In case no render clause matches or no
+ # template is found, let's render it as 500
+ def template_not_found(_template, assigns) do
+ render "500.html", assigns
+ end
+end
diff --git a/lib/nola_web/views/irc_view.ex b/lib/nola_web/views/irc_view.ex
new file mode 100644
index 0000000..331d91f
--- /dev/null
+++ b/lib/nola_web/views/irc_view.ex
@@ -0,0 +1,3 @@
+defmodule NolaWeb.IrcView do
+ use NolaWeb, :view
+end
diff --git a/lib/nola_web/views/layout_view.ex b/lib/nola_web/views/layout_view.ex
new file mode 100644
index 0000000..2bffc6f
--- /dev/null
+++ b/lib/nola_web/views/layout_view.ex
@@ -0,0 +1,81 @@
+defmodule NolaWeb.LayoutView do
+ use NolaWeb, :view
+
+ def liquid_markdown(conn, text) do
+ context_path = cond do
+ conn.assigns[:chan] -> "/#{conn.assigns[:network]}/#{NolaWeb.format_chan(conn.assigns[:chan])}"
+ conn.assigns[:network] -> "/#{conn.assigns[:network]}/-"
+ true -> "/-"
+ end
+
+ {:ok, ast} = Liquex.parse(text)
+ context = Liquex.Context.new(%{
+ "context_path" => context_path
+ })
+ {content, _} = Liquex.render(ast, context)
+ content
+ |> to_string()
+ |> Earmark.as_html!()
+ |> raw()
+ end
+
+ def page_title(conn) do
+ target = cond do
+ conn.assigns[:chan] ->
+ "#{conn.assigns.chan} @ #{conn.assigns.network}"
+ conn.assigns[:network] -> conn.assigns.network
+ true -> Keyword.get(Nola.name())
+ end
+
+ breadcrumb_title = Enum.map(Map.get(conn.assigns, :breadcrumbs)||[], fn({title, _href}) -> title end)
+
+ title = [conn.assigns[:title], breadcrumb_title, target]
+ |> List.flatten()
+ |> Enum.uniq()
+ |> Enum.filter(fn(x) -> x end)
+ |> Enum.intersperse(" / ")
+ |> Enum.join()
+
+ content_tag(:title, title)
+ end
+
+ def format_time(date, with_relative \\ true) do
+ alias Timex.Format.DateTime.Formatters
+ alias Timex.Timezone
+ date = if is_integer(date) do
+ date
+ |> DateTime.from_unix!(:millisecond)
+ |> DateTime.shift_zone!("Europe/Paris", Tzdata.TimeZoneDatabase)
+ else
+ date
+ |> DateTime.shift_zone!("Europe/Paris", Tzdata.TimeZoneDatabase)
+ end
+
+ now = DateTime.now!("Europe/Paris", Tzdata.TimeZoneDatabase)
+
+ now_week = Timex.iso_week(now)
+ date_week = Timex.iso_week(date)
+
+ {y, w} = now_week
+ now_last_week = {y, w-1}
+ now_last_roll = 7-Timex.days_to_beginning_of_week(now)
+
+ date_date = DateTime.to_date(date)
+ now_date = DateTime.to_date(date)
+
+ format = cond do
+ date.year != now.year -> "{D}/{M}/{YYYY} {h24}:{m}"
+ date_date == now_date -> "{h24}:{m}"
+ (now_week == date_week) || (date_week == now_last_week && (Date.day_of_week(date) >= now_last_roll)) -> "{WDfull} {h24}:{m}"
+ (now.year == date.year && now.month == date.month) -> "{WDfull} {D} {h24}:{m}"
+ true -> "{WDfull} {D} {M} {h24}:{m}"
+ end
+
+ {:ok, relative} = Formatters.Relative.relative_to(date, Timex.now("Europe/Paris"), "{relative}", "fr")
+ {:ok, full} = Formatters.Default.lformat(date, "{WDfull} {D} {YYYY} {h24}:{m}", "fr") #"{h24}:{m} {WDfull} {D}", "fr")
+ {:ok, detail} = Formatters.Default.lformat(date, format, "fr") #"{h24}:{m} {WDfull} {D}", "fr")
+
+ content_tag(:time, if(with_relative, do: relative, else: detail), [title: full])
+ end
+
+end
diff --git a/lib/nola_web/views/network_view.ex b/lib/nola_web/views/network_view.ex
new file mode 100644
index 0000000..7a24db1
--- /dev/null
+++ b/lib/nola_web/views/network_view.ex
@@ -0,0 +1,4 @@
+defmodule NolaWeb.NetworkView do
+ use NolaWeb, :view
+
+end
diff --git a/lib/nola_web/views/open_id_view.ex b/lib/nola_web/views/open_id_view.ex
new file mode 100644
index 0000000..bd8089b
--- /dev/null
+++ b/lib/nola_web/views/open_id_view.ex
@@ -0,0 +1,4 @@
+defmodule NolaWeb.OpenIdView do
+ use NolaWeb, :view
+
+end
diff --git a/lib/nola_web/views/page_view.ex b/lib/nola_web/views/page_view.ex
new file mode 100644
index 0000000..1bfaadd
--- /dev/null
+++ b/lib/nola_web/views/page_view.ex
@@ -0,0 +1,3 @@
+defmodule NolaWeb.PageView do
+ use NolaWeb, :view
+end