what is · download · reference · examples · news · implementation
HTK was developed to provide a structured way to build HTML pages. It has an homogeneuos API to all HTML elements despite their own particularities: all pre-defined form-field values are set with value attribute, even for multi-line fields (built with TEXTAREA constructor) or radio buttons (built with RADIO constructor).
htk.class_defaults.TD = "common"
print (htk.TR {
htk.TD { "first" },
htk.TD { "second", class = "special" },
htk.TD { "third" },
separator = "\n",
})
will generate the following output:
<TR> <TD class="common">first</TD> <TD class="special">second</TD> <TD class="common">third</TD> </TR>8
| Lua source | HTML generated | Final result |
|---|---|---|
print(htk.B { "Bold" }) | <B>Bold</B> | Bold |
print(htk.BIG {
separator = "\n",
"A sample ",
htk.EM { "text" },
" with some ",
htk.B { "formatting tags" },
htk.BR {},
}) | <BIG> A sample <EM>text</EM> with some <B>formatting tags</B> <BR> </BIG> |
A sample
text
with some
formatting tags
|
print(htk.FORM {
method = "POST",
htk.TABLE {
separator = "\n",
border = true,
htk.TEXT_FIELD {
label = "Full name",
separator = "\n",
name = "name",
value = "Write your name here",
},
htk.RADIO_FIELD {
label = "Sex",
separator = "\n",
name = "sex",
options = {
{ "Masc.", value = "M" },
{ "Fem.", value = "F" },
},
},
},
}) | <FORM method="POST"><TABLE border> <TR> <TD class="common"> Full name </TD> <TD class="common"> <INPUT name="name" value="Write your name here" type="text"> </TD> </TR> <TR> <TD class="common"> Sex </TD> <TD class="common"> <INPUT name="sex" value="M" type="radio">Masc.</INPUT><BR> <INPUT name="sex" value="F" type="radio">Fem.</INPUT><BR> </TD> </TR> </TABLE></FORM> | |
print(htk.BOX {
separator = '\n',
htk.SELECT {
multiple = true,
name = "cities",
value = "11",
options = {
{ "Rio de Janeiro", value="1" },
{ "Friburgo", value="5" },
{ "Saquarema", value="11" },
{ "Cabo Frio", value="12" },
},
},
htk.SELECT {
multiple = true,
name = "cities",
value = "11,1",
options = {
{ "Rio de Janeiro", value="1" },
{ "Friburgo", value="5" },
{ "Saquarema", value="11" },
{ "Cabo Frio", value="12" },
},
},
htk.SELECT {
multiple = true,
name = "cities",
value = "Friburgo,Cabo Frio",
options = { "Rio de Janeiro", "Friburgo", "Saquarema", "Cabo Frio", },
},
htk.BR {},
htk.RADIO {
name = "cities",
value = "Friburgo",
options = { "Rio de Janeiro", "Friburgo", "Saquarema", "Cabo Frio", },
},
}) | <SELECT multiple name="cities"> <OPTION name="cities" value="1">Rio de Janeiro</OPTION><BR> <OPTION name="cities" value="5">Friburgo</OPTION><BR> <OPTION name="cities" value="11" selected>Saquarema</OPTION><BR> <OPTION name="cities" value="12">Cabo Frio</OPTION><BR> </SELECT> <SELECT multiple name="cities"> <OPTION name="cities" value="1" selected>Rio de Janeiro</OPTION><BR> <OPTION name="cities" value="5">Friburgo</OPTION><BR> <OPTION name="cities" value="11" selected>Saquarema</OPTION><BR> <OPTION name="cities" value="12">Cabo Frio</OPTION><BR> </SELECT> <SELECT multiple name="cities"> <OPTION name="cities" value="Rio de Janeiro">Rio de Janeiro</OPTION><BR> <OPTION name="cities" value="Friburgo" selected>Friburgo</OPTION><BR> <OPTION name="cities" value="Saquarema">Saquarema</OPTION><BR> <OPTION name="cities" value="Cabo Frio" selected>Cabo Frio</OPTION><BR> </SELECT> <BR> <INPUT type="radio" name="cities" value="Rio de Janeiro">Rio de Janeiro</INPUT><BR> <INPUT type="radio" name="cities" value="Friburgo" checked>Friburgo</INPUT><BR> <INPUT type="radio" name="cities" value="Saquarema">Saquarema</INPUT><BR> <INPUT type="radio" name="cities" value="Cabo Frio">Cabo Frio</INPUT><BR> |
Rio de Janeiro Friburgo Saquarema Cabo Frio |
module function
But with version 1.X, the programmer must know what constructors are from HTK and what are the original from HTMLToolkit to write it down properly. Now, with version 2.0, HTMLToolkit was eliminated and all its constructors were incorporated into HTK.
Another difference to version 2.0 is the way the constructors are build. HTMLToolkit has a description table for each HTML element, almost always with the same contents; and also, the elements are always created as tables, its contents are checked (for some obligatory fields) and then the resulting string is created. Version 1.X of HTK depends on HTMLToolkit so it inherit all its functions. On version 2.0, HTK incorporated all HTMLToolkit constructors but with a different approach. As almost all functions differ only in the name of the tag element, now they're just one function, with many closures to make the difference. Also, there are a constructor generator that only build the constructors when they are called, so only the used constructors are really created.
All these changes made version 2.0 at about 60% faster than version 1.0. Besides, the source code is about a third of the previous version, making it easier to maintain, despite its complexity.
what is · download · reference · examples · news · implementation
![]() | and | ![]() |
| Last modified by Tomás on Fri Oct 21 10:41:26 2022 | ||