$(ee(e.last_name)) | $(ee(e.first_name)) | $(e.title)
| $(ee(e.email))
| $(ee(e.main_number)) | $(ee(e.cell_phone))
| $(join(["$(ee(c))" for c in e.comments]))
"""
reg_test() = begin
io = IOBuffer()
ob = reg_database(database)
show(io, ob)
return io
end
@tags html head body title dl dt dd table tr th td span
hs_database(d) =
html(head(title("Customers & Employees")),
body([hs_customer(c) for c in d]...))
hs_customer(c)=
dl(dt("Company"), dd(c.company),
dt("Phrase"), dd(c.phrase),
dt("Active Since"), dd(c.active),
dt("Employees"), dd(
table(tr(th("Last Name"),th("First Name"),th("Title"),
th("E-Mail"),th("Office Phone"),th("Cell Phone"),
th("Comments")),
[hs_employee(e) for e in c.employees]...)))
hs_employee(e) = tr(td(e.last_name), td(e.first_name), td(e.title),
td(href="mailto:$(e.email)", e.email),
td(e.main_number), td(e.cell_phone),
td([span(c) for c in e.comments]...))
hs_test() = begin
io = IOBuffer()
ob = hs_database(database)
show(io, MIME("text/html"), ob)
return io
end
function H(xs...)
HTML() do io
for x in xs
show(io, MIME"text/html"(), x)
end
end
end
function entity(str::AbstractString)
@assert length(str) == 1
entity(str[1])
end
entity(ch::Char) = "$(Int(ch));"
HE(x) = HTML(replace(x, r"[<&]" => entity))
HA(x) = HTML(replace(x, r"[<']" => entity))
#HE(x) = HTML(replace(replace(x, "&" => "&"), "<" => "<"))
#HA(x) = HTML(replace(replace(x, "&" => "&"), "\"" => """))
cus_database(d) =
H(HTML(""), HE("Customers & Employees"),
HTML(""),
[cus_customer(c) for c in d]...,
HTML(""))
cus_customer(c) =
H(HTML("- Company
- "), HE(c.company),
HTML("
- Phrase
- "), HE(c.phrase),
HTML("
- Active Siince
- "), HE(c.active),
HTML("""
- Employees
-
Last Name | First Name | Title
| E-Mail | Office Phone | Cell Phone
| Comments | """),
[cus_employee(e) for e in c.employees]...,
HTML(" "))
cus_employee(e) =
H(HTML(" |
"), HE(e.last_name),
HTML(" | "), HE(e.first_name),
HTML(" | "), HE(e.title),
HTML(" | "), HE(e.email), HTML(""),
HTML(" | "), HE(e.main_number),
HTML(" | "), HE(e.cell_phone),
HTML(" | "),
[H(HTML(""), HE(c), HTML("")) for c in e.comments]...)
cus_test() = begin
io = IOBuffer()
ob = cus_database(database)
show(io, MIME("text/html"), ob)
return io
end
nest_result(d) = @htl("
Customers & Employees)
$((map(d) do c; @htl("
- Company
- $(c.company)
- Phrase
- $(c.phrase)
- Active Since
- $(c.active)
- Employees
-
Last Name | First Name | Title
| E-Mail | Office Phone | Cell Phone
| Comments |
$((map(c.employees) do e; @htl("
$(e.last_name) | $(e.first_name) | $(e.title)
| $(e.email)
| $(e.main_number) | $(e.cell_phone)
| $((@htl("$c") for c in e.comments))
"); end)) |
"); end))
")
nest_test() = begin
io = IOBuffer()
ob = nest_result(database)
show(io, MIME("text/html"), ob)
return io
end
BenchmarkTools.DEFAULT_PARAMETERS.seconds = 20
@info("interpolate: ", @benchmark reg_test())
@info("Custom HTML: ", @benchmark cus_test())
@info("Hyperscript: ", @benchmark hs_test())
@info("HypertextLiteral: ", @benchmark htl_test())
@info("HTL (Attributes): ", @benchmark att_test())
@info("Nest Testing: ", @benchmark nest_test())
if false
open("htl.html", "w") do f
ob = htl_database(database)
show(f, MIME("text/html"), ob)
end
open("hs.html", "w") do f
ob = hs_database(database)
show(f, MIME("text/html"), ob)
end
open("reg.html", "w") do f
ob = reg_database(database)
show(f, ob)
end
open("cus.html", "w") do f
ob = cus_database(database)
show(f, MIME("text/html"), ob)
end
end
|