-
Notifications
You must be signed in to change notification settings - Fork 1
/
h5tk-2.3-1.rockspec
199 lines (161 loc) · 6.22 KB
/
h5tk-2.3-1.rockspec
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package = "h5tk"
version = "2.3-1"
source = {
url = "git://github.com/forflo/h5tk",
tag = "v4.3"
}
description = {
summary = "H5tk - An erector like html5 code generation toolkit for lua",
detailed = [[
# 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 builder = require("h5tk")
html_builder1 = builder(format, indent, use_tabs)
html_builder2 = builder(true, 4, false)
html_builder3 = builder(false)
*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)
You can always create new html builders with different
formatting settings. All builders will remain independent
from each other, just as they should be.
### Standard init Values
* *format* = true
* *indent* = 4
* *use_tabs* = false
## Motivation for h5tk
On luarocks there is another very similar package called "htk".
There are some drawbacks with this package
* No formatting (The HTML code can not automatically be indentet)
* No support for HTML5 tags
* You can only pass tables of strings to the constructor function.
h5tk on the other hand, handles every value as expected. You can
pass functions, tables of functions, tables of tables. All values
will be reduced (eventually) to a string.
## Basic workings
io.write(h5tk.emit(h5tk.tr{
someattr = "attrvalue"
h5tk.td{"foo1"},
h5tk.td{"foo2"},
h5tk.td{"boo3"},
h5tk.td{"boo4"}
}))
After the first evaluation step, the table that h5tk.tr gets would
look like this:
h5tk.emit(h5tk.tr{someattr = "attrvalue",
"<td>foo1</td>",
"<td>foo2</td>",
"<td>boo3</td>",
"<td>boo4</td>"})
Now, since someattr is a string key associated with "attrvalue",
the call to h5tk.tr would produce the following code:
<tr someattr="attrvalue">
<td>foo1</td>
<td>foo2</th>
<td>boo3</th>
<td>boo4</td>
</tr>
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"}
end),
h5tr.td{true},
{
"nested1",
"nested2",
{
"subnested1",
"foonested2"
}
},
"foo1",
"foo2",
"boo",
"boo4"
})
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
h5tk.emit(h5tk.tr{
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">
<td>
funcgenfoo
</td>
nested1 nested2snest
string
nil
true
false
42
</tr>
## 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.
]],
homepage = "http://www.github.com/forflo/h5tk",
license = "GPL"
}
dependencies = {
"lua ~> 5"
}
build = {
type = "builtin",
modules = {
h5tk = "h5tk.lua"
}
}