summaryrefslogtreecommitdiff
path: root/lib/lsg_web
diff options
context:
space:
mode:
authorhref <href@random.sh>2020-03-11 21:18:34 +0100
committerhref <href@random.sh>2020-03-11 21:18:34 +0100
commita28d24470ddeca6196219a1333c1ccac1319efef (patch)
tree4f29e3c8fb6afbb1f99d6b8737f844c95fca54df /lib/lsg_web
parentup to 420*100 (diff)
welp
Diffstat (limited to 'lib/lsg_web')
-rw-r--r--lib/lsg_web/controllers/irc_controller.ex27
-rw-r--r--lib/lsg_web/router.ex2
-rw-r--r--lib/lsg_web/templates/irc/index.html.eex35
-rw-r--r--lib/lsg_web/templates/irc/txt.html.eex5
-rw-r--r--lib/lsg_web/templates/irc/txts.html.eex9
-rw-r--r--lib/lsg_web/templates/page/index.html.eex2
6 files changed, 62 insertions, 18 deletions
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 {
}
</style>
-<h1>
- <small><a href="https://115ans.net">115ans.net</a> &rsaquo; </small><br/>
-irc 115ans</h1>
+<h1><%= Keyword.get(Application.get_env(:lsg, :irc), :name, "ircbot") %></h1>
-<p>
+<!--<p>
Serveur IRC: <a href="irc://irc.quakenet.org/lsg">irc.quakenet.org #lsg</a>.
&nbsp;Matrix: <a href="https://matrix.random.sh/riot/#rooms/#lsg:random.sh">#lsg:random.sh</a>.
<br />
<a href="https://115ans.net/irc/">Webchat</a>.
<br />
<a href="/irc/stats/">Statistiques</a>.
-</p>
+</del>
+</p>-->
<style type="text/css">
@@ -27,12 +26,34 @@ Serveur IRC: <a href="irc://irc.quakenet.org/lsg">irc.quakenet.org #lsg</a>.
}
</style>
+<p>
+ <% list = for {identifier, _} <- @commands do %>
+ <% name = String.replace(identifier, "_", " ") %>
+ <%= link(name, to: "##{identifier}") #raw("<a href='##{identifier}'>#{name}</a>") %>
+ <% end %>
+ <small><%= Enum.intersperse(list, " - ") %></small>
+</p>
+
<div class="irchelps">
- <%= for help <- @commands do %>
- <div class="help-entry"><%= help |> Earmark.as_html! |> raw() %></div>
+ <%= for {identifier, help} <- @commands do %>
+ <%= if help do %>
+ <div class="help-entry" id="<%= identifier %>"><%= help |> Earmark.as_html! |> raw() %></div>
+ <% end %>
<% end %>
</div>
+<br/><br/><br/>
+
+<p>
+<small>
+ <strong>Légende:</strong><br />
+ entre <code>< ></code>: argument obligatoire,<br />
+ entre <code>[ ]</code>: argument optionel; <code>[1 | ]</code>: argument optionel avec valeur par défaut.
+</small>
+</p>
+
+<br/><br/><br/>
+
<p>
<small>
source: <a href="https://git.yt/115ans/sys">git.yt/115ans/sys</a>
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 {
</style>
<h1>
- <small><a href="https://115ans.net">115ans.net</a> &rsaquo; <a href="/irc">irc</a> &rsaquo; <a href="/irc/txt">txt</a> &rsaquo;</small><br/>
+ <small><a href="/irc"><%= Keyword.get(Application.get_env(:lsg, :irc), :name, "ircbot") %></a> &rsaquo; <a href="/irc/txt">txt</a> &rsaquo;</small><br/>
<%= @name %>.txt</h1>
<ol>
@@ -17,3 +17,6 @@ ol li {
<% end %>
</ol>
+<p>
+ <a href="/irc/txt/<%= @name %>.txt">télécharger au format texte</a>
+</p>
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;
}
</style>
-<h1><small><a href="https://115ans.net">115ans.net</a> &rsaquo; <a href="/irc">irc</a> &rsaquo;</small><br/>
+<h1>
+ <small><a href="/irc"><%= Keyword.get(Application.get_env(:lsg, :irc), :name, "ircbot") %></a> &rsaquo; </small><br/>
txt</h1>
-<p><strong><%= @lines %></strong> lignes dans <strong><%= @files %></strong> fichiers.</p>
+<p><strong><%= @lines %></strong> lignes dans <strong><%= @files %></strong> fichiers.
+<a href="#help">Aide</a>.
+</p>
<ul>
<%= for {txt, data} <- @data do %>
@@ -20,5 +23,5 @@ h1 small {
<% end %>
</ul>
-<div class="help-entry"><%= @doc |> Earmark.as_html! |> raw() %></div>
+<div class="help-entry" id="help"><%= @doc |> Earmark.as_html! |> raw() %></div>
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 @@
-<p>Vous n'avez rien de mieux à faire ? Non ? Allez sur <a href="https://115ans.net">115ans.net</a>, alors.</p>
+<p>vOv</p>