summaryrefslogtreecommitdiff
path: root/lib/lsg_web/views
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lsg_web/views')
-rw-r--r--lib/lsg_web/views/layout_view.ex66
-rw-r--r--lib/lsg_web/views/network_view.ex4
2 files changed, 66 insertions, 4 deletions
diff --git a/lib/lsg_web/views/layout_view.ex b/lib/lsg_web/views/layout_view.ex
index 956d703..b28d3c5 100644
--- a/lib/lsg_web/views/layout_view.ex
+++ b/lib/lsg_web/views/layout_view.ex
@@ -1,20 +1,78 @@
defmodule LSGWeb.LayoutView do
use LSGWeb, :view
-
+
+ def liquid_markdown(conn, text) do
+ context_path = cond do
+ conn.assigns[:chan] -> "/#{conn.assigns[:network]}/#{LSGWeb.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(Application.get_env(:lsg, :irc), :name, "ircbot")
+ 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)
- |> Timezone.convert("Europe/Paris")
+ |> 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)
+
+ format = cond do
+ date.year != now.year -> "{D}/{M}/{YYYY} {h24}:{m}"
+ date.day == now.day -> "{h24}:{m}"
+ (now_week == date_week) || (date_week == now_last_week && (Date.day_of_week(date) >= now_last_roll)) -> "{WDfull} {h24}:{m}"
+ (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, detail} = Formatters.Default.lformat(date, "{D}/{M}/{YYYY} {h24}:{m}", "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: detail])
+ content_tag(:time, if(with_relative, do: relative, else: detail), [title: full])
end
end
diff --git a/lib/lsg_web/views/network_view.ex b/lib/lsg_web/views/network_view.ex
new file mode 100644
index 0000000..c369ce6
--- /dev/null
+++ b/lib/lsg_web/views/network_view.ex
@@ -0,0 +1,4 @@
+defmodule LSGWeb.NetworkView do
+ use LSGWeb, :view
+
+end