Hash :
b0aec28e
Author :
Thomas de Grivel
Date :
2024-09-19T16:24:02
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
defmodule FXView do
require HTML
require List
require Str
require URL
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(index_template)
}
def render_menu_index = fn (index) {
EKC3.render(menu_index_template)
}
def render_properties = fn (properties) {
EKC3.render(properties_template)
}
def render_show_file_preview = fn (path, size) {
mime = HTTP.mime_type(File.ext(path))
mime_first = (Sym) first(Str.split((Str) mime, "/"))
file_path = "/file" + Str.slice(path, 4, -1)
preview = if (mime_first == :image) do
"""<img class="#{size}" src="#{URL.escape(file_path)}" alt="#{HTML.escape(path)}" />"""
else
if (mime == :"text/plain") do
file = File.read(path)
if (size == :small && Str.size(file) > 80) do
file = Str.slice(file, 0, 80) + "..."
end
"""<pre class="#{size}">#{HTML.escape(file)}</pre>"""
else
HTML.escape(mime)
end
end
"""<div class="#{size}">#{preview}<hr /></div>"""
}
def render_show_file = fn (path, menu, file, properties) {
EKC3.render(show_file_template)
}
end