trying to port web app starter from PHP
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
Markup Functions
|
||||
markdown_to_ast
|
||||
markdown_to_html
|
||||
@@ -0,0 +1,8 @@
|
||||
Memcache Functions
|
||||
|
||||
memcache_command
|
||||
memcache_connect
|
||||
memcache_delete
|
||||
memcache_get
|
||||
memcache_get_multiple
|
||||
memcache_set
|
||||
@@ -0,0 +1,8 @@
|
||||
MySQL Functions
|
||||
|
||||
mysql_connect
|
||||
mysql_disconnect
|
||||
mysql_error
|
||||
mysql_escape
|
||||
mysql_insert_id
|
||||
mysql_query
|
||||
@@ -0,0 +1,10 @@
|
||||
Noise/Hash Functions
|
||||
|
||||
draw_float
|
||||
draw_int
|
||||
gen_noise01
|
||||
gen_noise32
|
||||
gen_noise64
|
||||
gen_float
|
||||
gen_int
|
||||
gen_sha1
|
||||
@@ -0,0 +1,15 @@
|
||||
Output / Invocation Functions
|
||||
|
||||
1_RENDER
|
||||
call_file
|
||||
component
|
||||
component_exists
|
||||
component_resolve
|
||||
load
|
||||
ob_close
|
||||
ob_get
|
||||
ob_get_close
|
||||
ob_start
|
||||
print
|
||||
render_component
|
||||
render_file
|
||||
@@ -0,0 +1,5 @@
|
||||
Sessions
|
||||
|
||||
make_session_id
|
||||
session_destroy
|
||||
session_start
|
||||
@@ -0,0 +1,6 @@
|
||||
Socket Functions
|
||||
|
||||
socket_close
|
||||
socket_connect
|
||||
socket_read
|
||||
socket_write
|
||||
@@ -0,0 +1,15 @@
|
||||
String Functions
|
||||
|
||||
concat
|
||||
filter
|
||||
first
|
||||
join
|
||||
nibble
|
||||
print
|
||||
split
|
||||
split_space
|
||||
split_utf8
|
||||
replace
|
||||
to_lower
|
||||
to_upper
|
||||
trim
|
||||
@@ -0,0 +1,17 @@
|
||||
File System Functions
|
||||
|
||||
basename
|
||||
dirname
|
||||
expand_path
|
||||
file_append
|
||||
file_exists
|
||||
file_get_contents
|
||||
file_mtime
|
||||
file_put_contents
|
||||
get_cwd
|
||||
ls
|
||||
mkdir
|
||||
set_cwd
|
||||
shell_escape
|
||||
shell_exec
|
||||
unlink
|
||||
@@ -0,0 +1,6 @@
|
||||
Task API
|
||||
|
||||
kill
|
||||
task
|
||||
task_repeat
|
||||
task_pid
|
||||
@@ -0,0 +1,7 @@
|
||||
Time and Date Functions
|
||||
|
||||
microtime
|
||||
time
|
||||
date
|
||||
gmdate
|
||||
parse_time
|
||||
@@ -0,0 +1,5 @@
|
||||
Types
|
||||
|
||||
DTree
|
||||
String
|
||||
StringMap
|
||||
@@ -0,0 +1,7 @@
|
||||
URI Functions
|
||||
|
||||
encode_query
|
||||
make_session_id
|
||||
parse_query
|
||||
uri_decode
|
||||
uri_encode
|
||||
@@ -0,0 +1,12 @@
|
||||
WebSocket Functions
|
||||
|
||||
ws_close
|
||||
ws_connection_count
|
||||
ws_connection_id
|
||||
ws_connections
|
||||
ws_is_binary
|
||||
ws_message
|
||||
ws_opcode
|
||||
ws_scope
|
||||
ws_send
|
||||
ws_send_to
|
||||
@@ -0,0 +1,158 @@
|
||||
|
||||
void render_see_section(String name)
|
||||
{
|
||||
StringList lines = split(file_get_contents("areas/"+name+".txt"), "\n");
|
||||
s32 idx = 0;
|
||||
for(auto line : lines)
|
||||
{
|
||||
if(idx == 0)
|
||||
{
|
||||
<><h3><?= line ?></h3><ul></>
|
||||
}
|
||||
else if(line != "")
|
||||
{
|
||||
<><li><a href="index.uce?p=<?= uri_encode(line) ?>"><?= line ?><span style="opacity:0.5">()</span></a></li></>
|
||||
}
|
||||
idx += 1;
|
||||
}
|
||||
<></ul></>
|
||||
}
|
||||
|
||||
|
||||
RENDER(Request& context)
|
||||
{
|
||||
|
||||
String page = first(context.get["p"], "index");
|
||||
|
||||
<><html>
|
||||
<head>
|
||||
<link rel="stylesheet" href='style.css?v=<?= time() ?>'></link>
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
<a href="index.uce">UCE Docs</a>:
|
||||
<?= page ?>
|
||||
</h1>
|
||||
<?
|
||||
|
||||
if(page == "index")
|
||||
{
|
||||
?><div style="display:flex;"><?
|
||||
?><div style="flex:1"><?
|
||||
?><h3>All API Functions</h3><?
|
||||
for(auto file_name : ls("pages/"))
|
||||
{
|
||||
String ft = nibble(file_name, ".");
|
||||
if(ft.substr(0, 2) == "0_")
|
||||
{
|
||||
String fn = ft;
|
||||
String pre = nibble(fn, "_");
|
||||
?>
|
||||
<div><a href="?p=<?= uri_encode(ft) ?>"><?= fn ?></a><span style="opacity:0.5"> : struct</span></div>
|
||||
<?
|
||||
}
|
||||
else if(ft.substr(0, 2) == "1_")
|
||||
{
|
||||
String fn = ft;
|
||||
String pre = nibble(fn, "_");
|
||||
?>
|
||||
<div><a href="?p=<?= uri_encode(ft) ?>"><?= fn ?></a><span style="opacity:0.5"> : directive</span></div>
|
||||
<?
|
||||
}
|
||||
else
|
||||
{
|
||||
?>
|
||||
<div><a href="?p=<?= uri_encode(ft) ?>"><?= ft ?><span style="opacity:0.5">()</span></a></div>
|
||||
<?
|
||||
}
|
||||
}
|
||||
?></div><?
|
||||
?><div style="flex:1"><?
|
||||
for(auto file_name : ls("areas/"))
|
||||
{
|
||||
String ft = nibble(file_name, ".");
|
||||
render_see_section(ft);
|
||||
}
|
||||
?></div><?
|
||||
?></div><?
|
||||
}
|
||||
else
|
||||
{
|
||||
auto doc = split(file_get_contents("pages/"+page+".txt"), "\n");
|
||||
String layout_class = "text";
|
||||
u32 line_idx = 0;
|
||||
for(auto s : doc)
|
||||
{
|
||||
line_idx++;
|
||||
if(s == "")
|
||||
{
|
||||
|
||||
}
|
||||
else if(s.substr(0, 1) == ":")
|
||||
{
|
||||
layout_class = s.substr(1);
|
||||
if(line_idx > 1)
|
||||
{
|
||||
?></div><?
|
||||
}
|
||||
?><div class="<?= layout_class ?>"><?
|
||||
if(layout_class == "params")
|
||||
{
|
||||
?><h3>Parameters</h3><?
|
||||
}
|
||||
else if(layout_class == "sig")
|
||||
{
|
||||
?><h3>Signature</h3><?
|
||||
}
|
||||
else if(layout_class == "pre")
|
||||
{
|
||||
layout_class = "sig";
|
||||
}
|
||||
else if(layout_class == "desc")
|
||||
{
|
||||
?><h3>Description</h3><?
|
||||
}
|
||||
else if(layout_class == "see")
|
||||
{
|
||||
/*?><h3>Related</h3><?*/
|
||||
}
|
||||
else
|
||||
{
|
||||
?><h3><?= layout_class ?></h3><?
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(s.substr(0, 1) == "-")
|
||||
{
|
||||
nibble(s, "-");
|
||||
?><li><?= (s) ?></li><?
|
||||
}
|
||||
else if(layout_class == "params")
|
||||
{
|
||||
?><div><b><?= trim(nibble(s, ":")) ?></b> : <?= trim(s) ?></div><?
|
||||
}
|
||||
else if(layout_class == "see")
|
||||
{
|
||||
if(s[0] == '>')
|
||||
{
|
||||
render_see_section(s.substr(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
?><div><a href="index.uce?p=<?= trim(s) ?>"><?= trim(s) ?><span style="opacity:0.5">()</span></a></div><?
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
?><div><? print(s); ?></div><?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html></>
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
:sig
|
||||
Request& context;
|
||||
|
||||
:ServerState* server
|
||||
Contains the current server state
|
||||
|
||||
:StringMap params
|
||||
All FastCGI server parameters
|
||||
|
||||
:StringMap get
|
||||
The current request's GET variables
|
||||
|
||||
:StringMap post
|
||||
The current request's POST variables
|
||||
|
||||
:StringMap cookies
|
||||
Cookies that have been transmitted by the browser
|
||||
|
||||
:StringMap session
|
||||
The current session
|
||||
|
||||
:String session_id
|
||||
ID of the session cookie
|
||||
|
||||
:String session_name
|
||||
Name of the session cookie
|
||||
|
||||
:DTree var
|
||||
Variable user-defined data
|
||||
|
||||
:DTree call
|
||||
Invocation or message-local structured data
|
||||
|
||||
:DTree connection
|
||||
Broker-owned per-WebSocket-connection state. Inside `WS(Request& context)`, updates to this tree persist for the lifetime of that socket connection.
|
||||
|
||||
:std::vector<UploadedFile> uploaded_files
|
||||
Files that have been uploaded in the current request
|
||||
|
||||
:StringMap header
|
||||
Headers to be sent back to the browser
|
||||
|
||||
:StringList set_cookies;
|
||||
Cookies that should be sent back to the browser
|
||||
|
||||
:u64 random_seed
|
||||
The current request's "random" noise generator seed
|
||||
|
||||
:u64 random_index
|
||||
The current request's "random" noise generator index position
|
||||
|
||||
:bool flags.log_request
|
||||
Whether the request should be logged
|
||||
|
||||
:Stats
|
||||
u32 stats.bytes_written
|
||||
f64 stats.time_init
|
||||
f64 stats.time_start
|
||||
f64 stats.time_end
|
||||
|
||||
:render_file(String file_name, [Request& context])
|
||||
Invokes another UCE file using the current or supplied request context
|
||||
|
||||
:see
|
||||
>types
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
:sig
|
||||
RENDER(Request& context)
|
||||
|
||||
:desc
|
||||
Defines the main HTTP render handler for the current `.uce` page.
|
||||
|
||||
When a page is requested over HTTP, the runtime loads the target file and calls its `RENDER(Request& context)` function.
|
||||
|
||||
Pages may also export additional named render handlers with `RENDER:NAME(Request& context)`.
|
||||
|
||||
Named render handlers are not used for the page's direct HTTP entrypoint. They are intended for component-style sub-rendering through helpers such as `component("components/card:BODY", props, context)` or `render_component("components/card:BODY", props, context)`.
|
||||
|
||||
The default page entrypoint is always the plain `RENDER(Request& context)` handler.
|
||||
|
||||
The request environment is passed explicitly through `context`, including params, cookies, post data, session state, headers, uploaded files, and the current `context.call` tree.
|
||||
|
||||
For a normal direct page request, `context.call` starts empty.
|
||||
|
||||
If the page is invoked from another UCE file via `render_file(file_name, context)`, the callee receives that same `context`.
|
||||
|
||||
Pages intended to serve WebSocket traffic may expose both `RENDER(Request& context)` and `WS(Request& context)`. In that case `RENDER(Request& context)` serves the initial HTTP response and `WS(Request& context)` handles subsequent WebSocket messages.
|
||||
|
||||
:see
|
||||
>ob
|
||||
@@ -0,0 +1,26 @@
|
||||
:sig
|
||||
WS(Request& context)
|
||||
|
||||
:desc
|
||||
Defines the WebSocket message handler for the current `.ws.uce` page.
|
||||
|
||||
The same page may expose both `RENDER(Request& context)` and `WS(Request& context)`. `RENDER(Request& context)` serves the initial HTTP response, while `WS(Request& context)` is called whenever a complete WebSocket message arrives for that page.
|
||||
|
||||
UCE reassembles fragmented messages before calling `WS(Request& context)`. Text and binary frames are both delivered. Use `context.call`, `context.connection`, `ws_opcode()`, and `ws_is_binary()` to inspect the current message.
|
||||
|
||||
`context.connection` is a broker-owned `DTree` for the current socket. It starts empty for a new client and persists across later `WS(Request& context)` calls on that same connection.
|
||||
|
||||
The current message data is available in `context.call`:
|
||||
|
||||
context.call["message"] : current message payload
|
||||
|
||||
context.call["connection_id"] : sender connection ID
|
||||
|
||||
context.call["scope"] : current endpoint scope
|
||||
|
||||
context.call["opcode"] : WebSocket opcode of the current message
|
||||
|
||||
context.call["document_uri"] : request URI of the current endpoint
|
||||
|
||||
:see
|
||||
>websocket
|
||||
@@ -0,0 +1,95 @@
|
||||
:sig
|
||||
UCE source preprocessing
|
||||
|
||||
:desc
|
||||
UCE runs a small custom source-to-source preprocessor before Clang sees a `.uce` or `.ws.uce` file.
|
||||
|
||||
The implementation lives in `src/lib/compiler.cpp`. It does not try to parse all of C++. Instead, it performs a narrow character-wise rewrite that understands UCE literal blocks, inline code islands, `#load`, and `EXPORT` harvesting, then writes a generated `.cpp` file and compiles that file into a shared object.
|
||||
|
||||
:Syntax
|
||||
- `<> ... </>` enters literal-output mode.
|
||||
- Inside a literal block, `<? ... ?>` emits raw C++.
|
||||
- Inside a literal block, `<?= expression ?>` emits `print(html_escape(expression));`.
|
||||
- Inside a literal block, `<?: expression ?>` emits `print(expression);` without HTML escaping.
|
||||
- `#load "other.uce"` injects another UCE unit at compile time.
|
||||
- `RENDER(Request& context)` and `WS(Request& context)` are normal C++ macros from `src/lib/compiler.h`.
|
||||
- `EXPORT` is also a normal C++ macro, but the custom pass additionally records exported declarations for metadata.
|
||||
|
||||
:Pipeline
|
||||
- The generated file starts by including `COMPILER_SYS_PATH/src/lib/uce_lib.h`.
|
||||
- It then inlines the configured setup template from `SETUP_TEMPLATE` (by default `scripts/setup.h.template`), which defines `set_current_request(Request*)`.
|
||||
- It inserts `#line 1` before page code so compiler diagnostics point back to the original `.uce` file.
|
||||
- Each literal block is rewritten into one or more `print(R"( ... )");` calls.
|
||||
- `<? ... ?>` temporarily breaks out of literal printing, emits the enclosed C++ unchanged, then resumes literal output.
|
||||
- `<?= ... ?>` becomes `print(html_escape(...));`. The runtime currently provides `html_escape()` overloads for `String`, `u64`, and `f64`.
|
||||
- `<?: ... ?>` becomes `print(...);` and is intended for trusted markup or already-escaped content.
|
||||
- `#load "file.uce"` is replaced with a generated C++ `#include` that points at the loaded unit's preprocessed `.cpp` file under `BIN_DIRECTORY`.
|
||||
- Lines beginning with `EXPORT` are scanned so their declarations can be written to a sibling `.exports.txt` file.
|
||||
- The final generated source is written to `BIN_DIRECTORY + src_path + "/" + source_file + ".cpp"`.
|
||||
- `scripts/compile` then compiles that generated `.cpp` into `source_file + ".so"` with `clang++ -shared -std=c++20 ...`.
|
||||
|
||||
:GeneratedFiles
|
||||
- Source file: `/some/path/page.uce`
|
||||
- Generated C++: `BIN_DIRECTORY/some/path/page.uce.cpp`
|
||||
- Shared object: `BIN_DIRECTORY/some/path/page.uce.so`
|
||||
- Export list: `BIN_DIRECTORY/some/path/page.uce.exports.txt`
|
||||
|
||||
:Example
|
||||
Example 1: literal output with escaped data
|
||||
`RENDER(Request& context)`
|
||||
`{`
|
||||
` <><h1><?= context.params["DOCUMENT_URI"] ?></h1></>`
|
||||
`}`
|
||||
|
||||
Roughly becomes:
|
||||
`print(R"(<h1>)");`
|
||||
`print(html_escape(context.params["DOCUMENT_URI"]));`
|
||||
`print(R"(</h1>)");`
|
||||
|
||||
Example 1b: literal output with trusted unescaped markup
|
||||
`RENDER(Request& context)`
|
||||
`{`
|
||||
` <><div class="panel"><?: component("components/card", context.call, context) ?></div></>`
|
||||
`}`
|
||||
|
||||
Roughly becomes:
|
||||
`print(R"(<div class="panel">)");`
|
||||
`print(component("components/card", context.call, context));`
|
||||
`print(R"(</div>)");`
|
||||
|
||||
Example 2: compile-time composition
|
||||
`#load "partials/nav.uce"`
|
||||
`RENDER(Request& context)`
|
||||
`{`
|
||||
` <><body>...</body></>`
|
||||
`}`
|
||||
|
||||
The loaded file is resolved relative to the current source file unless the path is already absolute.
|
||||
|
||||
:Rules
|
||||
- Literal mode starts only on the exact token `<>`.
|
||||
- Literal mode ends only on the exact token `</>`.
|
||||
- `#load` is recognized only when the current line starts with `#load ` at column 1.
|
||||
- `EXPORT` harvesting likewise only triggers when the current line starts with `EXPORT` at column 1 and is followed by whitespace.
|
||||
- Relative `#load` paths are expanded against the including unit's source directory.
|
||||
- `render_file()` and `call_file()` are runtime APIs; `#load` is a compile-time include/composition feature.
|
||||
|
||||
:Limitations
|
||||
- This pass is character-wise, not a full parser.
|
||||
- Outside literal blocks it only tracks double-quoted C++ strings while deciding whether `<>` should open literal mode.
|
||||
- It does not understand comments, raw string literals, templates, or general C++ token structure.
|
||||
- Inside literal blocks it tracks single and double quotes while scanning a `<? ... ?>` island so quoted `?>` text does not close the island early.
|
||||
- Literal blocks are not nested.
|
||||
- Because literal output is emitted as a C++ raw string literal `R"( ... )"`, literal content must not contain the exact terminator sequence `)"` or the generated C++ will break.
|
||||
- `#load` depends on the target unit's generated `.cpp` existing and being compilable. If the target cannot be preprocessed or compiled correctly, the including file will fail to compile as well.
|
||||
|
||||
:Debugging
|
||||
- When a page is compiled, inspect the generated file under `BIN_DIRECTORY` first. That file shows the exact C++ produced by the UCE preprocessor.
|
||||
- Compiler errors usually point back to the `.uce` source because the preprocessor inserts `#line 1`, but the generated `.cpp` is still the best place to inspect expansion problems.
|
||||
- If a `#load` include looks wrong, check the current file's directory, the configured `BIN_DIRECTORY`, and whether the loaded page already produced its own generated `.cpp`.
|
||||
|
||||
:see
|
||||
load
|
||||
render_file
|
||||
call_file
|
||||
0_context
|
||||
@@ -0,0 +1,27 @@
|
||||
:sig
|
||||
DTree
|
||||
|
||||
:desc
|
||||
Dynamic tree/container type used throughout UCE for structured data.
|
||||
|
||||
`DTree` can hold a `String`, `f64`, `bool`, pointer, or a nested map of child `DTree` values.
|
||||
|
||||
Use `t["key"]` to access or create child entries. Use `push()` / `pop()` when treating it like an array-like container with numeric string keys.
|
||||
|
||||
Common uses include:
|
||||
`json_decode()` / `json_encode()`
|
||||
`context.var`
|
||||
`context.call`
|
||||
`call_file()` return values
|
||||
|
||||
Useful methods include:
|
||||
`to_string()`
|
||||
`to_json()`
|
||||
`get_type_name()`
|
||||
`set_bool()`
|
||||
`remove()`
|
||||
`clear()`
|
||||
`each()`
|
||||
|
||||
:see
|
||||
>types
|
||||
@@ -0,0 +1,16 @@
|
||||
:sig
|
||||
String
|
||||
|
||||
:desc
|
||||
Primary string type used throughout UCE.
|
||||
|
||||
`String` is an alias for `std::string`.
|
||||
|
||||
It is used for request data, headers, cookie values, file contents, query strings, JSON text, and WebSocket payloads.
|
||||
|
||||
Because it is backed by `std::string`, it is binary-safe and may also contain raw bytes.
|
||||
|
||||
For UTF-8-aware splitting, use helpers such as `split_utf8()` instead of assuming one byte equals one character.
|
||||
|
||||
:see
|
||||
>types
|
||||
@@ -0,0 +1,22 @@
|
||||
:sig
|
||||
StringMap
|
||||
|
||||
:desc
|
||||
Associative container mapping `String` keys to `String` values.
|
||||
|
||||
`StringMap` is an alias for `std::map<String, String>`.
|
||||
|
||||
It is commonly used for:
|
||||
`context.params`
|
||||
`context.get`
|
||||
`context.post`
|
||||
`context.cookies`
|
||||
`context.session`
|
||||
`context.header`
|
||||
|
||||
Because it uses `std::map`, `map["key"]` will create an empty entry when that key does not already exist.
|
||||
|
||||
Related helpers such as `parse_query()` and `encode_query()` convert between query strings and `StringMap` values.
|
||||
|
||||
:see
|
||||
>types
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
String basename(String fn)
|
||||
|
||||
:params
|
||||
fn : raw filename
|
||||
return value : the file's name
|
||||
|
||||
:desc
|
||||
Isolates the file name component from a path/file name.
|
||||
|
||||
:see
|
||||
>sys
|
||||
@@ -0,0 +1,23 @@
|
||||
:sig
|
||||
DTree* call_file(String file_name, String function_name, DTree* call_param = null)
|
||||
|
||||
:params
|
||||
file_name : UCE file to load and execute
|
||||
function_name : name of the function to invoke
|
||||
call_param : optional, call parameter
|
||||
return value : DTree* returned from function
|
||||
|
||||
:desc
|
||||
Calls a function inside a UCE file.
|
||||
|
||||
:Example
|
||||
// export a function
|
||||
EXPORT void test_func()
|
||||
{
|
||||
print("HELLO FROM TEST FUNCTION");
|
||||
}
|
||||
// use that function in another file
|
||||
call_file("call_file_funcs.uce", "test_func");
|
||||
|
||||
:see
|
||||
>ob
|
||||
@@ -0,0 +1,28 @@
|
||||
:sig
|
||||
String component(String name, [DTree props], [Request& context])
|
||||
|
||||
:desc
|
||||
Renders another `.uce` file as a component and returns the captured output as a `String`.
|
||||
|
||||
`component()` resolves the target file relative to the current page and also tries the `components/` prefix automatically, mirroring the shorthand used by the web app starter example project.
|
||||
|
||||
Component props are passed in `context.call`.
|
||||
|
||||
Because `<?= ... ?>` HTML-escapes its value, embed component markup with `<?: component(...) ?>`, `print(component(...))`, or use `render_component(...)` for direct output.
|
||||
|
||||
When `name` contains a colon, such as `components/card:BODY`, the part after the colon selects a named render handler exported from the component file through `RENDER:BODY(Request& context)`.
|
||||
|
||||
The default handler is `RENDER(Request& context)`.
|
||||
|
||||
Resolution order is:
|
||||
exact file name
|
||||
exact file name with `.uce`
|
||||
the same two forms under `components/`
|
||||
|
||||
Example:
|
||||
`DTree props;`
|
||||
`props["title"] = "Status";`
|
||||
`<><?: component("workspace/panel", props, context) ?></>`
|
||||
|
||||
:see
|
||||
>ob
|
||||
@@ -0,0 +1,14 @@
|
||||
:sig
|
||||
bool component_exists(String name)
|
||||
|
||||
:desc
|
||||
Checks whether a component file can be resolved from the current page context.
|
||||
|
||||
Resolution tries the exact name first and then the `components/` shorthand form.
|
||||
|
||||
If `name` contains a colon, only the file portion is used for existence checks.
|
||||
|
||||
This is useful when a page wants to render an optional component if it is present without hard-failing when it is missing.
|
||||
|
||||
:see
|
||||
>ob
|
||||
@@ -0,0 +1,14 @@
|
||||
:sig
|
||||
String component_resolve(String name)
|
||||
|
||||
:desc
|
||||
Resolves a component name to the concrete `.uce` file path that will be loaded.
|
||||
|
||||
Resolution tries the exact file name first, then the same name with `.uce` appended, and then the same two forms under the `components/` prefix.
|
||||
|
||||
If `name` contains a colon, only the file portion is used for resolution.
|
||||
|
||||
This is primarily a debugging helper so you can see which concrete file a shorthand component name maps to.
|
||||
|
||||
:see
|
||||
>ob
|
||||
@@ -0,0 +1,11 @@
|
||||
:sig
|
||||
String concat(...vals)
|
||||
|
||||
:params
|
||||
...val : one or more values that should be concatenated
|
||||
|
||||
:desc
|
||||
Returns a string with all the parameters concatenated into one.
|
||||
|
||||
:see
|
||||
>string
|
||||
@@ -0,0 +1,125 @@
|
||||
:sig
|
||||
String date(String format = "", u64 timestamp = 0)
|
||||
|
||||
:params
|
||||
format : formatting string specifying the date format
|
||||
timestamp : optional timestamp value, defaults to current time
|
||||
return value : a formatted date
|
||||
|
||||
:desc
|
||||
Returns a formatted date. This is based on the Linux date() command. The formatting string supports the following sequences:
|
||||
:pre
|
||||
%% a literal %
|
||||
|
||||
%a locale's abbreviated weekday name (e.g., Sun)
|
||||
|
||||
%A locale's full weekday name (e.g., Sunday)
|
||||
|
||||
%b locale's abbreviated month name (e.g., Jan)
|
||||
|
||||
%B locale's full month name (e.g., January)
|
||||
|
||||
%c locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
|
||||
|
||||
%C century; like %Y, except omit last two digits (e.g., 20)
|
||||
|
||||
%d day of month (e.g., 01)
|
||||
|
||||
%D date; same as %m/%d/%y
|
||||
|
||||
%e day of month, space padded; same as %_d
|
||||
|
||||
%F full date; like %+4Y-%m-%d
|
||||
|
||||
%g last two digits of year of ISO week number (see %G)
|
||||
|
||||
%G year of ISO week number (see %V); normally useful only
|
||||
with %V
|
||||
|
||||
%h same as %b
|
||||
|
||||
%H hour (00..23)
|
||||
|
||||
%I hour (01..12)
|
||||
|
||||
%j day of year (001..366)
|
||||
|
||||
%k hour, space padded ( 0..23); same as %_H
|
||||
|
||||
%l hour, space padded ( 1..12); same as %_I
|
||||
|
||||
%m month (01..12)
|
||||
|
||||
%M minute (00..59)
|
||||
|
||||
%n a newline
|
||||
|
||||
%N nanoseconds (000000000..999999999)
|
||||
|
||||
%p locale's equivalent of either AM or PM; blank if not known
|
||||
|
||||
%P like %p, but lower case
|
||||
|
||||
%q quarter of year (1..4)
|
||||
|
||||
%r locale's 12-hour clock time (e.g., 11:11:04 PM)
|
||||
|
||||
%R 24-hour hour and minute; same as %H:%M
|
||||
|
||||
%s seconds since 1970-01-01 00:00:00 UTC
|
||||
|
||||
%S second (00..60)
|
||||
|
||||
%t a tab
|
||||
|
||||
%T time; same as %H:%M:%S
|
||||
|
||||
%u day of week (1..7); 1 is Monday
|
||||
|
||||
%U week number of year, with Sunday as first day of week
|
||||
(00..53)
|
||||
|
||||
%V ISO week number, with Monday as first day of week (01..53)
|
||||
|
||||
%w day of week (0..6); 0 is Sunday
|
||||
|
||||
%W week number of year, with Monday as first day of week
|
||||
(00..53)
|
||||
|
||||
%x locale's date representation (e.g., 12/31/99)
|
||||
|
||||
%X locale's time representation (e.g., 23:13:48)
|
||||
|
||||
%y last two digits of year (00..99)
|
||||
|
||||
%Y year
|
||||
|
||||
%z +hhmm numeric time zone (e.g., -0400)
|
||||
|
||||
%:z +hh:mm numeric time zone (e.g., -04:00)
|
||||
|
||||
%::z +hh:mm:ss numeric time zone (e.g., -04:00:00)
|
||||
|
||||
%:::z numeric time zone with : to necessary precision (e.g.,
|
||||
-04, +05:30)
|
||||
|
||||
%Z alphabetic time zone abbreviation (e.g., EDT)
|
||||
|
||||
By default, date pads numeric fields with zeroes. The following
|
||||
optional flags may follow '%':
|
||||
|
||||
- (hyphen) do not pad the field
|
||||
|
||||
_ (underscore) pad with spaces
|
||||
|
||||
0 (zero) pad with zeros
|
||||
|
||||
+ pad with zeros, and put '+' before future years with >4
|
||||
digits
|
||||
|
||||
^ use upper case if possible
|
||||
|
||||
# use opposite case if possible
|
||||
|
||||
:see
|
||||
>time
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
String dirname(String fn)
|
||||
|
||||
:params
|
||||
fn : raw filename
|
||||
return value : the directory's name
|
||||
|
||||
:desc
|
||||
Isolates the directory name component from a path/file name.
|
||||
|
||||
:see
|
||||
>sys
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
f64 draw_float(f64 from, f64 to)
|
||||
|
||||
:params
|
||||
from : minimum value
|
||||
to : maximum value
|
||||
return value : a noise value between 'from' and 'to'
|
||||
|
||||
:desc
|
||||
This function works exactly like generate_float(), but context.random_index is used for the 'index' value and context.random_seed is used for the seed. After this function has been called, the context.random_index is increased by one. At the start of every request, context.random_seed is automatically populated with a new seed value.
|
||||
|
||||
:see
|
||||
>noise
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
u64 draw_int(u64 from, u64 to)
|
||||
|
||||
:params
|
||||
from : minimum value
|
||||
to : maximum value
|
||||
return value : a noise value between 'from' and 'to'
|
||||
|
||||
:desc
|
||||
This function works exactly like generate_int(), but context.random_index is used for the 'index' value and context.random_seed is used for the seed. After this function has been called, the context.random_index is increased by one. At the start of every request, context.random_seed is automatically populated with a new seed value.
|
||||
|
||||
:see
|
||||
>noise
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
String encode_query(StringMap map)
|
||||
|
||||
:params
|
||||
q : StringMap containing URL parameters to be encoded
|
||||
return value : a string with the encoded parameters
|
||||
|
||||
:desc
|
||||
Encodes a StringMap containing URL parameters into a single String.
|
||||
|
||||
:see
|
||||
>uri
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
String expand_path(String path, String relative_to_path = "")
|
||||
|
||||
:params
|
||||
path : a relative path
|
||||
relative_to_path : optional, expand relative to this path (if not given, the current path is used)
|
||||
return value : expanded version of the 'path'
|
||||
|
||||
:desc
|
||||
Converts a relative path name into an absolute path, using the current working directory as a base.
|
||||
|
||||
:see
|
||||
>sys
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
void file_append(String file_name, ...val)
|
||||
|
||||
:params
|
||||
file_name : file name of file that should be written to
|
||||
...val : one or more values that should be written into the file
|
||||
|
||||
:desc
|
||||
Opens or creates a given file and appends data to it.
|
||||
|
||||
:see
|
||||
>sys
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
bool file_exists(String path)
|
||||
|
||||
:params
|
||||
path : the path name to be checked
|
||||
return value : true if the file exists
|
||||
|
||||
:desc
|
||||
Checks whether the file or path specified by 'path' exists.
|
||||
|
||||
:see
|
||||
>sys
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
String file_get_contents(String file_name)
|
||||
|
||||
:params
|
||||
file_name : file name of file that should be read
|
||||
return value : String containing the file's contents
|
||||
|
||||
:desc
|
||||
Reads the file identified by 'file_name' and returns it as a String. If the file cannot be read, this function will return an empty string.
|
||||
|
||||
:see
|
||||
>sys
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
time_t file_mtime(String file_name)
|
||||
|
||||
:params
|
||||
file_name : name of the file
|
||||
return value : Unix time stamp of the file's last modification
|
||||
|
||||
:desc
|
||||
Retrieves the last modification date of 'file_name' as a Unix timestamp.
|
||||
|
||||
:see
|
||||
>sys
|
||||
>time
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
bool file_put_contents(String file_name, String content)
|
||||
|
||||
:params
|
||||
file_name : file name of file that should be written
|
||||
content : content that should be written
|
||||
return value : true if write was successful
|
||||
|
||||
:desc
|
||||
Writes the String 'content' into a file identified by 'file_name'. Any pre-existing content of the file will be overwritten.
|
||||
|
||||
:see
|
||||
>sys
|
||||
@@ -0,0 +1,14 @@
|
||||
:sig
|
||||
StringList filter(StringList items, function<bool (String)> f)
|
||||
vector<T> filter(vector<T> items, function<bool (T)> f)
|
||||
|
||||
:params
|
||||
items : list of items to be filtered
|
||||
f : a function that decides which items should be in the new list
|
||||
return value : a new list
|
||||
|
||||
:desc
|
||||
Returns a list containing the members of 'items' for which 'f' returned boolean true.
|
||||
|
||||
:see
|
||||
>string
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
String first(String... args)
|
||||
|
||||
:params
|
||||
args : a variable number of String arguments
|
||||
return value : first of the 'args' that was not empty.
|
||||
|
||||
:desc
|
||||
Given a variable number of String parameters, the first() function returns the first of these parameters that was not empty. Leading and trailing whitespace characters are not considered, resulting in a string that contains only whitespace characters being considered empty.
|
||||
|
||||
:see
|
||||
>string
|
||||
@@ -0,0 +1,10 @@
|
||||
:sig
|
||||
f64 float_val(String s)
|
||||
|
||||
:params
|
||||
s : string to be converted
|
||||
return value : a f64 containing the number (0 if no number could be identified).
|
||||
|
||||
:desc
|
||||
Extracts a floating point number from a String.
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
:sig
|
||||
f64 generate_float(f64 from, f64 to, u64 index, u64 seed = 0)
|
||||
|
||||
:params
|
||||
from : minimum result
|
||||
to : maximum result
|
||||
index : index position to generate number from
|
||||
seed : seed position to generate number from (defaults to 0)
|
||||
return value : noise value
|
||||
|
||||
:desc
|
||||
Generates a noise value between 'from' and 'to', given the 'index' and 'seed' numbers.
|
||||
|
||||
|
||||
:see
|
||||
>noise
|
||||
@@ -0,0 +1,16 @@
|
||||
:sig
|
||||
u64 generate_int(u64 from, u64 to, u64 index, u64 seed = 0)
|
||||
|
||||
:params
|
||||
from : minimum result
|
||||
to : maximum result
|
||||
index : index position to generate number from
|
||||
seed : seed position to generate number from (defaults to 0)
|
||||
return value : noise value
|
||||
|
||||
:desc
|
||||
Generates a noise value between 'from' and 'to', given the 'index' and 'seed' numbers.
|
||||
|
||||
|
||||
:see
|
||||
>noise
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
u32 noise01(u64 index, u64 seed = 0)
|
||||
|
||||
:params
|
||||
index : index position
|
||||
seed : seed set (defaults to 0)
|
||||
return value : a noise value from 0 to 1
|
||||
|
||||
:desc
|
||||
Generates a noise value in the range from 0 to 1 for the given 'index' and 'seed' values.
|
||||
|
||||
:see
|
||||
>noise
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
u32 noise32(u32 index, u32 seed = 0)
|
||||
|
||||
:params
|
||||
index : index position
|
||||
seed : seed set (defaults to 0)
|
||||
return value : a noise value given the 'index' and 'seed' values.
|
||||
|
||||
:desc
|
||||
Generates a noise value for the given 'index' and 'seed' values.
|
||||
|
||||
:see
|
||||
>noise
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
u32 noise64(u64 index, u64 seed = 0)
|
||||
|
||||
:params
|
||||
index : index position
|
||||
seed : seed set (defaults to 0)
|
||||
return value : a noise value given the 'index' and 'seed' values.
|
||||
|
||||
:desc
|
||||
Generates a noise value for the given 'index' and 'seed' values.
|
||||
|
||||
:see
|
||||
>noise
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
String sha1(String s, bool as_binary = false)
|
||||
|
||||
:params
|
||||
s : data to be hashed
|
||||
as_binary : when set to false, returns hash in hexadecimal notation (defaults to false)
|
||||
return value : the resulting hash value
|
||||
|
||||
:desc
|
||||
Returns the sha1 hash of 's'.
|
||||
|
||||
:see
|
||||
>noise
|
||||
@@ -0,0 +1,11 @@
|
||||
:sig
|
||||
String get_cwd()
|
||||
|
||||
:params
|
||||
return value : the current working directory
|
||||
|
||||
:desc
|
||||
Returns the current working directory.
|
||||
|
||||
:see
|
||||
>sys
|
||||
@@ -0,0 +1,125 @@
|
||||
:sig
|
||||
String gmdate(String format = "", u64 timestamp = 0)
|
||||
|
||||
:params
|
||||
format : formatting string specifying the date format
|
||||
timestamp : optional timestamp value, defaults to current time
|
||||
return value : a formatted date
|
||||
|
||||
:desc
|
||||
Returns a formatted date in the GMT/UTC timezone. This is based on the Linux date() command. The formatting string supports the following sequences:
|
||||
:pre
|
||||
%% a literal %
|
||||
|
||||
%a locale's abbreviated weekday name (e.g., Sun)
|
||||
|
||||
%A locale's full weekday name (e.g., Sunday)
|
||||
|
||||
%b locale's abbreviated month name (e.g., Jan)
|
||||
|
||||
%B locale's full month name (e.g., January)
|
||||
|
||||
%c locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
|
||||
|
||||
%C century; like %Y, except omit last two digits (e.g., 20)
|
||||
|
||||
%d day of month (e.g., 01)
|
||||
|
||||
%D date; same as %m/%d/%y
|
||||
|
||||
%e day of month, space padded; same as %_d
|
||||
|
||||
%F full date; like %+4Y-%m-%d
|
||||
|
||||
%g last two digits of year of ISO week number (see %G)
|
||||
|
||||
%G year of ISO week number (see %V); normally useful only
|
||||
with %V
|
||||
|
||||
%h same as %b
|
||||
|
||||
%H hour (00..23)
|
||||
|
||||
%I hour (01..12)
|
||||
|
||||
%j day of year (001..366)
|
||||
|
||||
%k hour, space padded ( 0..23); same as %_H
|
||||
|
||||
%l hour, space padded ( 1..12); same as %_I
|
||||
|
||||
%m month (01..12)
|
||||
|
||||
%M minute (00..59)
|
||||
|
||||
%n a newline
|
||||
|
||||
%N nanoseconds (000000000..999999999)
|
||||
|
||||
%p locale's equivalent of either AM or PM; blank if not known
|
||||
|
||||
%P like %p, but lower case
|
||||
|
||||
%q quarter of year (1..4)
|
||||
|
||||
%r locale's 12-hour clock time (e.g., 11:11:04 PM)
|
||||
|
||||
%R 24-hour hour and minute; same as %H:%M
|
||||
|
||||
%s seconds since 1970-01-01 00:00:00 UTC
|
||||
|
||||
%S second (00..60)
|
||||
|
||||
%t a tab
|
||||
|
||||
%T time; same as %H:%M:%S
|
||||
|
||||
%u day of week (1..7); 1 is Monday
|
||||
|
||||
%U week number of year, with Sunday as first day of week
|
||||
(00..53)
|
||||
|
||||
%V ISO week number, with Monday as first day of week (01..53)
|
||||
|
||||
%w day of week (0..6); 0 is Sunday
|
||||
|
||||
%W week number of year, with Monday as first day of week
|
||||
(00..53)
|
||||
|
||||
%x locale's date representation (e.g., 12/31/99)
|
||||
|
||||
%X locale's time representation (e.g., 23:13:48)
|
||||
|
||||
%y last two digits of year (00..99)
|
||||
|
||||
%Y year
|
||||
|
||||
%z +hhmm numeric time zone (e.g., -0400)
|
||||
|
||||
%:z +hh:mm numeric time zone (e.g., -04:00)
|
||||
|
||||
%::z +hh:mm:ss numeric time zone (e.g., -04:00:00)
|
||||
|
||||
%:::z numeric time zone with : to necessary precision (e.g.,
|
||||
-04, +05:30)
|
||||
|
||||
%Z alphabetic time zone abbreviation (e.g., EDT)
|
||||
|
||||
By default, date pads numeric fields with zeroes. The following
|
||||
optional flags may follow '%':
|
||||
|
||||
- (hyphen) do not pad the field
|
||||
|
||||
_ (underscore) pad with spaces
|
||||
|
||||
0 (zero) pad with zeros
|
||||
|
||||
+ pad with zeros, and put '+' before future years with >4
|
||||
digits
|
||||
|
||||
^ use upper case if possible
|
||||
|
||||
# use opposite case if possible
|
||||
|
||||
:see
|
||||
>time
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
String html_escape(String s)
|
||||
|
||||
:params
|
||||
s : string to be escaped
|
||||
return value : an HTML-safe escaped version of 's'
|
||||
|
||||
:desc
|
||||
Returns a version of the input string where the following characters have been replace by HTML entities:
|
||||
- & → &
|
||||
- < → lt;
|
||||
- > → >
|
||||
- " → "
|
||||
@@ -0,0 +1,11 @@
|
||||
:sig
|
||||
u64 int_val(String s, u32 base = 10)
|
||||
|
||||
:params
|
||||
s : string to be converted
|
||||
base : number system base (default 10)
|
||||
return value : a u64 containing the number (0 if no number could be identified).
|
||||
|
||||
:desc
|
||||
Extracts an integer from a String.
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
String join(StringList l, String delim = "\n")
|
||||
|
||||
:params
|
||||
l : list of strings to be joined
|
||||
delim : delimiter (defaults to newline character)
|
||||
return value : a string containing items joined by 'delim'
|
||||
|
||||
:desc
|
||||
Joins the items contained in 'l' into a single String.
|
||||
|
||||
:see
|
||||
>string
|
||||
@@ -0,0 +1,10 @@
|
||||
:sig
|
||||
DTree json_decode(String s)
|
||||
|
||||
:params
|
||||
s : string containing JSON data
|
||||
return value : a DTree object containing the deserialized JSON data
|
||||
|
||||
:desc
|
||||
Deserializes 's' into a DTree structure.
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
:sig
|
||||
String json_encode(DTree t)
|
||||
|
||||
:params
|
||||
t : DTree object to be serialized
|
||||
return value : string containing the JSON result
|
||||
|
||||
:desc
|
||||
Serializes a DTree structure 't' into a String in JSON notation.
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
:sig
|
||||
s64 kill(pid_t pid, s64 sig)
|
||||
|
||||
:params
|
||||
pid : PID of the process
|
||||
sig : signal number
|
||||
return value : 0 if signal was sent, -1 otherwise
|
||||
|
||||
:desc
|
||||
This is the standard POSIX kill() function, provided here for reference.
|
||||
|
||||
Possible signal numbers are: SIGABND, SIGABRT, SIGALRM, SIGBUS, SIGFPE, SIGHUP, SIGILL, SIGINT, SIGKILL, SIGPIPE, SIGPOLL, SIGPROF, SIGQUIT, SIGSEGV, SIGSYS, SIGTERM, SIGTRAP, SIGURG, SIGUSR1, SIGUSR2, SIGVTALRM, SIGXCPU, SIGXFSZ, SIGCHLD, SIGIO, SIGIOERR, SIGWINCH, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGCONT.
|
||||
|
||||
:see
|
||||
>task
|
||||
@@ -0,0 +1,11 @@
|
||||
:sig
|
||||
#load "myfile.uce"
|
||||
|
||||
:params
|
||||
file name : name of an UCE file that should be included
|
||||
|
||||
:desc
|
||||
Includes another UCE file
|
||||
|
||||
:see
|
||||
>ob
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
StringList ls(String path)
|
||||
|
||||
:params
|
||||
path : a filesystem path
|
||||
return value : list of directory entries
|
||||
|
||||
:desc
|
||||
Returns a list of files and subdirectories within the given 'path'.
|
||||
|
||||
:see
|
||||
>sys
|
||||
@@ -0,0 +1,11 @@
|
||||
:sig
|
||||
String make_session_id()
|
||||
|
||||
:params
|
||||
return value : a new session ID
|
||||
|
||||
:desc
|
||||
Creates a session ID
|
||||
|
||||
:see
|
||||
>session
|
||||
@@ -0,0 +1,77 @@
|
||||
:sig
|
||||
DTree markdown_to_ast(String src)
|
||||
DTree markdown_to_ast(String src, DTree options)
|
||||
|
||||
:params
|
||||
src : markdown source text
|
||||
options : optional markdown options tree
|
||||
return value : a `DTree` document AST
|
||||
|
||||
:desc
|
||||
Parses Markdown source into a structured `DTree` document tree.
|
||||
|
||||
The parser targets a practical GitHub-flavored subset by default:
|
||||
- ATX headings (`#`)
|
||||
- setext headings
|
||||
- paragraphs
|
||||
- blockquotes
|
||||
- ordered and unordered lists
|
||||
- task list items
|
||||
- fenced code blocks
|
||||
- tables
|
||||
- horizontal rules
|
||||
- emphasis / strong / strikethrough
|
||||
- links, images, autolinks, and code spans
|
||||
- `:::` directive blocks for component-based extensions
|
||||
|
||||
The returned AST uses `type` plus node-specific fields such as `level`, `text`, `lang`, `href`, `src`, `name`, `argument`, `attrs`, and `children`.
|
||||
|
||||
Top-level documents use:
|
||||
`type = "document"`
|
||||
`children = [...]`
|
||||
|
||||
Common block nodes:
|
||||
`heading`
|
||||
`paragraph`
|
||||
`blockquote`
|
||||
`list`
|
||||
`list_item`
|
||||
`code_block`
|
||||
`table`
|
||||
`directive`
|
||||
`hr`
|
||||
|
||||
Common inline nodes:
|
||||
`text`
|
||||
`code`
|
||||
`strong`
|
||||
`em`
|
||||
`strike`
|
||||
`link`
|
||||
`image`
|
||||
`raw_html`
|
||||
|
||||
:Example
|
||||
`DTree options = json_decode("{\"components\":{\":::warning\":\"components/markdown/warning\"}}");`
|
||||
`DTree ast = markdown_to_ast(file_get_contents("README.md"), options);`
|
||||
`print(json_encode(ast));`
|
||||
|
||||
:Options
|
||||
`options["gfm"]`
|
||||
Enables GitHub-style extras such as tables, task lists, strikethrough, and bare-URL autolinks.
|
||||
Defaults to true.
|
||||
|
||||
`options["allow_html"]`
|
||||
Allows raw HTML passthrough nodes to be captured and rendered.
|
||||
Defaults to false.
|
||||
|
||||
`options["components"]`
|
||||
Component hook map used later by `markdown_to_html()`.
|
||||
The parser preserves directive data needed by those hooks.
|
||||
|
||||
:see
|
||||
markdown_to_html
|
||||
component
|
||||
render_component
|
||||
json_encode
|
||||
DTree
|
||||
@@ -0,0 +1,100 @@
|
||||
:sig
|
||||
String markdown_to_html(String src)
|
||||
String markdown_to_html(String src, DTree options)
|
||||
|
||||
:params
|
||||
src : markdown source text
|
||||
options : optional markdown options tree
|
||||
return value : rendered HTML string
|
||||
|
||||
:desc
|
||||
Renders Markdown source into HTML and returns the generated markup as a `String`.
|
||||
|
||||
`markdown_to_html()` does not write to the output stream directly. This keeps it aligned with the UCE naming convention where `render_*` names are reserved for direct-output helpers.
|
||||
|
||||
Because the return value is HTML markup, embed it with `<?: markdown_to_html(...) ?>`, `print(markdown_to_html(...))`, or pass it through a component.
|
||||
|
||||
By default the function aims at a practical GitHub-flavored Markdown target, including tables, task lists, fenced code blocks, autolinks, and strikethrough.
|
||||
|
||||
:Example
|
||||
`DTree options;`
|
||||
`options["components"][":::warning"] = "components/markdown/warning";`
|
||||
`options["components"]["node.code_block"] = "components/markdown/code_block";`
|
||||
`String html = markdown_to_html(file_get_contents("guide.md"), options);`
|
||||
`print(html);`
|
||||
|
||||
:SupportedSyntax
|
||||
- headings with `#` or setext underlines
|
||||
- paragraphs
|
||||
- ordered and unordered lists
|
||||
- task lists
|
||||
- blockquotes
|
||||
- fenced code blocks
|
||||
- horizontal rules
|
||||
- tables
|
||||
- inline emphasis, strong, strikethrough, code spans
|
||||
- links, images, and bare `http://` / `https://` URLs
|
||||
- `:::name ... :::` directive blocks
|
||||
|
||||
:Options
|
||||
`options["gfm"]`
|
||||
Defaults to true.
|
||||
Turns on GitHub-style extras such as tables, task lists, autolinks, and strikethrough.
|
||||
|
||||
`options["allow_html"]`
|
||||
Defaults to false.
|
||||
When true, raw HTML blocks and inline tags may pass through as `raw_html` nodes instead of being escaped as plain text.
|
||||
|
||||
`options["components"]`
|
||||
Declares renderer extension points using normal UCE components.
|
||||
|
||||
Exact directive hooks:
|
||||
`options["components"][":::warning"] = "components/markdown/warning"`
|
||||
This hook is selected for `:::warning ... :::` blocks.
|
||||
|
||||
Generic node hooks:
|
||||
`options["components"]["node.code_block"] = "components/markdown/code_block"`
|
||||
`options["components"]["node.table"] = "components/markdown/table"`
|
||||
`options["components"]["node.link"] = "components/markdown/link"`
|
||||
`options["components"]["node.directive"] = "components/markdown/directive"`
|
||||
|
||||
If both an exact directive hook and a generic `node.directive` hook exist, the exact directive hook wins.
|
||||
|
||||
:ComponentProps
|
||||
When a markdown hook component is called, its props arrive in `context.call`.
|
||||
|
||||
Useful fields include:
|
||||
`context.call["hook"]` : matched hook key such as `:::warning` or `node.code_block`
|
||||
`context.call["target"]` : resolved component target name
|
||||
`context.call["default_html"]` : renderer output without the hook
|
||||
`context.call["children_html"]` : already-rendered child HTML
|
||||
`context.call["node"]` : full AST node
|
||||
`context.call["type"]` : node type
|
||||
`context.call["name"]` : directive name when applicable
|
||||
`context.call["argument"]` : directive remainder after the name
|
||||
`context.call["text"]` : source text for nodes such as `code_block`
|
||||
`context.call["lang"]` : fenced code language
|
||||
`context.call["href"]` / `context.call["src"]` / `context.call["title"]`
|
||||
`context.call["options"]` : full markdown options tree
|
||||
|
||||
This lets a component either replace the HTML completely or wrap `default_html` / `children_html`.
|
||||
|
||||
:DirectiveSchema
|
||||
Directive blocks use this form:
|
||||
`:::warning title="Heads up"`
|
||||
`Body markdown here`
|
||||
`:::`
|
||||
|
||||
The parser stores:
|
||||
`node["name"] = "warning"`
|
||||
`node["argument"] = ...` for bare trailing text
|
||||
`node["attrs"] = ...` for parsed `key=value` pairs such as `title="Heads up"`
|
||||
|
||||
This makes directive components a good fit for alerts, callouts, cards, embeds, and any richer page-level markdown extension.
|
||||
|
||||
:see
|
||||
markdown_to_ast
|
||||
component
|
||||
render_component
|
||||
json_decode
|
||||
String
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
String memcache_command(u64 connection, String command)
|
||||
|
||||
:params
|
||||
connection : connection handle
|
||||
command : string containing the Memcache command
|
||||
return value : string containing the Memcache server's response
|
||||
|
||||
:desc
|
||||
Executes a command on an open memcache connection.
|
||||
|
||||
:see
|
||||
>memcache
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
u64 memcache_connect(String host = "127.0.0.1", short port = 11211)
|
||||
|
||||
:params
|
||||
host : optional host name of the memcache server, defaults to local address 127.0.0.1
|
||||
port : optional memcache server's port, defaults to 11211
|
||||
return value : the connection handle (or -1 if an error occurred)
|
||||
|
||||
:desc
|
||||
Connects to a memcache server instance.
|
||||
|
||||
:see
|
||||
>memcache
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
bool memcache_delete(u64 connection, String key)
|
||||
|
||||
:params
|
||||
connection : connection handle
|
||||
key : key string
|
||||
return value : true if the operation was successful
|
||||
|
||||
:desc
|
||||
Deletes entry specified by the 'key'.
|
||||
|
||||
:see
|
||||
>memcache
|
||||
@@ -0,0 +1,14 @@
|
||||
:sig
|
||||
String memcache_get(u64 connection, String key, String default_value = "")
|
||||
|
||||
:params
|
||||
connection : connection handle
|
||||
key : key string
|
||||
default_value : optional default value
|
||||
return value : value that was returned by the Memcache server
|
||||
|
||||
:desc
|
||||
Retrieves a value from an existing connection to a Memcache server.
|
||||
|
||||
:see
|
||||
>memcache
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
StringMap memcache_get_multiple(u64 connection, StringList keys)
|
||||
|
||||
:params
|
||||
connection : connection handle
|
||||
keys : a list of strings containing the keys to be retrieved
|
||||
return value : a StringMap with the retrieved entries
|
||||
|
||||
:desc
|
||||
Retrieves a bunch of entries all at once.
|
||||
|
||||
:see
|
||||
>memcache
|
||||
@@ -0,0 +1,15 @@
|
||||
:sig
|
||||
bool memcache_set(u64 connection, String key, String value, u64 expires_in = 60*60)
|
||||
|
||||
:params
|
||||
connection : connection handle
|
||||
key : the entry's key
|
||||
value : the value to be set
|
||||
expires_in : optional expiration timeout, defaults to one hour
|
||||
return value : true if the operation was successful
|
||||
|
||||
:desc
|
||||
Stores a 'value' on the Memcache server.
|
||||
|
||||
:see
|
||||
>memcache
|
||||
@@ -0,0 +1,11 @@
|
||||
:sig
|
||||
f64 microtime()
|
||||
|
||||
:params
|
||||
return value : current Unix timestamp
|
||||
|
||||
:desc
|
||||
Returns a 64 bit float containing the current Unix timestamp with millisecond accuracy or better.
|
||||
|
||||
:see
|
||||
>time
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
bool mkdir(String path)
|
||||
|
||||
:params
|
||||
path : the path name to be created
|
||||
return value : returns true if the directory was successfully created
|
||||
|
||||
:desc
|
||||
Creates a directory stated by 'path'
|
||||
|
||||
:see
|
||||
>sys
|
||||
@@ -0,0 +1,14 @@
|
||||
:sig
|
||||
MySQL* mysql_connect(String host = "localhost", String username = "root", String password = "")
|
||||
|
||||
:params
|
||||
host : host name of the MySQL server
|
||||
username : user name
|
||||
password : password
|
||||
return value : pointer to the MySQL connection struct
|
||||
|
||||
:desc
|
||||
Establishes a connection to a MySQL server.
|
||||
|
||||
:see
|
||||
>mysql
|
||||
@@ -0,0 +1,11 @@
|
||||
:sig
|
||||
void mysql_disconnect(MySQL* m)
|
||||
|
||||
:params
|
||||
m : pointer to an existing MySQL connection struct
|
||||
|
||||
:desc
|
||||
Closes a connection to a MySQL server.
|
||||
|
||||
:see
|
||||
>mysql
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
String mysql_error(MySQL* m)
|
||||
|
||||
:params
|
||||
m : pointer to a MySQL connection struct
|
||||
return value : MySQL error message (if present, otherwise empty string)
|
||||
|
||||
:desc
|
||||
Returns the last error message from a connection to a MySQL server.
|
||||
|
||||
:see
|
||||
>mysql
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
String mysql_escape(String raw, char quote_char)
|
||||
|
||||
:params
|
||||
raw : the string to be escaped
|
||||
quote_char : the character that should be used to wrap the string (pass NULL for no wrapping)
|
||||
return value : the safe version of the 'raw' string
|
||||
|
||||
:desc
|
||||
Escapes a string such that it can be passed as a safe value into an SQL expression.
|
||||
|
||||
:see
|
||||
>mysql
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
u64 mysql_insert_id(MySQL* m)
|
||||
|
||||
:params
|
||||
m : pointer to an active MySQL connection
|
||||
return value : the last used automatic row ID
|
||||
|
||||
:desc
|
||||
This retrieves the last row ID that was used for a column with an AUTO_INCREMENT row key.
|
||||
|
||||
:see
|
||||
>mysql
|
||||
@@ -0,0 +1,17 @@
|
||||
:sig
|
||||
DTree mysql_query(MySQL* m, String q, StringMap params)
|
||||
|
||||
:params
|
||||
m : pointer to an active MySQL connection struct
|
||||
q : a string containing a MySQL query
|
||||
params : optional, a list of query parameter keys and values
|
||||
return value : a list of rows returned from executing the query
|
||||
|
||||
:desc
|
||||
Executes a MySQL query and returns the resulting data (if any).
|
||||
|
||||
:Examples
|
||||
(tbd)
|
||||
|
||||
:see
|
||||
>mysql
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
String nibble(String& haystack, String delim)
|
||||
|
||||
:params
|
||||
haystack : string to be nibbled at
|
||||
delim : delimiter
|
||||
return value : string before first occurrence of 'delim'
|
||||
|
||||
:desc
|
||||
Returns the part of 'haystack' before the first occurrence of 'delim', removing the corresponding part from 'haystack' (including 'delim'). If the substring 'delim' does not occurr in 'haystack', the entire string is returned and 'haystack' is set to an empty string.
|
||||
|
||||
:see
|
||||
>string
|
||||
@@ -0,0 +1,11 @@
|
||||
:sig
|
||||
void ob_close()
|
||||
|
||||
:params
|
||||
(none)
|
||||
|
||||
:desc
|
||||
Discard the current output buffer. If are more output buffers on the stack, switch to the next one.
|
||||
|
||||
:see
|
||||
>ob
|
||||
@@ -0,0 +1,11 @@
|
||||
:sig
|
||||
String ob_get()
|
||||
|
||||
:params
|
||||
return value : content of the current output buffer
|
||||
|
||||
:desc
|
||||
Returns the contents of the current output buffer.
|
||||
|
||||
:see
|
||||
>ob
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
String ob_get_close()
|
||||
|
||||
:params
|
||||
return value : content of the current output buffer
|
||||
|
||||
:desc
|
||||
Returns the contents of the current output buffer and then discards the buffer.
|
||||
If are more output buffers on the stack, switch to the next one.
|
||||
|
||||
:see
|
||||
>ob
|
||||
@@ -0,0 +1,11 @@
|
||||
:sig
|
||||
void ob_start()
|
||||
|
||||
:params
|
||||
(none)
|
||||
|
||||
:desc
|
||||
Starts a new output buffer. All subsequent output will be directed into this buffer. Every call to ob_start() starts a new buffer and puts that buffer on the output buffer stack. ob_close() and ob_get_close() destroy buffers and remove them from the stack.
|
||||
|
||||
:see
|
||||
>ob
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
StringMap parse_query(String q)
|
||||
|
||||
:params
|
||||
q : string containing URL parameters
|
||||
return value : a StringMap containing the parameters
|
||||
|
||||
:desc
|
||||
Decodes a string of the format 'a=b&c=d' into a StringMap containing keyed entries.
|
||||
|
||||
:see
|
||||
>uri
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
u64 parse_time(String time_string)
|
||||
|
||||
:params
|
||||
time_string : a string containing a date and/or time in text form
|
||||
return value : the interpreted 'time_string' as a Unix timestamp
|
||||
|
||||
:desc
|
||||
Attempts to parse the given 'time_string' into a Unix timestamp.
|
||||
|
||||
:see
|
||||
>time
|
||||
@@ -0,0 +1,11 @@
|
||||
:sig
|
||||
void print(...val)
|
||||
|
||||
:params
|
||||
...val : one or more values that should be output
|
||||
|
||||
:desc
|
||||
Appends data to the current request's output stream.
|
||||
|
||||
:see
|
||||
>string
|
||||
@@ -0,0 +1,19 @@
|
||||
:sig
|
||||
void render_component(String name, [DTree props], [Request& context])
|
||||
|
||||
:desc
|
||||
Renders another `.uce` file as a component and writes the result directly to the current output buffer.
|
||||
|
||||
This is the direct-output counterpart to `component()`.
|
||||
|
||||
Component props are passed through `context.call`, and `name:RENDERFUNC` may be used to select a named handler exported by `RENDER:RENDERFUNC(Request& context)`.
|
||||
|
||||
Use `render_component()` when you want to write component output directly from C++ code instead of capturing it as a `String`.
|
||||
|
||||
Example:
|
||||
`DTree props;`
|
||||
`props["body"] = "Hello";`
|
||||
`render_component("components/card:BODY", props, context);`
|
||||
|
||||
:see
|
||||
>ob
|
||||
@@ -0,0 +1,22 @@
|
||||
:sig
|
||||
void render_file(String file_name)
|
||||
void render_file(String file_name, Request& context)
|
||||
|
||||
:params
|
||||
file_name : UCE file to load and execute
|
||||
context : optional request context to pass into the target page
|
||||
|
||||
:desc
|
||||
Calls another UCE file and executes its `RENDER(Request& context)` function.
|
||||
|
||||
If `context` is omitted, the current active request context is used.
|
||||
|
||||
:Example
|
||||
// call a common page template
|
||||
render_file("page-template.uce");
|
||||
|
||||
// explicitly pass a request context
|
||||
render_file("page-template.uce", context);
|
||||
|
||||
:see
|
||||
>ob
|
||||
@@ -0,0 +1,14 @@
|
||||
:sig
|
||||
String replace(String s, String search, String replace_with)
|
||||
|
||||
:params
|
||||
s : the string where replacements should happen
|
||||
search : the string that should be searched for
|
||||
replace_with : the string that should appear in places where 'search' occurs
|
||||
return value : a version of 's' where all instances of 'search' have been replaced with 'replace_with'
|
||||
|
||||
:desc
|
||||
Replace all occurrences of 'search' with the string defined in 'replace_with'.
|
||||
|
||||
:see
|
||||
>string
|
||||
@@ -0,0 +1,11 @@
|
||||
:sig
|
||||
void session_destroy(String session_name)
|
||||
|
||||
:params
|
||||
session_name : the name of the session
|
||||
|
||||
:desc
|
||||
Deletes the cookie specified by 'session_name' and clears the data stored under the session ID. This empties the 'context.session_id' and 'context.session' variables.
|
||||
|
||||
:see
|
||||
>session
|
||||
@@ -0,0 +1,18 @@
|
||||
:sig
|
||||
String session_start(String session_name = "uce-session")
|
||||
|
||||
:params
|
||||
session_name : optional name of the session cookie, defaults to "uce-session"
|
||||
return value : the current session ID
|
||||
|
||||
:desc
|
||||
Starts session or connects to existing session. This function sets a cookie with the name contained in 'session_name' if it does not exist and fills that cookie with a new unique session ID. It then loads the session data for that session ID. Afterwards, the following fields are populated in the 'context' variable:
|
||||
|
||||
context.session_id : the current session ID
|
||||
|
||||
context.session_name : the current session cookie name
|
||||
|
||||
context.session : the current session data. The session data is automatically saved after a request completes.
|
||||
|
||||
:see
|
||||
>session
|
||||
@@ -0,0 +1,11 @@
|
||||
:sig
|
||||
void set_cwd(String path)
|
||||
|
||||
:params
|
||||
path : the new working directory
|
||||
|
||||
:desc
|
||||
Sets a new working directory.
|
||||
|
||||
:see
|
||||
>sys
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
String shell_escape(String raw)
|
||||
|
||||
:params
|
||||
raw : string that should be escaped
|
||||
return value : escaped version of 'raw'
|
||||
|
||||
:desc
|
||||
Escapes a parameter for shell_exec
|
||||
|
||||
:see
|
||||
>sys
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
String shell_exec(String cmd)
|
||||
|
||||
:params
|
||||
cmd : string that contains the shell command line to be executed
|
||||
return value : output of the command execution
|
||||
|
||||
:desc
|
||||
Executes a Linux shell command and returns the generated output
|
||||
|
||||
:see
|
||||
>sys
|
||||
@@ -0,0 +1,11 @@
|
||||
:sig
|
||||
void socket_close(u64 sockfd)
|
||||
|
||||
:params
|
||||
sockfd : socket handle
|
||||
|
||||
:desc
|
||||
Closes an existing socket connection.
|
||||
|
||||
:see
|
||||
>socket
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
u64 socket_connect(String host, short port)
|
||||
|
||||
:params
|
||||
host : host name
|
||||
port : port number
|
||||
return value : the socket handle
|
||||
|
||||
:desc
|
||||
Opens a socket connection to the given 'host' and 'port'.
|
||||
|
||||
:see
|
||||
>socket
|
||||
@@ -0,0 +1,14 @@
|
||||
:sig
|
||||
String socket_read(u64 sockfd, u32 max_length = 1024*128, u32 timeout = 1);
|
||||
|
||||
:params
|
||||
sockfd : socket handle
|
||||
max_length : optional maximum data size, defaults to 128kBytes
|
||||
timeout : optional operation timeout, defaults to one second
|
||||
return value : string containing the data that was read
|
||||
|
||||
:desc
|
||||
Reads data from a socket connection.
|
||||
|
||||
:see
|
||||
>socket
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
bool socket_write(u64 sockfd, String data)
|
||||
|
||||
:params
|
||||
sockfd : socket handle
|
||||
data : a string containing the data to be written to the socket
|
||||
return value : true if the write operation was successful
|
||||
|
||||
:desc
|
||||
Writes a string of 'data' to the given socket.
|
||||
|
||||
:see
|
||||
>socket
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
StringList split(String str, String delim)
|
||||
|
||||
:params
|
||||
str : string to be split
|
||||
delim : delimiter
|
||||
return value : a list of strings
|
||||
|
||||
:desc
|
||||
Splits 'str' into multiple strings based on the given delimiter 'delim'.
|
||||
|
||||
:see
|
||||
>string
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
StringList split_space(String str)
|
||||
|
||||
:params
|
||||
str : string to be split
|
||||
return value : a list of strings
|
||||
|
||||
:desc
|
||||
Splits 'str' into multiple strings along any whitespace characters (multiple whitespace characters count as one).
|
||||
|
||||
:see
|
||||
>string
|
||||
@@ -0,0 +1,20 @@
|
||||
:sig
|
||||
StringList split_utf8(String str, bool compound_characters = false)
|
||||
|
||||
|
||||
:params
|
||||
str : string to be split
|
||||
compound_characters : optional, if true tries to combine compound characters
|
||||
return value : a list of Unicode characters
|
||||
|
||||
:desc
|
||||
Splits the string 'str' into its constituent Unicode code points.
|
||||
|
||||
If 'compound_characters' is true, split_utf8 will attempt to combine compound characters based on very simple rules:
|
||||
<li>combine characters if they're connected by a Zero-Width Joiner (ZWJ) character</li>
|
||||
<li>combine two characters if they're both a Regional Indicator Symbol Letter</li>
|
||||
<li>if a character is a Variation Selector, append it to the previous character</li>
|
||||
<li>in all other cases, characters remain on their own</li>
|
||||
|
||||
:see
|
||||
>string
|
||||
@@ -0,0 +1,13 @@
|
||||
:sig
|
||||
pid_t task(String key, std::function<void()> exec_func)
|
||||
|
||||
:params
|
||||
key : string uniquely identifying the task
|
||||
exec_func : function to execute
|
||||
return value : the process ID of the started (or still running) task
|
||||
|
||||
:desc
|
||||
task() starts the 'exec_func' in a new process and returns that process' ID. If a process with the same 'key' is already running, task will not start a new process but instead just return the PID of the process that is already running.
|
||||
|
||||
:see
|
||||
>task
|
||||
@@ -0,0 +1,12 @@
|
||||
:sig
|
||||
pid_t task_pid(String key)
|
||||
|
||||
:params
|
||||
key : string uniquely identifying the task
|
||||
return value : the process ID of the task
|
||||
|
||||
:desc
|
||||
Checks whether a process with the given 'key' is running and returns its PID if it is. Returns 0 otherwise.
|
||||
|
||||
:see
|
||||
>task
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user