Hash :
3f685486
Author :
Thomas de Grivel
Date :
2025-09-11T16:54:22
fix make fx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
## kc3
## Copyright from 2022 to 2025 kmx.io <contact@kmx.io>
##
## Permission is hereby granted to use this software granted the above
## copyright notice and this permission paragraph are included in all
## copies and substantial portions of this software.
##
## THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
## PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
## AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
## THIS SOFTWARE.
require EKC3
require File
require HTML
require Inspect
require Sh
require URL
defmodule FXView do
def path_links = fn {
(path) {
[_dot | path_list] = Str.split(path, "/")
path_links(path_list, "/", [])
}
([], _, acc) { List.join(List.reverse(acc), "/") }
([first | rest], url, acc) {
a = """
<a href="#{URL.escape(url + first)}">#{HTML.escape(first)}</a>
"""
path_links(rest, "#{url}#{first}/", [a | acc])
}
}
def menu_index_template =
EKC3.load("app/templates/fx/menu_index.html.ekc3")
def index_template =
EKC3.load("app/templates/fx/index.html.ekc3")
def properties_template =
EKC3.load("app/templates/fx/properties.html.ekc3")
def show_file_template =
EKC3.load("app/templates/fx/show_file.html.ekc3")
def render_index = fn (index) {
EKC3.render(FXView.index_template)
}
def render_menu_index = fn (index) {
EKC3.render(FXView.menu_index_template)
}
def render_properties = fn (properties) {
EKC3.render(FXView.properties_template)
}
def render_show_file_preview = fn (path, size) {
file_size = File.size(path)
mime = HTTP.mime_type(File.ext(path))
[mime_first, mime_second] = Str.split((Str) mime, "/")
mime_first = (Sym) mime_first
mime_second = (Sym) mime_second
file_path = "/file" + Str.slice(path, 4, -1)
preview = if (mime_first == :image) do
if (size == :small && file_size > 16024024) do
""
else
"""<img class="#{size}" src="#{URL.escape(file_path)}" alt="#{HTML.escape(path)}" />"""
end
else
if (mime_first == :video) do
"""<video class="#{size}" controls><source src="#{URL.escape(file_path)}" /></video>"""
else
if (mime_first == :audio) do
"""<audio class="#{size}" controls src="#{URL.escape(file_path)}" />"""
else
if (mime_first == :text ||
Str.starts_with?(mime, "application/javascript") ||
mime == "application/x-shellscript\n") do
file = if (size == :small && file_size > 77) do
Str.slice(File.read_max(path, 77), 0, 77) + "..."
else
File.read_all(path)
end
ext = File.ext(path)
class = if (ext == "kc3" ||
ext == "ekc3" ||
ext == "facts") do
"class=\"language-elixir\""
else
if (ext != "") do
"class=\"language-#{ext}\""
else
if (File.name(path) == "GNUmakefile" ||
File.name(path) == "Makefile" ||
File.name(path) == "makefile") do
"class=\"language-make\""
else
""
end
end
end
"""<pre class="#{size}"><code #{class}>#{HTML.escape(file)}</code> </pre>"""
else
content = if (size == :small) do
File.read_slice(path, 0, 42)
else
File.read_all(path)
end
file = if (Str.is_utf8?(content)) do content else
Inspect.str_hex(content)
end
"""<pre class="#{size}">#{HTML.escape(file)}</pre>"""
end
end
end
end
"""<span class="size">#{HTML.escape(human_size(file_size))}</span>
<span class="file">#{HTML.escape(mime)}</span>
<div class="#{size}">#{preview}<hr /></div>"""
}
def render_show_file = fn (path, menu, file, properties) {
nav2 = ""
EKC3.render(FXView.show_file_template)
}
end