|
Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
|
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_val * | load_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. | |
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.
Definition in file native_dynamic_template.h.
| char * apply_base_path_html_dup_runtime | ( | const char * | html, |
| const char * | base_path ) |
Rewrites relative URLs in HTML to use a base path.
| html | Original HTML string. |
| base_path | URL base path to prepend, or NULL for no change. |
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().
| 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.
| state_path | On-disk runtime state JSON path. |
| user_id | Signed-in user id. |
| app_root | App root used to locate declarative fragments when needed. |
Definition at line 11080 of file native_json_runtime_ops.c.
References TextBufferRuntime::length, native_json_doc_free(), native_json_doc_load_file(), 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_service_by_id_runtime(), state_find_technician_for_business_runtime(), state_find_user_by_id_runtime(), TextBufferRuntime::text, text_buffer_append_html_escaped_runtime(), text_buffer_append_text_runtime(), text_buffer_free_runtime(), text_buffer_take_runtime(), user_manages_business_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().
| 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.
| state_path | On-disk runtime state JSON path. |
| user_id | Signed-in user id. |
| app_root | App root used to locate declarative fragments when needed. |
Definition at line 11434 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_long_default(), 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(), user_manages_business_runtime(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), yyjson_doc_get_root(), yyjson_get_str(), 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().
| 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.
| state_path | On-disk runtime state JSON path. |
| business_slug | Business slug from the matched route. |
| app_root | App root used to locate declarative fragments when needed. |
Definition at line 11519 of file native_json_runtime_ops.c.
References day_of_week_options_html_dup_runtime(), json_value_truthy_runtime(), 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_service_booking_options_editor_html_dup_runtime(), render_service_sort_order_options_html_dup_runtime(), render_technician_checkboxes_html_dup_runtime(), state_array_runtime(), state_find_business_by_slug_runtime(), TextBufferRuntime::text, text_buffer_append_format_runtime(), text_buffer_free_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_int(), yyjson_mut_obj_add_strcpy(), yyjson_mut_obj_put(), yyjson_mut_strcpy(), yyjson_mut_write(), and YYJSON_WRITE_NOFLAG.
Referenced by resolve_declared_page_params_json_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.
| state_path | On-disk runtime state JSON path. |
| business_slug | Business slug from the matched route. |
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().
| 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.
| page_id | Declared UCAL page id (e.g. "login", "register"). |
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().
| char * error_alert_html_dup_runtime | ( | const char * | message | ) |
Renders an error alert.
| message | Error message text, or NULL/empty for no alert. |
Definition at line 5338 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 business_availability_edit_page_params_json_dup_runtime(), generated_admin_manage_page_params_json_dup_runtime(), handle_template_invite_accept_page_json_command(), handle_template_login_page_json_command(), handle_template_password_reset_complete_page_json_command(), handle_template_password_reset_request_page_json_command(), handle_template_register_page_json_command(), invite_accept_page_params_json_dup_runtime(), login_page_params_json_dup_runtime(), password_reset_complete_page_params_json_dup_runtime(), password_reset_request_page_params_json_dup_runtime(), and register_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.
| state_path | On-disk runtime state JSON path. |
| user_id | Signed-in user id. |
| app_root | App root used to locate declarative fragments when needed. |
Builds rendered explore page params JSON from runtime state.
| state_path | On-disk runtime state JSON path. |
| app_root | App root used to locate declarative fragments when needed. |
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().
| char * hidden_next_input_html_dup_runtime | ( | const char * | next_path | ) |
Renders a hidden next-path <input> HTML, or an empty string.
| next_path | Next URL path, or NULL/empty for no input. |
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().
| char * html_escaped_dup_runtime | ( | const char * | text | ) |
Escapes one plain-text string for safe HTML insertion.
| text | Raw text input. |
Definition at line 5329 of file native_json_runtime_ops.c.
References text_buffer_append_html_escaped_runtime(), text_buffer_free_runtime(), and text_buffer_take_runtime().
Referenced by handle_template_invite_accept_page_json_command(), handle_template_invite_created_page_json_command(), handle_template_layout_page_html_command(), handle_template_layout_page_json_command(), handle_template_password_reset_complete_page_json_command(), invite_accept_target_html_dup_runtime(), proof_task_items_html_dup_runtime(), render_page_html_dup_runtime(), and runtime_page_params_add_escaped_string_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.
| base_path | Base directory path. |
| relative_path | Relative file path. |
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().
| yyjson_val * load_root_from_text_runtime | ( | const char * | text, |
| yyjson_doc ** | doc_out ) |
Parses JSON text into a yyjson_val root.
| text | NUL-terminated JSON text. |
| doc_out | Output pointer to the parsed document (must be freed by caller with native_json_doc_free()). |
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().
| 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.
| state_path | On-disk runtime state JSON path. |
| user_id | Signed-in user id. |
| app_root | UCAL app root used to locate fragment templates. |
| payment_preference_options_html | Pre-rendered payment preference options. |
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().
| 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.
| template_file | File-system path to the template. |
| params_root | JSON object providing values for each placeholder. |
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().
| 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.
| app_root | App root directory (for finding templates/layout/). |
| base_path | URL base path for scoping, or NULL. |
| layout_id | Layout identifier (e.g. "account_shell"). |
| title | Page title. |
| body | Already-rendered body HTML. |
| current_lang | Current language code (e.g. "en"), or NULL. |
| current_request_target | Current request path for nav highlighting. |
| has_user | Non-zero when a user is authenticated. |
| managed_business_count | Number of businesses the user manages. |
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().
| 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.
| template_text | Raw path template string with placeholder expressions. |
| params_root | JSON object providing values for each key. |
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().
| 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| template_text | Raw template string with placeholder expressions. |
| params_root | JSON object providing values for each key. |
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().
| 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.
| state_path | On-disk runtime state JSON path. |
| business_slug | Business slug from the matched route. |
| service_id | Service id from the matched route. |
| app_root | UCAL app root used to locate fragment templates. |
| error_message | Optional error text to render into the form. |
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().