Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
Loading...
Searching...
No Matches
native_dynamic_template.h File Reference

Declares template rendering functions for the in-process dynamic runtime. More...

#include "yyjson.h"

Go to the source code of this file.

Functions

Template rendering helpers
char * render_template_text_dup_runtime (const char *template_text, yyjson_val *params_root)
 Renders one HTML template text string with JSON parameter substitution.
char * render_path_template_text_dup_runtime (const char *template_text, yyjson_val *params_root)
 Renders one path-oriented template text string with JSON substitution.
char * render_file_template_dup_runtime (const char *template_file, yyjson_val *params_root)
 Reads a template file and renders it with JSON parameter substitution.
yyjson_valload_root_from_text_runtime (const char *text, yyjson_doc **doc_out)
 Parses JSON text into a yyjson_val root.
char * apply_base_path_html_dup_runtime (const char *html, const char *base_path)
 Rewrites relative URLs in HTML to use a base path.
char * declared_page_relative_path_dup_runtime (const char *app_root, const char *page_id)
 Resolves one UCAL declared page id to its app-relative page-spec path.
char * join_base_relative_path_dup_runtime (const char *base_path, const char *relative_path)
 Joins a base path and a relative path into one string.
char * render_page_html_dup_runtime (const char *app_root, const char *base_path, const char *layout_id, const char *title, const char *body, const char *current_lang, const char *current_request_target, int has_user, int managed_business_count)
 Builds the nav context and renders a full layout page.
char * error_alert_html_dup_runtime (const char *message)
 Renders an error alert.
char * html_escaped_dup_runtime (const char *text)
 Escapes one plain-text string for safe HTML insertion.
char * hidden_next_input_html_dup_runtime (const char *next_path)
 Renders a hidden next-path <input> HTML, or an empty string.
char * profile_render_page_params_json_dup_runtime (const char *state_path, long user_id, const char *app_root, const char *payment_preference_options_html)
 Builds rendered profile page params JSON from runtime state.
char * service_book_form_page_params_json_dup_runtime (const char *state_path, const char *business_slug, long service_id, const char *app_root, const char *error_message)
 Builds rendered service-book-form page params JSON from runtime state.
char * business_edit_page_params_json_dup_runtime (const char *state_path, const char *business_slug)
 Builds rendered business-edit page params JSON from runtime state.
char * explore_render_page_params_json_dup_runtime (const char *state_path, const char *app_root)
 Builds rendered appointments page params JSON from runtime state.
char * appointments_render_page_params_json_dup_runtime (const char *state_path, long user_id, const char *app_root)
 Builds rendered appointments page params JSON from runtime state.
char * business_dashboard_render_page_params_json_dup_runtime (const char *state_path, long user_id, const char *app_root)
 Builds rendered business dashboard page params JSON from runtime state.
char * business_detail_admin_render_page_params_json_dup_runtime (const char *state_path, const char *business_slug, const char *app_root)
 Builds rendered business admin page params JSON from runtime state.

Detailed Description

Declares template rendering functions for the in-process dynamic runtime.

These functions are exposed from native_json_runtime_ops.c so that the dynamic runtime handler (native_dynamic_runtime.c) can render page templates in-process without shelling out.

See also
native_dynamic_runtime.h for the higher-level entry point.
native_json_runtime_ops.c for the implementations.

Definition in file native_dynamic_template.h.

Function Documentation

◆ apply_base_path_html_dup_runtime()

char * apply_base_path_html_dup_runtime ( const char * html,
const char * base_path )

Rewrites relative URLs in HTML to use a base path.

Parameters
htmlOriginal HTML string.
base_pathURL base path to prepend, or NULL for no change.
Returns
Newly allocated scoped HTML string, or NULL on failure. Caller must free.

Definition at line 5272 of file native_json_runtime_ops.c.

References streq(), text_buffer_append_format_runtime(), text_buffer_append_text_runtime(), text_buffer_free_runtime(), and text_buffer_take_runtime().

Referenced by handle_template_apply_base_path_command(), handle_template_layout_page_html_command(), and render_page_html_dup_runtime().

◆ appointments_render_page_params_json_dup_runtime()

◆ business_dashboard_render_page_params_json_dup_runtime()

char * business_dashboard_render_page_params_json_dup_runtime ( const char * state_path,
long user_id,
const char * app_root )

◆ business_detail_admin_render_page_params_json_dup_runtime()

char * business_detail_admin_render_page_params_json_dup_runtime ( const char * state_path,
const char * business_slug,
const char * app_root )

◆ business_edit_page_params_json_dup_runtime()

char * business_edit_page_params_json_dup_runtime ( const char * state_path,
const char * business_slug )

Builds rendered business-edit page params JSON from runtime state.

Uses the native state model to produce the parameter object expected by templates/businesses/business_edit.body.html.

Parameters
state_pathOn-disk runtime state JSON path.
business_slugBusiness slug from the matched route.
Returns
Newly allocated compact JSON string, or NULL on failure. Caller must free.

Definition at line 11743 of file native_json_runtime_ops.c.

References business_media_url_dup_runtime(), json_value_truthy_runtime(), native_json_doc_free(), native_json_doc_load_file(), native_json_obj_get(), native_json_obj_get_string_dup(), state_find_business_by_slug_runtime(), streq(), text_buffer_append_html_escaped_runtime(), text_buffer_append_text_runtime(), text_buffer_free_runtime(), text_buffer_take_runtime(), yyjson_doc_get_root(), yyjson_mut_doc_free(), yyjson_mut_doc_new(), yyjson_mut_doc_set_root(), yyjson_mut_obj(), yyjson_mut_obj_add_strcpy(), yyjson_mut_write(), and YYJSON_WRITE_NOFLAG.

Referenced by resolve_declared_page_params_json_runtime().

◆ declared_page_relative_path_dup_runtime()

char * declared_page_relative_path_dup_runtime ( const char * app_root,
const char * page_id )

Resolves one UCAL declared page id to its app-relative page-spec path.

Parameters
page_idDeclared UCAL page id (e.g. "login", "register").
Returns
Matching relative path string, or NULL when unknown.
Note
The returned pointer is borrowed from an internal table and must NOT be freed by the caller.

Definition at line 5022 of file native_json_runtime_ops.c.

References app_root_relative_path_dup_runtime(), path_exists(), and ucal_declared_page_relative_path_runtime().

Referenced by handle_page_route(), handle_template_declared_page_contract_command(), and render_declared_page_response_with_headers_runtime().

◆ error_alert_html_dup_runtime()

◆ explore_render_page_params_json_dup_runtime()

char * explore_render_page_params_json_dup_runtime ( const char * state_path,
const char * app_root )

Builds rendered appointments page params JSON from runtime state.

Parameters
state_pathOn-disk runtime state JSON path.
user_idSigned-in user id.
app_rootApp root used to locate declarative fragments when needed.
Returns
Newly allocated compact JSON string, or NULL on failure. Caller must free.

Builds rendered explore page params JSON from runtime state.

Parameters
state_pathOn-disk runtime state JSON path.
app_rootApp root used to locate declarative fragments when needed.
Returns
Newly allocated compact JSON string, or NULL on failure. Caller must free.

Definition at line 10683 of file native_json_runtime_ops.c.

References business_media_url_dup_runtime(), TextBufferRuntime::length, native_json_doc_free(), native_json_doc_load_file(), native_json_obj_get(), native_json_obj_get_string_dup(), render_business_fragment_from_doc_dup_runtime(), state_array_runtime(), TextBufferRuntime::text, text_buffer_append_text_runtime(), text_buffer_free_runtime(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), yyjson_doc_get_root(), yyjson_get_bool(), yyjson_is_bool(), yyjson_is_obj(), yyjson_mut_doc_free(), yyjson_mut_doc_new(), yyjson_mut_doc_set_root(), yyjson_mut_obj(), yyjson_mut_obj_add_strcpy(), yyjson_mut_write(), and YYJSON_WRITE_NOFLAG.

Referenced by resolve_declared_page_params_json_runtime().

◆ hidden_next_input_html_dup_runtime()

char * hidden_next_input_html_dup_runtime ( const char * next_path)

Renders a hidden next-path <input> HTML, or an empty string.

Parameters
next_pathNext URL path, or NULL/empty for no input.
Returns
Newly allocated HTML string. Caller must free.

Definition at line 5352 of file native_json_runtime_ops.c.

References text_buffer_append_html_escaped_runtime(), text_buffer_append_text_runtime(), text_buffer_free_runtime(), and text_buffer_take_runtime().

Referenced by handle_template_login_page_json_command(), handle_template_register_page_json_command(), login_page_params_json_dup_runtime(), and register_page_params_json_dup_runtime().

◆ html_escaped_dup_runtime()

◆ join_base_relative_path_dup_runtime()

char * join_base_relative_path_dup_runtime ( const char * base_path,
const char * relative_path )

Joins a base path and a relative path into one string.

Parameters
base_pathBase directory path.
relative_pathRelative file path.
Returns
Newly allocated joined path, or NULL on failure. Caller must free.

Definition at line 4871 of file native_json_runtime_ops.c.

Referenced by generated_surface_fixture_path_dup_runtime(), handle_page_route(), handle_template_layout_page_html_command(), render_business_fragment_dup_runtime(), render_declared_page_response_with_headers_runtime(), and render_page_html_dup_runtime().

◆ load_root_from_text_runtime()

yyjson_val * load_root_from_text_runtime ( const char * text,
yyjson_doc ** doc_out )

Parses JSON text into a yyjson_val root.

Parameters
textNUL-terminated JSON text.
doc_outOutput pointer to the parsed document (must be freed by caller with native_json_doc_free()).
Returns
Root value, or NULL on parse failure.

Definition at line 338 of file native_json_runtime_ops.c.

References native_json_doc_free(), native_json_doc_load_text(), and yyjson_doc_get_root().

Referenced by append_validation_error_runtime(), handle_generated_surface_coerce_candidate_command(), handle_generated_surface_context_command(), handle_generated_surface_default_candidate_command(), handle_generated_surface_display_value_command(), handle_generated_surface_edit_page_json_command(), handle_generated_surface_filter_controls_html_command(), handle_generated_surface_form_fields_html_command(), handle_generated_surface_list_columns_json_command(), handle_generated_surface_list_result_command(), handle_generated_surface_manage_page_json_command(), handle_generated_surface_manage_table_json_command(), handle_generated_surface_mutate_command(), handle_generated_surface_params_json_command(), handle_generated_surface_relation_checkboxes_html_command(), handle_generated_surface_select_options_html_command(), handle_generated_surface_sort_options_html_command(), handle_generated_surface_submitted_command(), handle_generated_surface_validation_report_command(), handle_object_array_all_integers_command(), handle_object_array_item_json_lines_command(), handle_object_array_length_command(), handle_object_array_lines_command(), handle_object_build_command(), handle_object_field_number_command(), handle_object_field_string_command(), handle_object_field_text_command(), handle_object_merge_command(), handle_object_path_array_length_command(), handle_object_path_bool_command(), handle_object_path_json_command(), handle_object_path_number_command(), handle_object_path_string_command(), handle_object_relative_path_array_to_absolute_json_command(), handle_page_route(), handle_request_compact_json_command(), handle_request_compact_object_command(), handle_request_compact_object_strict_command(), handle_request_field_command(), handle_state_named_command(), handle_template_layout_page_html_command(), handle_template_render_file_command(), handle_template_render_path_command(), handle_validation_error_envelope_command(), handle_validation_field_list_html_command(), handle_validation_has_errors_command(), handle_validation_summary_text_command(), native_dynamic_runtime_handle_request(), normalized_payload_object_mut_runtime(), render_business_fragment_from_doc_dup_runtime(), render_declared_page_response_with_headers_runtime(), and render_page_html_dup_runtime().

◆ profile_render_page_params_json_dup_runtime()

char * profile_render_page_params_json_dup_runtime ( const char * state_path,
long user_id,
const char * app_root,
const char * payment_preference_options_html )

Builds rendered profile page params JSON from runtime state.

Uses the native state model plus declarative profile fragments to produce the parameter object expected by templates/profile/profile.body.html.

Parameters
state_pathOn-disk runtime state JSON path.
user_idSigned-in user id.
app_rootUCAL app root used to locate fragment templates.
payment_preference_options_htmlPre-rendered payment preference options.
Returns
Newly allocated compact JSON string, or NULL on failure. Caller must free.

Definition at line 10148 of file native_json_runtime_ops.c.

References TextBufferRuntime::length, native_json_doc_free(), native_json_doc_load_file(), native_json_obj_get(), native_json_obj_get_long_default(), native_json_obj_get_string_dup(), render_business_fragment_from_doc_dup_runtime(), state_array_runtime(), state_find_business_by_id_runtime(), state_find_user_by_id_runtime(), TextBufferRuntime::text, text_buffer_append_text_runtime(), text_buffer_free_runtime(), text_buffer_take_runtime(), value_long_equals_runtime(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), yyjson_doc_get_root(), yyjson_is_obj(), yyjson_mut_doc_free(), yyjson_mut_doc_new(), yyjson_mut_doc_set_root(), yyjson_mut_obj(), yyjson_mut_obj_add_strcpy(), yyjson_mut_write(), and YYJSON_WRITE_NOFLAG.

Referenced by resolve_declared_page_params_json_runtime().

◆ render_file_template_dup_runtime()

char * render_file_template_dup_runtime ( const char * template_file,
yyjson_val * params_root )

Reads a template file and renders it with JSON parameter substitution.

Parameters
template_fileFile-system path to the template.
params_rootJSON object providing values for each placeholder.
Returns
Newly allocated rendered string, or NULL on failure. Caller must free.

Definition at line 4885 of file native_json_runtime_ops.c.

References read_file_text(), render_template_text_dup_runtime(), and yyjson_is_obj().

Referenced by handle_page_route(), handle_template_layout_page_html_command(), render_business_fragment_dup_runtime(), render_declared_page_response_with_headers_runtime(), and render_page_html_dup_runtime().

◆ render_page_html_dup_runtime()

char * render_page_html_dup_runtime ( const char * app_root,
const char * base_path,
const char * layout_id,
const char * title,
const char * body,
const char * current_lang,
const char * current_request_target,
int has_user,
int managed_business_count )

Builds the nav context and renders a full layout page.

Constructs the navigation HTML (language selector, login/logout links, profile links, etc.) and renders the layout template with the given body HTML embedded. Applies base-path scoping to the result.

Parameters
app_rootApp root directory (for finding templates/layout/).
base_pathURL base path for scoping, or NULL.
layout_idLayout identifier (e.g. "account_shell").
titlePage title.
bodyAlready-rendered body HTML.
current_langCurrent language code (e.g. "en"), or NULL.
current_request_targetCurrent request path for nav highlighting.
has_userNon-zero when a user is authenticated.
managed_business_countNumber of businesses the user manages.
Returns
Newly allocated full page HTML, or NULL on failure. Caller must free.

Definition at line 5418 of file native_json_runtime_ops.c.

References apply_base_path_html_dup_runtime(), html_escaped_dup_runtime(), join_base_relative_path_dup_runtime(), language_options_html_dup_runtime(), load_root_from_text_runtime(), native_json_doc_free(), render_file_template_dup_runtime(), streq(), TextBufferRuntime::text, text_buffer_append_text_runtime(), text_buffer_free_runtime(), text_buffer_take_runtime(), yyjson_mut_doc_free(), yyjson_mut_doc_new(), yyjson_mut_doc_set_root(), yyjson_mut_obj(), yyjson_mut_obj_add_strcpy(), yyjson_mut_write(), and YYJSON_WRITE_NOFLAG.

Referenced by handle_page_route(), and render_declared_page_response_with_headers_runtime().

◆ render_path_template_text_dup_runtime()

char * render_path_template_text_dup_runtime ( const char * template_text,
yyjson_val * params_root )

Renders one path-oriented template text string with JSON substitution.

This variant is for internal route or action path assembly rather than HTML body rendering. Plain placeholders are validated as path references by default while still accepting the explicit {path:key} and {url:key} forms.

Parameters
template_textRaw path template string with placeholder expressions.
params_rootJSON object providing values for each key.
Returns
Newly allocated rendered string, or NULL on failure. Caller must free.

Definition at line 4867 of file native_json_runtime_ops.c.

References render_template_text_with_default_kind_dup_runtime(), and TEMPLATE_PLACEHOLDER_PATH_RUNTIME.

Referenced by generated_surface_operation_path_dup_runtime(), handle_generated_surface_manage_page_json_command(), and handle_template_render_path_command().

◆ render_template_text_dup_runtime()

char * render_template_text_dup_runtime ( const char * template_text,
yyjson_val * params_root )

Renders one HTML template text string with JSON parameter substitution.

Plain {key} placeholders render into HTML text context and are escaped by default. Explicit prefixes are available for other trusted contexts:

  • {html:key} inserts a trusted raw HTML fragment
  • {path:key} inserts a validated path/reference for URL attributes
  • {url:key} inserts a validated URL/reference for URL attributes
Parameters
template_textRaw template string with placeholder expressions.
params_rootJSON object providing values for each key.
Returns
Newly allocated rendered string, or NULL on failure. Caller must free.

Definition at line 4863 of file native_json_runtime_ops.c.

References render_template_text_with_default_kind_dup_runtime(), and TEMPLATE_PLACEHOLDER_TEXT_RUNTIME.

Referenced by emit_template_text_runtime(), and render_file_template_dup_runtime().

◆ service_book_form_page_params_json_dup_runtime()

char * service_book_form_page_params_json_dup_runtime ( const char * state_path,
const char * business_slug,
long service_id,
const char * app_root,
const char * error_message )

Builds rendered service-book-form page params JSON from runtime state.

Uses the native state model plus declarative booking fragments to produce the parameter object expected by templates/businesses/service_book_form.body.html.

Parameters
state_pathOn-disk runtime state JSON path.
business_slugBusiness slug from the matched route.
service_idService id from the matched route.
app_rootUCAL app root used to locate fragment templates.
error_messageOptional error text to render into the form.
Returns
Newly allocated compact JSON string, or NULL on failure. Caller must free.

Definition at line 8655 of file native_json_runtime_ops.c.

References native_json_doc_free(), native_json_doc_load_file(), native_json_obj_get(), native_json_obj_get_array(), native_json_obj_get_long_default(), native_json_obj_get_string_dup(), render_service_visual_html_dup_runtime(), service_media_url_dup_runtime(), state_find_business_by_slug_runtime(), state_find_service_by_id_runtime(), streq(), TextBufferRuntime::text, text_buffer_append_format_runtime(), text_buffer_append_html_escaped_runtime(), text_buffer_append_text_runtime(), text_buffer_free_runtime(), text_buffer_take_runtime(), value_long_equals_runtime(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), yyjson_doc_get_root(), yyjson_get_str(), yyjson_is_str(), yyjson_mut_doc_free(), yyjson_mut_doc_new(), yyjson_mut_doc_set_root(), yyjson_mut_obj(), yyjson_mut_obj_add_int(), yyjson_mut_obj_add_strcpy(), yyjson_mut_write(), and YYJSON_WRITE_NOFLAG.

Referenced by resolve_declared_page_params_json_runtime().