https://github.com/zeroxthreef/stsml
A scriptable HTML templating server
https://github.com/zeroxthreef/stsml
Last synced: 11 months ago
JSON representation
A scriptable HTML templating server
- Host: GitHub
- URL: https://github.com/zeroxthreef/stsml
- Owner: zeroxthreef
- License: unlicense
- Created: 2020-07-25T11:12:33.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-08-12T02:52:12.000Z (almost 5 years ago)
- Last Synced: 2025-03-28T00:47:02.108Z (about 1 year ago)
- Language: C
- Size: 58.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# STSML
STS Markup Language can do simple scriptable html modifications with the scripting language [STS](https://github.com/zeroxthreef/SimpleTinyScript) (simple tiny script). Sort of like of PHP but this is nowhere near that level.
stsml has an asynchronus task system and redis client functions built in.
## STSML Documentation
stsml is different from vanilla STS's syntax in the following examples: (note that any amount of space including none is ok for these)
``<% ... %>`` (multiline expression)
Multiline STS expressions can be done inside matching brackets. If the file only contains these, nothing will be sent unless explicitly written to the buffer.
Example:
```
<%
print this message will go directly to stderr
print hello :)
%>
<% local i 0 %>
<% loop(< $i 10) { %>
hello, currently at: <%? pass $i %>
<% ++ $i; } # the semicolon is used to put multiple expressions on the same line %>
```
``<%! file/path %>`` (include absolute)
``<%@ file/path %>`` (include relative)
stsml files can be included directly into the current document relative to the current path '@', or relative to the server's working directory '!'. Note that a recursive include will either stack overflow or oom your machine.
``<%? ... %>``(print single expression string value)
Print directly to the current http buffer using just a single STS expression. Note that this means you have to pass a root expression, which means that if you arent calling a function, a `pass` action needs to be used.
Example:
```
<%
local test "hello world"
%>
local value: <%? pass $test %>
<%? string a b c d e f %>
```
## STSML Function Documentation
`http-write append_string`
Append strings to the current http buffer.
`http-clear`
Clear the http buffer.
`http-method-get`
Returns the current http method as a string like 'GET'.
`http-path-get`
Returns the current http not-query string aka the request path
`http-body-get`
Returns the raw http body.
`http-post-get post_key_str`
Returns post data as a string if found, nil if not.
`http-query-get query_key_str`
Returns url query data as a string if found, nil if not.
`http-file-get post_file_name_str`
Returns a string of the file uploaded to a path somewhere in /tmp/ if exists, nil if not. Note that this temporary file disappears when the script exits.
`http-cookie-get cookie_key_str`
Returns the cookie value if found, nil if not.
`http-cookie-put cookie_key_str cookie_value_str cookie_ttl cookie_flags`
Sets a cookie. Flags are 1 for httponly and 2 for secure. Bitwise OR both of these and secure httponly cookies will be set.
`http-header-get header_key_str`
Returns the header value string if found, nil if not.
`http-header-put header_key_str header_value_str`
Set an http header to the header value string.
`http-write-file path_str`
Write a file to the http buffer instead. This is loaded after scripts finish and overrides the regular buffer.
`http-route absolute_str`
Reroute the server internally. Path is absolute and the root is the working directory.
`redis-connect ip_str port_number`
Connects to a Redis server and returns 1.0 on a successful connection, 0.0 otherwise.
`redis ...`
Sends a Redis command to the global connection. Will only take strings and numbers. Any other value type will be skipped. Note that the total number (not size of arguments, these can be nearly infinite) of arguments is limited to an already absurdly long amount of arguments **(1024 max)**, but nothing bad will happen if this is reached, which is near impossible.
This returns a value that converts the redis response to an STS value, so it may be an array, string, or any other kind of value.
`task-create script_file ...`
Create a task thread for asynchronus things. Can run forever if necessary. **Note that these do not share globals with the rest of the system** and all arguments passed are recursively copied.
`stop`
Stop listening for new connections and stop the server process cleanly.
## Server Usage
`-help`
Print help page that lists this section.
`-port`
Set the http port. The default is 8080.
`-init`
Set the startup STS script. **NOTE: this is NOT FOR STSML SCRIPTS. Only regular STS scripts will work**. All of the same functions will work, but it will not be parsed as an stsml file.
`-last_resort`
Display an stsml file if everything else fails. Note that this will halt the server if this file is not found.
`-working_dir`
Set the server working directory.
## Building & Installing
stsml depends on [hiredis](https://github.com/redis/hiredis) and [onion](https://github.com/davidmoreno/onion).
**Debian/Ubuntu:**
```
sudo apt install libhiredis-dev
git clone https://github.com/davidmoreno/onion.git
cd onion
... complete onion install instructions
cd ..
git clone https://github.com/zeroxthreef/stsml.git --recursive
cd stsml
./build.sh
sudo ./install.sh
```
## License
Public Domain / Unlicense (pretty much the same)