Commit a1d4da67613f7dd2ff93c24e9cdee78a1646f8f8

Thomas de Grivel 2024-09-16T18:28:16

wip fx

diff --git a/.gitignore b/.gitignore
index cf76b40..1c8ae46 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,6 +28,7 @@ httpd/kc3_httpd
 httpd/kc3_httpd_asan
 httpd/kc3_httpd_cov
 httpd/kc3_httpd_debug
+httpd/fx/log/*.log
 ikc3/ikc3
 ikc3/ikc3_asan
 ikc3/ikc3_cov
diff --git a/httpd/fx/app/controllers/fx_controller.kc3 b/httpd/fx/app/controllers/fx_controller.kc3
index 214cc6f..61312b1 100644
--- a/httpd/fx/app/controllers/fx_controller.kc3
+++ b/httpd/fx/app/controllers/fx_controller.kc3
@@ -1,8 +1,81 @@
 defmodule FXController do
 
-  def route = fn (req) do
-    if (req.method == GET || req.method == HEAD) do
-      path = "." + req.url, 
+  require EKC3
+  require File
+  require List
+  require Str
+
+  def fx_index = fn {
+    (path, path_md) { fx_index(path, path_md, path, []) }
+    ([], path_md, dir, acc) { List.reverse(acc) }
+    ([file | rest], path_md, dir, acc) {
+      if (Str.starts_with?(file, ".") ||
+          Str.starts_with?(file, "index.") ||
+          (Str.rindex_character(file, '.') > 0 &&
+           ! Str.ends_with?(file, ".md") &&
+           ! Str.ends_with?(file, ".html"))) do
+        fx_index(rest, path_md, dir, acc)
+      else
+        path = dir + file
+        name = Str.subst(file, "_", " ")
+        url = Str.slice(path, 1, -1)
+        if File.is_directory?(path) do
+          items = fx_index(List.sort(File.list(path)), path_md,
+            path + "/", [])
+          item = %{type: :dir,
+                   url: url,
+                   name: name,
+                   items: items}
+          fx_index(rest, path_md, dir, [item | acc])
+        else
+          end_ = Str.rindex_character(name, '.')
+          if (end_ > 0) do
+            name = Str.slice(name, 0, end_)
+            end_ = Str.rindex_character(name, '.')
+            if (end_ > 0) do
+              name = Str.slice(name, 0, end_)
+            end
+          end
+          end_ = Str.rindex_character(url, '.')
+          if (end_ > 0) do
+            url = Str.slice(url, 0, end_)
+            end_ = Str.rindex_character(url, '.')
+            if (end_ > 0) do
+              url = Str.slice(url, 0, end_)
+            end
+          end
+          item = %{type: :file,
+                   url: url,
+                   name: name,
+                   items: []}
+          fx_index(rest, path_md, dir, [item | acc])
+        end
+      end
+    }
+    (path, path_md, dir, acc) {
+      if (type(path) == Str) do
+        fx_index(List.sort(File.list(path)), path_md, dir, acc)
+      end
+    }
+  }
+
+  def show_file = fn (path) {
+    index = fx_index("./fx/", path)
+    menu = FXView.render_menu(index)
+    title = path
+    page = FXView.render_show(menu, html)
+    body = LayoutView.render(title, page)
+    %HTTP.Response{body: body}
+
+  }
+
+  def route = fn (req) {
+    if ((req.method == GET ||
+         req.method == HEAD) &&
+        (req.url == "/fx" ||
+         Str.starts_with?(req.url, "/fx/"))) do
+      path = "." + req.url
+      show(path)
     end
   end
 
diff --git a/httpd/fx/app/templates/fx/properties.html.ekc3 b/httpd/fx/app/templates/fx/properties.html.ekc3
new file mode 100644
index 0000000..d3a769a
--- /dev/null
+++ b/httpd/fx/app/templates/fx/properties.html.ekc3
@@ -0,0 +1,9 @@
+<table>
+  <%= raw List.join(List.map(properties, fn (fact) {
+    """
+  <tr>
+    <td>#{HTML.escape(fact.predicate)}</td>
+    <td>#{HTML.escape(fact.object)}</td>
+  </tr>
+"""}), "\n") %>
+</table>
diff --git a/httpd/fx/log/.keep b/httpd/fx/log/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/httpd/fx/log/.keep
diff --git a/log/.keep b/log/.keep
deleted file mode 100644
index e69de29..0000000
--- a/log/.keep
+++ /dev/null