Commit 6cc163b030295764737357d696d4156232b3221c

Thomas de Grivel 2024-09-27T16:46:39

wip test/httpd nav and File.read_all

diff --git a/README.md b/README.md
index 584972d..aac28d9 100644
--- a/README.md
+++ b/README.md
@@ -36,7 +36,7 @@ Supported architectures :
 
 ### Install dependencies
 
-#### Debian / Ubuntu / PopOS
+#### Debian / Ubuntu / PopOS / Mint
 
 ```
 # install build tools
@@ -45,11 +45,11 @@ sudo apt install pkg-config clang libtool-bin make ruby time
 # install dependencies
 sudo apt install libffi-dev libbsd-dev libevent-dev
 
+# install demo dependencies
+sudo apt install libsdl2-dev libxkbcommon-dev libfreetype-dev 
+
 # use clang
 export CC=clang
-
-# create symlinks to libs
-make lib_links
 ```
 
 
diff --git a/httpd/fx/app/controllers/fx_controller.kc3 b/httpd/fx/app/controllers/fx_controller.kc3
index a1d3fa0..63d6c2d 100644
--- a/httpd/fx/app/controllers/fx_controller.kc3
+++ b/httpd/fx/app/controllers/fx_controller.kc3
@@ -134,7 +134,7 @@ defmodule FXController do
   def tag_route = fn (req) {
     if (req.url == "/tag" ||
         Str.starts_with?(req.url, "/tag/")) do
-      ["", "tag", tag | url] = Str.split(req.url, "/")     
+      ["", "tag", tag | url] = Str.split(req.url, "/")
       path = "./fx" + req.url
       if (req.method == GET) do
         response = tag_create(path, tag)
@@ -148,4 +148,55 @@ defmodule FXController do
     end
   }
 
+  def property_create = fn (path, property, value) {
+    body = """
+<html>
+  <head>
+    <title>Property create</title>
+  </head>
+  <body>
+    <p><h1>Property create</h1></p>
+    <p>Path : #{HTML.escape(inspect(path))}</p>
+    <p>Property : #{HTML.escape(inspect(property))}</p>
+    <p>Value : #{HTML.escape(inspect(value))}</p>
+  </body>
+</html>
+"""
+    %HTTP.Response{body: body}
+  }
+
+  def property_delete = fn (path, property, value) {
+    body = """
+<html>
+  <head>
+    <title>Property delete</title>
+  </head>
+  <body>
+    <p><h1>Property delete</h1></p>
+    <p>Path : #{HTML.escape(inspect(path))}</p>
+    <p>Property : #{HTML.escape(inspect(property))}</p>
+    <p>Value : #{HTML.escape(inspect(value))}</p>
+  </body>
+</html>
+"""
+    %HTTP.Response{body: body}
+  }
+
+  def property_route = fn (req) {
+    if (req.url == "/property" ||
+        Str.starts_with?(req.url, "/property/")) do
+      ["", "property", property, value | url] = Str.split(req.url, "/")
+      path = "./fx" + req.url
+      if (req.method == GET) do
+        response = property_create(path, property, value)
+      else
+        if (req.method == DELETE) do
+          response = property_delete(path, property, value)
+        else
+          error_404_page(req)
+        end
+      end
+    end
+  }
+
 end
diff --git a/httpd/fx/config/routes.kc3 b/httpd/fx/config/routes.kc3
index b75b2be..31443b0 100644
--- a/httpd/fx/config/routes.kc3
+++ b/httpd/fx/config/routes.kc3
@@ -2,7 +2,7 @@ def HTTPd.routes = []
 
 def_route("/fx/", FXController.fx_route)
 def_route("/tag/", FXController.tag_route)
-#def_route("/property/", FXController.property_route)
+def_route("/property/", FXController.property_route)
 
 def_static_route("/file", "./fx/", 1)
 
diff --git a/test/httpd/app/controllers/doc_controller.kc3 b/test/httpd/app/controllers/doc_controller.kc3
index 3b0b56b..f9d29fd 100644
--- a/test/httpd/app/controllers/doc_controller.kc3
+++ b/test/httpd/app/controllers/doc_controller.kc3
@@ -63,7 +63,7 @@ defmodule DocController do
     index = doc_index("./doc/", path_html)
     menu = DocView.render_menu(index)
     title = "kc3-lang.org"
-    html = File.read(path_html)
+    html = File.read_all(path_html)
     page = DocView.render_show(menu, html)
     body = LayoutView.render(title, page)
     %HTTP.Response{body: body}
@@ -73,7 +73,7 @@ defmodule DocController do
     index = doc_index("./doc/", path_md)
     menu = DocView.render_menu(index)
     title = "kc3-lang.org"
-    md = File.read(path_md)
+    md = File.read_all(path_md)
     html = Markdown.to_html_str(md)
     page = DocView.render_show(menu, html)
     body = LayoutView.render(title, page)
diff --git a/test/httpd/app/templates/footer.html.ekc3 b/test/httpd/app/templates/footer.html.ekc3
new file mode 100644
index 0000000..abf96ec
--- /dev/null
+++ b/test/httpd/app/templates/footer.html.ekc3
@@ -0,0 +1,5 @@
+<footer>
+  <a href="https://kmx.io/">kmx.io</a>
+  <a href="https://git.kmx.io/kc3-lang/kc3">kc3_httpd</a>
+  <a href="https://kc3-lang.org/release/v0.1.13/">v0.1.13</a>
+</footer>
diff --git a/test/httpd/app/templates/layout.html.ekc3 b/test/httpd/app/templates/layout.html.ekc3
index 01ecf1f..2ce18c6 100644
--- a/test/httpd/app/templates/layout.html.ekc3
+++ b/test/httpd/app/templates/layout.html.ekc3
@@ -13,7 +13,7 @@
     <link rel="icon" type="image/png" sizes="16x16" href="/_images/kc3.16.png">
   </head>
   <body>
-    <%= raw EKC3.render_file("app/templates/nav.html.ekc3") %>
+    <%= raw nav %>
     <%= raw page %>
   </body>
 </html>
diff --git a/test/httpd/app/views/layout_view.kc3 b/test/httpd/app/views/layout_view.kc3
index e3043d1..672aada 100644
--- a/test/httpd/app/views/layout_view.kc3
+++ b/test/httpd/app/views/layout_view.kc3
@@ -2,6 +2,10 @@ defmodule LayoutView do
 
   def template = EKC3.load("app/templates/layout.html.ekc3")
 
+  def template_nav = EKC3.load("app/templates/nav.html.ekc3")
+
+  def nav = EKC3.render(template_nav)
+
   def render = fn (title, page) {
     EKC3.render(template)
   }