diff options
author | sanine <sanine.not@pm.me> | 2022-05-22 02:35:53 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-05-22 02:35:53 -0500 |
commit | 9855e635835716c638ab72c844d5dac08288a20c (patch) | |
tree | e2feb87779195165818acb69d0c1a4f998dae846 |
initial commit
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | README.md | 17 | ||||
-rw-r--r-- | marigold.lua | 39 | ||||
-rwxr-xr-x | test.lua | 48 |
4 files changed, 105 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8d98f9d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.* diff --git a/README.md b/README.md new file mode 100644 index 0000000..1509a93 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +marigold-cgi +============ + +A Lua CGI scripting toolkit. + +usage +----- + +### retrieving meta-variables + +`marigold.get_metavars()` - returns a table. The keys are the (lowercase) names of the meta-variables described in section 4.1 of RFC 3875 and are associated with their (string) values. + +### generating html + +`marigold.h(tag, attributes_and_children)` - returns a `marigold.html` table. `tag` is a string; `attributes_and_children` is a table containing, uh, tag attributes and children. Attributes are string keys with string values and represent the tag's attributes (e.g. `{id='tag1', class='large blinking'}` converts to `<[tag] id="tag1" class="large blinking"></[tag]>`). Children are the array elements of the table and should contain `marigold.html` tables as values. + +The only thing that is special about `marigold.html` tables is that they can be passed to `marigold.render_html(tbl, indent_level=0)` in order to produce actual string output. diff --git a/marigold.lua b/marigold.lua new file mode 100644 index 0000000..939a7ba --- /dev/null +++ b/marigold.lua @@ -0,0 +1,39 @@ +-- ANTI-CAPITALIST SOFTWARE LICENSE (v 1.4) +-- +-- Copyright (c) 2022 Kate Swanson +-- +-- This is anti-capitalist software, released for free use by individuals and +-- organizations that do not operate by capitalist principles. +-- +-- Permission is hereby granted, free of charge, to any person or organization ( +-- the "User") obtaining a copy of this software and associated documentation +-- files (the "Software"), to use, copy, modify, merge, distribute, and/or sell +-- copies of the Software, subject to the following conditions: +-- +-- 1. The above copyright notice and this permission notice shall be included in +-- all copies or modified versions of the Software. +-- +-- 2. The User is one of the following: +-- a. An individual person, laboring for themselves +-- b. A non-profit organization +-- c. An educational institution +-- d. An organization that seeks shared profit for all of its members, and allows +-- non-members to set the cost of their labor +-- +-- 3. If the User is an organization with owners, then all owners are workers and +-- all workers are owners with equal equity and/or equal vote. +-- +-- 4. If the User is an organization, then the User is not law enforcement or +-- military, or working for or under either. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY +-- KIND, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +-- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE +-- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +-- CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +-- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +local marigold = {} + + diff --git a/test.lua b/test.lua new file mode 100755 index 0000000..d66f977 --- /dev/null +++ b/test.lua @@ -0,0 +1,48 @@ +#!/usr/bin/lua + +local marigold = require 'marigold' + +function test(description, func) + io.write(description .. ': ') + local result, msg = pcall(func) + if result == true then + print("OK") + else + print("FAIL") + print(debug.traceback(msg)) + print() + end +end + +function test_assert(str) + local f = assert(loadstring('return ' .. str)) + assert(f(), 'assertion failed: ' .. str) +end + + +test("marigold.get_metavars correctly calls os.getenv", function() + -- mock os.getenv + local old_getenv = os.getenv + local env_tbl = { + AUTH_TYPE = 'some auth type', + CONTENT_LENGTH = 'a zillion', + GATEWAY_INTERFACE = 'idk, something', + PATH_INFO = 'youll see, its a secret', + PATH_TRANSLATED = 'i told you its a secret!', + QUERY_STRING = 'which string do you want?', + REMOTE_ADDR = 'probably somewhere in nunavut', + REMOTE_HOST = 'woah wait are we talking about parasites?', + REMOTE_IDENT = 'are you a cop?', + REMOTE_USER = 'seriously, you have to tell me if you are', + REQUEST_METHOD = 'uhh, to do what?', + SCRIPT_NAME = 'pretty sure this is hamlet', + SERVER_NAME = 'this isnt a restaurant', + SERVER_PROTOCOL = 'no really, not a restaurant', + SERVER_SOFTWARE = 'not familiar with that dish...', + } + os.getenv = function(varname) return env_tbl[varname] end + + -- actually call the function + --local metavars = marigold.get_metavars() + test_assert("type(metavars) == 'table'") +end) |