H5tk - An erector like html5 code generation toolkit for lua

$ luarocks install h5tk

# h5tk

This module can be used to generate HTML5 code.
It is very similar to the [erector](http://erector.rubyforge.org/) framework.

# Installation
It's on [luarocks](https://luarocks.org/modules/forflo/h5tk)!
Just execute

$ sudo luarocks install h5tk

# Usage
All functions take a table as input. Each value whose
key is of type string is interpreted as an attribute for
the current html tag. Every value whose key is of type number
is considered to be a part of the data
that should be enclosed between the specified html tags.

h5tk can be used to produce unformatted and formatted html markup.
In formatting mode, the number of intendation spaces can be adjusted.
The toolkit even allows you to use tabs instead of spaces!

## Initialization
Without further ado, consider the code below.

local h5tk = require("h5tk").init(format, indent, use_tabs)
-- format toggles formatting of the html code (must be a boolean)
-- indent specifies the number of spaces (or tabs) used for each
-- indentation level (must be a number)
-- use_tabs switches the indentation character (must be a boolean)
-- (false: spaces, true: tabs)

### Standard init Values

* *format* = true
* *indent* = 4
* *use_tabs* = false

## Basic workings

someattr = "attrvalue"

After the first evaluation step, the table that h5tk.tr gets would
look like this:

h5tk.emit(h5tk.tr{someattr = "attrvalue",

Now, since someattr is a string key associated with "attrvalue",
the call to h5tk.tr would produce the following code:

<tr someattr="attrvalue">

This would also work if we hadn't put all attrname = "attrvalue"
pairs on top of our table.

## Function evaluation
Lets put some more data in our table.

h5tk.emit(h5tk.tr{someattr = "attrvalue",
(function ()
return h5tr.td{"funcgenfoo"}

Lets tackle this step-by-step!
* The function gets evaluated and calls h5tr.td, which, in turn,
generates a result table that'll be put into the parent table (h5tk.tr{})
* Pure boolean values will be interpreted as "true" for true and "false" for false
* Sub-tables will act, as if they were not present, meaning that the contained strings or values
will be put directly into the table that h5tr.tr gets. They also don't have any impact on the
indentation on the resulting html markup code

## General type evaluation

someattr = "attrvalue", => "someattr="attrvalue""
(function ()
return h5tr.td{"funcgenfoo"}
end), => "<td>funcgenfoo</td>"
{"nested1", " nested2", {"snest"}}, => "nested1 nested2snest"
"string", => "string"
nil, => "nil"
true, => "true"
false, => "false"
42 => "42"

The final result:
<tr someattr="attrvalue">
nested1 nested2snest

## Notes
### Special tags
Some HTML5-tags have the following syntax:

<tagname attr="attrval" moreattr="attrval" ...>

Which means, as you can see, that they don't have an end-tag,
and don't enclose text data. h5tk handles these tags correctly.
For example:

h5tk.img{src = "foo.bar.com"}
-- creates without and end tag:
<img src="foo.bar.com">

This is also true for every other tag that acts like this.

### Boolean attributes
The dialog tag can have an boolean attribute which is
commonly denoted as:

<dialog open> ...

While you can't express this with h5tk,

<dialog open="">

means the same thing, which, in fact, you can produce very
easily. This behaviour will change, though.


2.3-19 years ago4,913 downloads
2.2-19 years ago48 downloads
2.1-19 years ago68 downloads
2.0-19 years ago66 downloads
1.0-19 years ago137 downloads


lua ~> 5