module demo::vis::StaticSite
rascal-0.40.17
Demonstrates HTML generation and viewing in Rascal.
Usage
import demo::vis::StaticSite;
Dependencies
import lang::html::IO;
Description
In the current module we have a function table
which transforms
any binary relation into an HTML table:
module demo::vis::StaticSite
import lang::html::IO;
HTMLElement table(rel[&T, &U] r)
= table([
tr([
td([text("<a>")]),
td([text("<b>")])
])
| <a, b> <- r
]);
When we try this out on the commandline, the REPL will pop-up a browser window such that we can visualize the result:
rascal>import demo::vis::StaticSite;
ok
rascal>import lang::html::IO;
ok
rascal>characters = {"Sneezy", "Sleepy", "Dopey", "Doc", "Happy", "Bashful", "Grumpy"};
set[str]: {"Happy","Sleepy","Bashful","Grumpy","Doc","Dopey","Sneezy"}
rascal>serve(table(characters * characters));
To get this effect we used the following library modules:
- AST contains the HTML abstract syntax tree definition
- IO knows how to pretty-print HTML
- Content provides access to the builtin application server of the Rascal REPL
function table
Translates a binary relation to an HTML table element.
HTMLElement table(rel[&T, &U] r)
= table([
tr([
td([text("<a>")]),
td([text("<b>")])
])
| <a, b> <- r
]);