summaryrefslogtreecommitdiff
path: root/README.md
blob: 180b168b044a5bb019cfbaa7e18427bf7d884472 (plain)
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
marigold-cgi
============

A Lua CGI scripting toolkit.


functions
---------

#### `marigold.get_metavars()` ####

Returns a table containing all of the meta-variables described in section 4.1 
of [RFC 3875]. The keys are the lowercase metavariable names (e.g. `
request_method`) and the values are strings containing their values.


#### `marigold.h(tag_type [string], content [string, opt], tbl [table, opt])` ####

Builds a table to be used with `marigold.html`.

  * `tag_type`: the type of the tag, e.g. `<p>`, `<div>`, etc
  * `content`: any text content within the tag. may be omitted and *still include tbl*
  * `tbl`: table containing both tag attributes and children. Values with 
     string keys are considered attributes, while values with numeric keys are 
     added as children in the same order as the keys.

Returns a table with stringly-typed `tag` and `content` keys, and table-typed `
attributes` and `children` keys. There is no reason you can't generate a table 
like this by hand and pass it to `marigold.html`; this function is provided for convenience.


#### `marigold.html(tbl [table], indent_level [number, opt])` ####

Reads a `marigold.h`-formatted table and returns a pretty-printed HTML fragment representing it.

  * `tbl`: a table as described above
  * `indent_level`: 0 by default, but if you're rendering a document piecemeal you might set this

Returns a string with nicely formatted HTML. To render a whole document, pass 
it a `marigold.h('html', ...)` result.


#### `marigold.decode_percent(str [string])` ####

Decodes percent-encoded strings.

  * `str`: a string with percent-encoded values embedded

Returns the clean string, with the percent-encoded values decoded. Note that 
it will NOT do things like replace '+' with ' ' for `application/x-www-form-urlencoded` 
data.


#### `marigold.decode_query(str [string])` ####

Decodes `application/x-www-form-urlencoded` data into a table.

   * `str`: the string containing the data to decode

Returns a table containing all the key-value pairs that could be extracted 
from the string, with all percent-encoding removed and appropriate '+' replaced with ' '.


[RFC 3875]: https://www.rfc-editor.org/rfc/rfc3875.html