diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lsg_irc/txt_plugin.ex | 10 | ||||
-rw-r--r-- | lib/lsg_web/controllers/irc_controller.ex | 34 | ||||
-rw-r--r-- | lib/lsg_web/templates/irc/txts.html.eex | 29 |
3 files changed, 51 insertions, 22 deletions
diff --git a/lib/lsg_irc/txt_plugin.ex b/lib/lsg_irc/txt_plugin.ex index 93c4bb1..2c9dfca 100644 --- a/lib/lsg_irc/txt_plugin.ex +++ b/lib/lsg_irc/txt_plugin.ex @@ -168,9 +168,13 @@ defmodule LSG.IRC.TxtPlugin do result = with_stateful_results(msg, {:bang,"txt",msg.network,msg.channel,grep}, fn() -> Enum.reduce(state.triggers, [], fn({trigger, data}, acc) -> - Enum.reduce(data, acc, fn({l, _}, acc) -> - [{trigger, l} | acc] - end) + if !String.contains?(trigger, ".") do + Enum.reduce(data, acc, fn({l, _}, acc) -> + [{trigger, l} | acc] + end) + else + acc + end end) |> Enum.filter(fn({_, line}) -> line diff --git a/lib/lsg_web/controllers/irc_controller.ex b/lib/lsg_web/controllers/irc_controller.ex index 317bb27..9ddeefc 100644 --- a/lib/lsg_web/controllers/irc_controller.ex +++ b/lib/lsg_web/controllers/irc_controller.ex @@ -19,19 +19,19 @@ defmodule LSGWeb.IrcController do end def txt(conn, %{"name" => name}) do - case String.split(name, ".", parts: 2) do - [name, "txt"] -> - data = data() - if Map.has_key?(data, name) do - lines = Enum.join(data[name], "\n") - text(conn, lines) - else - conn - |> put_status(404) - |> text("Not found") - end - _ -> - do_txt(conn, name) + if String.contains?(name, ".txt") do + name = String.replace(name, ".txt", "") + data = data() + if Map.has_key?(data, name) do + lines = Enum.join(data[name], "\n") + text(conn, lines) + else + conn + |> put_status(404) + |> text("Not found") + end + else + do_txt(conn, name) end end def txt(conn, _), do: do_txt(conn, nil) @@ -40,10 +40,12 @@ defmodule LSGWeb.IrcController do defp do_txt(conn, nil) do doc = LSG.IRC.TxtPlugin.irc_doc() data = data() - lines = Enum.reduce(data, 0, fn({_, lines}, acc) -> acc + Enum.count(lines) end) + main = Enum.filter(data, fn({trigger, _}) -> !String.contains?(trigger, ".") end) |> Enum.into(Map.new) + system = Enum.filter(data, fn({trigger, _}) -> String.contains?(trigger, ".") end) |> Enum.into(Map.new) + lines = Enum.reduce(main, 0, fn({_, lines}, acc) -> acc + Enum.count(lines) end) conn |> assign(:title, "txt") - |> render("txts.html", data: data, doc: doc, files: Enum.count(data), lines: lines) + |> render("txts.html", data: main, doc: doc, files: Enum.count(main), lines: lines, system: system) end defp do_txt(conn, txt) do @@ -75,7 +77,7 @@ defmodule LSGWeb.IrcController do |> Enum.reduce(%{}, fn(path, m) -> path = String.split(path, "/") file = List.last(path) - [key, "txt"] = String.split(file, ".", parts: 2) + key = String.replace(file, ".txt", "") data = dir <> file |> File.read! |> String.split("\n") diff --git a/lib/lsg_web/templates/irc/txts.html.eex b/lib/lsg_web/templates/irc/txts.html.eex index 66321b5..68d35f5 100644 --- a/lib/lsg_web/templates/irc/txts.html.eex +++ b/lib/lsg_web/templates/irc/txts.html.eex @@ -1,8 +1,8 @@ <div> <h2 class="text-gray-500 text-xs font-medium uppercase tracking-wide"> <strong><%= @lines %></strong> lignes dans <strong><%= @files %></strong> fichiers - — - <a href="#help">Aide</a> + <a href="#help" class="ml-4 font-bold">Aide</a> + <a href="#system" class="text-gray-300 ml-4">Fichiers système</a> </h2> <ul class="mt-3 grid grid-cols-1 gap-5 sm:gap-6 sm:grid-cols-4 lg:grid-cols-6"> <%= for {txt, data} <- @data do %> @@ -22,5 +22,28 @@ </ul> </div> -<div class="prose" id="help"><%= LSGWeb.LayoutView.liquid_markdown(@conn, @doc) %></div> +<div class="prose mt-12" id="help""><%= LSGWeb.LayoutView.liquid_markdown(@conn, @doc) %></div> +<div class="mt-24"> + <h2 class="text-gray-500 text-xs font-medium uppercase tracking-wide"> + Fichiers système + </h2> + + <ul class="mt-3 grid grid-cols-1 gap-5 sm:gap-6 sm:grid-cols-4 lg:grid-cols-6"> + <%= for {txt, data} <- @system do %> + <% base_url = cond do + @conn.assigns[:chan] -> "/#{@conn.assigns.network}/#{LSGWeb.format_chan(@conn.assigns.chan)}" + true -> "/-" + end %> + <li class="col-span-1 flex shadow-sm rounded-m"> + <div class="flex-1 flex items-center justify-between border-l border-t border-r border-b border-gray-200 bg-white rounded-md truncate"> + <div class="flex-1 px-4 py-2 text-sm leading-5 truncate"> + <a href="<%= base_url %>/txt/<%= txt %>" class="text-gray-900 text-lg font-medium hover:text-gray-600 transition ease-in-out duration-150"><%= txt %></a> + <p class="text-gray-500"><%= Enum.count(data) %> lignes</p> + </div> + </div> + </li> + <% end %> + </ul> + +</div> |