working on documentation and more API functions

This commit is contained in:
udo
2026-04-29 12:09:37 +00:00
parent cd445f3c9b
commit 9f7625c7fd
94 changed files with 1896 additions and 458 deletions
@@ -5,7 +5,7 @@ COMPONENT(Request& context)
starter_boot(context);
String current_theme = context.cfg.get_by_path("theme/key").to_string();
String current_label = first(context.cfg.get_by_path("theme/label").to_string(), current_theme);
String route_path = context.var["starter"]["route"]["l_path"].to_string();
String route_path = context.call["starter"]["route"]["l_path"].to_string();
<>
<div id="theme-switcher" style="position: fixed; right: 1.5rem; bottom: 1.5rem; z-index: 9999; font-family: inherit;">
@@ -3,7 +3,7 @@
COMPONENT(Request& context)
{
starter_boot(context);
String title = first(context.var["starter"]["page_title"].to_string(), context.cfg.get_by_path("site/default_page_title").to_string());
String title = first(context.call["starter"]["page_title"].to_string(), context.cfg.get_by_path("site/default_page_title").to_string());
String description = first(context.cfg.get_by_path("theme/meta_description").to_string(), "UCE starter example");
String theme_color = first(context.cfg.get_by_path("theme/theme_color").to_string(), "#0f172a");
String icon = starter_asset_url(context.cfg.get_by_path("theme/path").to_string() + "icon.png", context);
@@ -4,13 +4,13 @@ COMPONENT(Request& context)
{
starter_boot(context);
if(context.props["main_html"].to_string() != "")
context.var["starter"]["fragments"]["main"] = context.props["main_html"];
context.call["starter"]["fragments"]["main"] = context.props["main_html"];
if(context.props["json"].get_type_name() == "array")
context.var["starter"]["json"] = context.props["json"];
context.call["starter"]["json"] = context.props["json"];
if(context.props["page_type"].to_string() != "")
context.var["starter"]["page_type"] = context.props["page_type"];
context.call["starter"]["page_type"] = context.props["page_type"];
if(context.props["embed_mode"].to_string() != "")
context.var["starter"]["embed_mode"] = context.props["embed_mode"];
context.call["starter"]["embed_mode"] = context.props["embed_mode"];
starter_render_page(context);
}
+3 -3
View File
@@ -10,7 +10,7 @@ RENDER(Request& context)
if(resolved["file"].to_string() != "")
{
if(resolved["param"].to_string() != "")
context.var["app"]["route"]["param"] = resolved["param"];
context.call["app"]["route"]["param"] = resolved["param"];
unit_render(resolved["file"].to_string(), context);
}
else
@@ -19,11 +19,11 @@ RENDER(Request& context)
<>
<section class="card">
<h1>404 Not Found</h1>
<p><?= context.var["app"]["error"].to_string() ?></p>
<p><?= context.call["app"]["error"].to_string() ?></p>
</section>
</>
}
String main_html = ob_get_close();
context.var["app"]["fragments"]["main"] = main_html;
context.call["app"]["fragments"]["main"] = main_html;
app_render_page(context);
}
+28 -28
View File
@@ -3,7 +3,7 @@
String app_fs_root(Request& context)
{
String root = context.var["app"]["fs_root"].to_string();
String root = context.call["app"]["fs_root"].to_string();
if(root == "")
root = cwd_get();
return(root);
@@ -11,7 +11,7 @@ String app_fs_root(Request& context)
String app_script_url(Request& context)
{
String url = context.var["app"]["script_url"].to_string();
String url = context.call["app"]["script_url"].to_string();
if(url == "")
url = first(context.params["DOCUMENT_URI"], context.params["SCRIPT_NAME"]);
return(url);
@@ -19,7 +19,7 @@ String app_script_url(Request& context)
String app_base_url(Request& context)
{
String base = context.var["app"]["base_url"].to_string();
String base = context.call["app"]["base_url"].to_string();
if(base == "")
{
base = dirname(app_script_url(context));
@@ -74,7 +74,7 @@ DTree app_make_route(Request& context)
DTree app_resolve_view(Request& context, String base_dir = "views")
{
DTree result;
DTree route = context.var["app"]["route"];
DTree route = context.call["app"]["route"];
String lpath = first(route["l_path"].to_string(), "index");
String base = trim(base_dir);
if(base != "" && base[base.length() - 1] == '/')
@@ -114,12 +114,12 @@ DTree app_resolve_view(Request& context, String base_dir = "views")
void app_register_css(String path, Request& context)
{
context.var["app"]["assets"]["css"][path] = path;
context.call["app"]["assets"]["css"][path] = path;
}
void app_register_js(String path, Request& context)
{
context.var["app"]["assets"]["js"][path] = path;
context.call["app"]["assets"]["js"][path] = path;
}
String app_asset_url(String path, Request& context)
@@ -133,7 +133,7 @@ String app_asset_url(String path, Request& context)
void app_render_registered_css(Request& context)
{
context.var["app"]["assets"]["css"].each([&](DTree item, String key) {
context.call["app"]["assets"]["css"].each([&](DTree item, String key) {
String path = item.to_string();
if(path != "")
{
@@ -144,7 +144,7 @@ void app_render_registered_css(Request& context)
void app_render_registered_js(Request& context)
{
context.var["app"]["assets"]["js"].each([&](DTree item, String key) {
context.call["app"]["assets"]["js"].each([&](DTree item, String key) {
String path = item.to_string();
if(path != "")
{
@@ -185,8 +185,8 @@ void app_redirect(String path, Request& context)
void app_not_found(String message, Request& context)
{
context.set_status(404, "Not Found");
context.var["app"]["error"] = message;
context.var["app"]["page_title"] = "404 Not Found";
context.call["app"]["error"] = message;
context.call["app"]["page_title"] = "404 Not Found";
}
String app_menu_href(String menu_key, DTree menu_item, Request& context)
@@ -208,7 +208,7 @@ String app_page_main_html(Request& context)
{
String main_html = context.props["main_html"].to_string();
if(main_html == "")
main_html = context.var["app"]["fragments"]["main"].to_string();
main_html = context.call["app"]["fragments"]["main"].to_string();
return(main_html);
}
@@ -231,7 +231,7 @@ bool app_bool_value(DTree value, bool fallback = false)
bool app_request_embed_mode(Request& context)
{
return(app_bool_value(context.var["app"]["embed_mode"]));
return(app_bool_value(context.call["app"]["embed_mode"]));
}
bool app_page_embed_mode(Request& context)
@@ -244,7 +244,7 @@ bool app_page_embed_mode(Request& context)
String app_theme_page_component(Request& context)
{
String page_type = first(context.var["app"]["page_type"].to_string(), "html");
String page_type = first(context.call["app"]["page_type"].to_string(), "html");
if(page_type == "blank")
return("themes/common/page.blank.uce");
if(page_type == "json")
@@ -264,9 +264,9 @@ void app_render_page(Request& context)
return;
DTree page_props;
page_props["main_html"] = context.var["app"]["fragments"]["main"];
if(context.var["app"]["json"].get_type_name() == "array")
page_props["json"] = context.var["app"]["json"];
page_props["main_html"] = context.call["app"]["fragments"]["main"];
if(context.call["app"]["json"].get_type_name() == "array")
page_props["json"] = context.call["app"]["json"];
String page_component = app_theme_page_component(context);
if(page_component != "" && file_exists(page_component))
@@ -370,19 +370,19 @@ DTree starter_resolve_view(Request& context, String base_dir = "views")
void app_init(Request& context)
{
if(context.var["app"]["booted"].to_string() == "1")
if(context.call["app"]["booted"].to_string() == "1")
return;
context.var["app"]["booted"] = "1";
context.var["app"]["fs_root"] = cwd_get();
context.var["app"]["script_url"] = first(context.params["DOCUMENT_URI"], context.params["SCRIPT_NAME"]);
context.call["app"]["booted"] = "1";
context.call["app"]["fs_root"] = cwd_get();
context.call["app"]["script_url"] = first(context.params["DOCUMENT_URI"], context.params["SCRIPT_NAME"]);
String base_url = dirname(context.var["app"]["script_url"].to_string());
String base_url = dirname(context.call["app"]["script_url"].to_string());
if(base_url == "")
base_url = "/";
if(base_url[base_url.length() - 1] != '/')
base_url.append(1, '/');
context.var["app"]["base_url"] = base_url;
context.call["app"]["base_url"] = base_url;
DTree config = get_config();
String requested_theme = first(context.get["theme"], context.cookies["app_theme"], config["theme"]["key"].to_string());
@@ -394,12 +394,12 @@ void app_init(Request& context)
});
config["theme"]["key"] = requested_theme;
context.cfg = config;
context.var["cfg"].set_reference(&context.cfg);
context.var["app"]["config"].set_reference(&context.cfg);
context.var["app"]["route"] = app_make_route(context);
context.var["app"]["page_type"] = "html";
context.var["app"]["page_title"] = first(config["menu"][context.var["app"]["route"]["l_path"].to_string()]["title"].to_string(), config["site"]["default_page_title"].to_string(), "Home");
context.var["app"]["embed_mode"].set_bool(context.get["embed"] != "");
context.call["cfg"].set_reference(&context.cfg);
context.call["app"]["config"].set_reference(&context.cfg);
context.call["app"]["route"] = app_make_route(context);
context.call["app"]["page_type"] = "html";
context.call["app"]["page_title"] = first(config["menu"][context.call["app"]["route"]["l_path"].to_string()]["title"].to_string(), config["site"]["default_page_title"].to_string(), "Home");
context.call["app"]["embed_mode"].set_bool(context.get["embed"] != "");
if(context.get["theme"] != "" && context.get["theme"] == requested_theme)
{
+5 -5
View File
@@ -148,7 +148,7 @@ struct AppUser
session_start();
context.session[session_key()] = email;
context.var["app"]["current_user"] = user;
context.call["app"]["current_user"] = user;
result["result"].set_bool(true);
result["profile"] = user;
return(result);
@@ -156,7 +156,7 @@ struct AppUser
bool is_signed_in()
{
if(context.var["app"]["current_user"]["email"].to_string() != "")
if(context.call["app"]["current_user"]["email"].to_string() != "")
return(true);
String user_id = context.session[session_key()];
if(user_id == "")
@@ -167,20 +167,20 @@ struct AppUser
context.session.erase(session_key());
return(false);
}
context.var["app"]["current_user"] = user;
context.call["app"]["current_user"] = user;
return(true);
}
DTree current()
{
if(is_signed_in())
return(context.var["app"]["current_user"]);
return(context.call["app"]["current_user"]);
return(DTree());
}
void logout()
{
context.session.erase(session_key());
context.var["app"]["current_user"].clear();
context.call["app"]["current_user"].clear();
}
};
@@ -7,8 +7,8 @@ COMPONENT(Request& context)
context.header["Cache-Control"] = "no-cache, no-store, must-revalidate";
if(context.props["json"].get_type_name() == "array")
print(json_encode(context.props["json"]));
else if(context.var["starter"]["json"].get_type_name() == "array")
print(json_encode(context.var["starter"]["json"]));
else if(context.call["starter"]["json"].get_type_name() == "array")
print(json_encode(context.call["starter"]["json"]));
else
print(starter_page_main_html(context));
}
@@ -5,7 +5,7 @@ COMPONENT(Request& context)
starter_boot(context);
bool embed_mode = starter_page_embed_mode(context);
String main_html = starter_page_main_html(context);
String current_path = context.var["starter"]["route"]["l_path"].to_string();
String current_path = context.call["starter"]["route"]["l_path"].to_string();
DTree global_props;
global_props["cookie_consent"].set_bool(false);
@@ -3,7 +3,7 @@
RENDER(Request& context)
{
starter_boot(context);
context.var["starter"]["page_title"] = "Login";
context.call["starter"]["page_title"] = "Login";
StarterUser users(context);
DTree result;
if(context.params["REQUEST_METHOD"] == "POST")
@@ -9,7 +9,7 @@ RENDER(Request& context)
starter_redirect("account/login", context);
return;
}
context.var["starter"]["page_title"] = "Profile";
context.call["starter"]["page_title"] = "Profile";
DTree user = users.current();
String roles = "";
user["roles"].each([&](DTree role, String key) {
@@ -3,7 +3,7 @@
RENDER(Request& context)
{
starter_boot(context);
context.var["starter"]["page_title"] = "Register";
context.call["starter"]["page_title"] = "Register";
StarterUser users(context);
DTree result;
if(context.params["REQUEST_METHOD"] == "POST")
@@ -3,7 +3,7 @@
RENDER(Request& context)
{
starter_boot(context);
context.var["starter"]["page_title"] = "OAuth Callback";
context.call["starter"]["page_title"] = "OAuth Callback";
String code = context.get["code"];
String state = context.get["state"];
String error = context.get["error"];
@@ -3,7 +3,7 @@
RENDER(Request& context)
{
starter_boot(context);
context.var["starter"]["page_title"] = "Auth";
context.call["starter"]["page_title"] = "Auth";
starter_register_css("views/marketing.css", context);
DTree props;
@@ -3,19 +3,19 @@
RENDER(Request& context)
{
starter_boot(context);
context.var["starter"]["page_type"] = "json";
context.call["starter"]["page_type"] = "json";
DTree body = json_decode(context.in);
if(context.params["REQUEST_METHOD"] == "POST" && body["oauth_service"].to_string() != "" && body["oauth_state"].to_string() != "")
{
context.session["oauth_service"] = body["oauth_service"].to_string();
context.session["oauth_state"] = body["oauth_state"].to_string();
context.var["starter"]["json"]["status"] = "success";
context.call["starter"]["json"]["status"] = "success";
}
else
{
context.set_status(400, "Bad Request");
context.var["starter"]["json"]["status"] = "error";
context.var["starter"]["json"]["message"] = "Invalid input";
context.call["starter"]["json"]["status"] = "error";
context.call["starter"]["json"]["message"] = "Invalid input";
}
}
@@ -3,7 +3,7 @@
RENDER(Request& context)
{
starter_boot(context);
context.var["starter"]["page_title"] = "Dashboard";
context.call["starter"]["page_title"] = "Dashboard";
starter_register_css("views/dashboard.css", context);
DTree props;
+1 -1
View File
@@ -3,7 +3,7 @@
RENDER(Request& context)
{
starter_boot(context);
context.var["starter"]["page_title"] = "Features";
context.call["starter"]["page_title"] = "Features";
starter_register_css("views/marketing.css", context);
<>
<h1>Features</h1>
+2 -2
View File
@@ -3,7 +3,7 @@
RENDER(Request& context)
{
starter_boot(context);
context.var["starter"]["page_title"] = "Gauges";
context.call["starter"]["page_title"] = "Gauges";
starter_register_css("themes/common/css/gauges.css", context);
f64 pi = 3.14159265358979323846;
@@ -69,7 +69,7 @@ RENDER(Request& context)
props.clear();
props["id"] = "needle_demo";
props["title"] = "Needle Gauge";
props["subtitle"] = "The original analog gauge now uses the same elevated panels, typography, and theme-token palette as the arc gauges.";
props["subtitle"] = "The original analog gauge uses the same elevated panels, typography, and theme-token palette as the arc gauges.";
props["style"] = "flex:1 1 24rem";
props["listen"].set_bool(true);
props["label"] = "CPU";
+1 -1
View File
@@ -3,7 +3,7 @@
RENDER(Request& context)
{
starter_boot(context);
context.var["starter"]["page_title"] = "Home";
context.call["starter"]["page_title"] = "Home";
starter_register_css("views/marketing.css", context);
DTree props;
+1 -1
View File
@@ -3,7 +3,7 @@
RENDER(Request& context)
{
starter_boot(context);
context.var["starter"]["page_title"] = "Components";
context.call["starter"]["page_title"] = "Components";
starter_register_css("views/marketing.css", context);
<>
@@ -3,7 +3,7 @@
RENDER(Request& context)
{
starter_boot(context);
context.var["starter"]["page_type"] = "blank";
context.call["starter"]["page_type"] = "blank";
<>
<?= std::to_string((u64)time()) ?> - Page 2 Section 1 loaded
<pre>UCE starter AJAX fragment response</pre>
+1 -1
View File
@@ -3,7 +3,7 @@
RENDER(Request& context)
{
starter_boot(context);
context.var["starter"]["page_title"] = "Ajaxy";
context.call["starter"]["page_title"] = "Ajaxy";
<>
<h1>Ajax Demo</h1>
<div id="page2-section1">
@@ -3,7 +3,7 @@
RENDER(Request& context)
{
starter_boot(context);
context.var["starter"]["page_title"] = "Theme Preview";
context.call["starter"]["page_title"] = "Theme Preview";
starter_register_css("views/themes.css", context);
String current_theme_key = context.cfg.get_by_path("theme/key").to_string();
String theme_label = first(context.cfg.get_by_path("theme/label").to_string(), current_theme_key);
+1 -1
View File
@@ -3,7 +3,7 @@
RENDER(Request& context)
{
starter_boot(context);
context.var["starter"]["page_title"] = "Themes";
context.call["starter"]["page_title"] = "Themes";
starter_register_css("views/themes.css", context);
String current_theme = context.cfg.get_by_path("theme/key").to_string();
@@ -3,8 +3,8 @@
RENDER(Request& context)
{
starter_boot(context);
context.var["starter"]["page_title"] = "Workspace";
String section = first(context.var["starter"]["route"]["param"].to_string(), "overview");
context.call["starter"]["page_title"] = "Workspace";
String section = first(context.call["starter"]["route"]["param"].to_string(), "overview");
if(section != "overview" && section != "projects" && section != "activity")
section = "overview";