Files
moloapp/example/app/Templates.cpp
T
retoor 3c4334cec9 feat: implement MoloApp plans 01-15 with integration
Full C++23 framework tree: runtime, observability, security,
data, app, realtime, supervisor, clients, CLI, example plus
enterprise tenancy, audit, operability, governance,
supplychain. Postgres via docker compose for tests.
2026-10-23 18:20:04 +02:00

137 lines
3.5 KiB
C++

#include "App.hpp"
#include "../fw/Templates.hpp"
namespace molo::example::app {
namespace {
const char kBase[] = R"BASE(<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ title }}</title>
<link rel="stylesheet" href="/static/app.css">
</head>
<body>
<header class="topbar">
<a class="brand" href="/">{{ site }}</a>
<nav class="nav-wide">
<a href="/">Index</a>
<a href="/templates/page">Templates</a>
<a href="/forms/contact">Forms</a>
<a href="/docs">Docs</a>
<a href="/health">Health</a>
</nav>
<details class="nav-narrow">
<summary>Menu</summary>
<nav>
<a href="/">Index</a>
<a href="/templates/page">Templates</a>
<a href="/forms/contact">Forms</a>
<a href="/docs">Docs</a>
<a href="/health">Health</a>
</nav>
</details>
</header>
<main>
{% block content %}{% endblock %}
</main>
<footer><p>{{ site }}: living example, {{ backend }}</p></footer>
</body>
</html>
)BASE";
const char kIndex[] = R"INDEX({% extends "base.html" %}
{% block content %}
<h1>Living example</h1>
<p>Every framework feature, one click away. Mobile-first: narrow the window
and the top nav collapses into a dropdown menu.</p>
{% if show_matrix %}
<table>
<thead><tr><th>Feature</th><th>Route</th></tr></thead>
<tbody>
{% for row in matrix %}
<tr><td>{{ row.feature }}</td><td><a href="{{ row.route }}">{{ row.route }}</a></td></tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>Matrix hidden.</p>
{% endif %}
{% include "nav_hint.html" %}
{% endblock %}
)INDEX";
const char kPage[] = R"PAGE({% extends "base.html" %}
{% block content %}
<h1>{{ heading }}</h1>
<p>Author: {{ author|upper }}</p>
<p>Raw (escaped): {{ snippet }}</p>
<p>Trusted (safe): {{ snippet|safe }}</p>
<ul>
{% for item in items %}
<li>{{ item.name }} ({{ item.kind }})</li>
{% endfor %}
</ul>
{% endblock %}
)PAGE";
const char kContact[] = R"CONTACT({% extends "base.html" %}
{% block content %}
<h1>Contact</h1>
{% if posted %}
<p class="ok">Thanks {{ name }}, message received.</p>
{% else %}
<form method="post" action="/forms/contact">
<label>Name <input name="name" value="{{ name }}"></label>
<label>Email <input name="email" value="{{ email }}"></label>
<label>Message <textarea name="message">{{ message }}</textarea></label>
<button type="submit">Send</button>
</form>
{% endif %}
{% if error %}
<p class="error">{{ error }}</p>
{% endif %}
{% endblock %}
)CONTACT";
const char kDocs[] = R"DOCS({% extends "base.html" %}
{% block content %}
<h1>API docs</h1>
<p>OpenAPI JSON: <a href="/openapi.json">/openapi.json</a></p>
<ul>
{% for row in routes %}
<li><code>{{ row.method }} {{ row.path }}</code> : {{ row.summary }}</li>
{% endfor %}
</ul>
{% endblock %}
)DOCS";
const char kError[] = R"ERROR({% extends "base.html" %}
{% block content %}
<h1>Error {{ status }}</h1>
<p>{{ message }}</p>
{% endblock %}
)ERROR";
const char kNavHint[] =
"<p class=\"hint\">Tip: this page works on a 360px phone.</p>\n";
} // namespace
void load_templates(Services& services) {
services.templates->add_template("base.html", kBase);
services.templates->add_template("index.html", kIndex);
services.templates->add_template("page.html", kPage);
services.templates->add_template("contact.html", kContact);
services.templates->add_template("docs.html", kDocs);
services.templates->add_template("error.html", kError);
services.templates->add_template("nav_hint.html", kNavHint);
services.templates->add_global("site", "MoloApp living example");
services.templates->add_global("backend", "skeleton");
}
} // namespace molo::example::app