From a28d24470ddeca6196219a1333c1ccac1319efef Mon Sep 17 00:00:00 2001 From: href Date: Wed, 11 Mar 2020 21:18:34 +0100 Subject: welp --- lib/lsg_web/controllers/irc_controller.ex | 27 +++++++++++++++++++----- lib/lsg_web/router.ex | 2 +- lib/lsg_web/templates/irc/index.html.eex | 35 ++++++++++++++++++++++++------- lib/lsg_web/templates/irc/txt.html.eex | 5 ++++- lib/lsg_web/templates/irc/txts.html.eex | 9 +++++--- lib/lsg_web/templates/page/index.html.eex | 2 +- 6 files changed, 62 insertions(+), 18 deletions(-) (limited to 'lib/lsg_web') diff --git a/lib/lsg_web/controllers/irc_controller.ex b/lib/lsg_web/controllers/irc_controller.ex index af7fff1..022807d 100644 --- a/lib/lsg_web/controllers/irc_controller.ex +++ b/lib/lsg_web/controllers/irc_controller.ex @@ -2,19 +2,35 @@ defmodule LSGWeb.IrcController do use LSGWeb, :controller def index(conn, _) do - doc = LSG.IRC.TxtHandler.irc_doc() commands = for mod <- (Application.get_env(:lsg, :irc)[:plugins] ++ Application.get_env(:lsg, :irc)[:handlers]) do - mod.irc_doc() + identifier = Module.split(mod) |> List.last |> String.replace("Plugin", "") |> Macro.underscore + {identifier, mod.irc_doc()} end - |> Enum.reject(fn(i) -> i == nil end) + |> Enum.reject(fn({_, i}) -> i == nil end) render conn, "index.html", commands: commands end - def txt(conn, %{"name" => name}), do: do_txt(conn, name) + 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) + end + end def txt(conn, _), do: do_txt(conn, nil) + defp do_txt(conn, nil) do - doc = LSG.IRC.TxtHandler.irc_doc() + doc = LSG.IRC.TxtPlugin.irc_doc() data = data() lines = Enum.reduce(data, 0, fn({_, lines}, acc) -> acc + Enum.count(lines) end) render conn, "txts.html", data: data, doc: doc, files: Enum.count(data), lines: lines @@ -27,6 +43,7 @@ defmodule LSGWeb.IrcController do else conn |> put_status(404) + |> text("Not found") end end diff --git a/lib/lsg_web/router.ex b/lib/lsg_web/router.ex index 9373e85..c47e422 100644 --- a/lib/lsg_web/router.ex +++ b/lib/lsg_web/router.ex @@ -2,7 +2,7 @@ defmodule LSGWeb.Router do use LSGWeb, :router pipeline :browser do - plug :accepts, ["html"] + plug :accepts, ["html", "txt"] #plug :fetch_session #plug :fetch_flash #plug :protect_from_forgery diff --git a/lib/lsg_web/templates/irc/index.html.eex b/lib/lsg_web/templates/irc/index.html.eex index c42d71f..f127101 100644 --- a/lib/lsg_web/templates/irc/index.html.eex +++ b/lib/lsg_web/templates/irc/index.html.eex @@ -4,18 +4,17 @@ h1 small { } -

- 115ans.net
-irc 115ans

+

<%= Keyword.get(Application.get_env(:lsg, :irc), :name, "ircbot") %>

-

+ +

+ <% list = for {identifier, _} <- @commands do %> + <% name = String.replace(identifier, "_", " ") %> + <%= link(name, to: "##{identifier}") #raw("#{name}") %> + <% end %> + <%= Enum.intersperse(list, " - ") %> +

+
- <%= for help <- @commands do %> -
<%= help |> Earmark.as_html! |> raw() %>
+ <%= for {identifier, help} <- @commands do %> + <%= if help do %> +
<%= help |> Earmark.as_html! |> raw() %>
+ <% end %> <% end %>
+


+ +

+ + Légende:
+ entre < >: argument obligatoire,
+ entre [ ]: argument optionel; [1 | ]: argument optionel avec valeur par défaut. +
+

+ +


+

source: git.yt/115ans/sys diff --git a/lib/lsg_web/templates/irc/txt.html.eex b/lib/lsg_web/templates/irc/txt.html.eex index e060e5f..5b31320 100644 --- a/lib/lsg_web/templates/irc/txt.html.eex +++ b/lib/lsg_web/templates/irc/txt.html.eex @@ -8,7 +8,7 @@ ol li {

- 115ans.netirctxt
+ <%= Keyword.get(Application.get_env(:lsg, :irc), :name, "ircbot") %>txt
<%= @name %>.txt

    @@ -17,3 +17,6 @@ ol li { <% end %>
+

+ télécharger au format texte +

diff --git a/lib/lsg_web/templates/irc/txts.html.eex b/lib/lsg_web/templates/irc/txts.html.eex index 5039c29..28d0220 100644 --- a/lib/lsg_web/templates/irc/txts.html.eex +++ b/lib/lsg_web/templates/irc/txts.html.eex @@ -9,10 +9,13 @@ h1 small { font-size: 14px; } -

115ans.netirc
+

+ <%= Keyword.get(Application.get_env(:lsg, :irc), :name, "ircbot") %>
txt

-

<%= @lines %> lignes dans <%= @files %> fichiers.

+

<%= @lines %> lignes dans <%= @files %> fichiers. +Aide. +

-
<%= @doc |> Earmark.as_html! |> raw() %>
+
<%= @doc |> Earmark.as_html! |> raw() %>
diff --git a/lib/lsg_web/templates/page/index.html.eex b/lib/lsg_web/templates/page/index.html.eex index 98e407c..1b8519a 100644 --- a/lib/lsg_web/templates/page/index.html.eex +++ b/lib/lsg_web/templates/page/index.html.eex @@ -1 +1 @@ -

Vous n'avez rien de mieux à faire ? Non ? Allez sur 115ans.net, alors.

+

vOv

-- cgit v1.2.3