[mod] template handling
This commit is contained in:
parent
a2a8c27e5e
commit
e471e1f252
31 changed files with 183 additions and 68 deletions
|
@ -22,6 +22,7 @@ document.addEventListener(
|
||||||
);
|
);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
{{templates}}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
|
@ -10,21 +10,29 @@ namespace _zeitbild.frontend_web.helpers
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo caching
|
|
||||||
*/
|
*/
|
||||||
export async function template_coin(
|
export async function template_coin(
|
||||||
|
group : string,
|
||||||
name : string,
|
name : string,
|
||||||
data : Record<string, string>
|
data : Record<string, string>
|
||||||
) : Promise<string>
|
) : Promise<string>
|
||||||
{
|
{
|
||||||
let content : string;
|
let content : string;
|
||||||
if (! (name in _template_cache)) {
|
const key : string = lib_plankton.string.coin(
|
||||||
|
"{{group}}/{{name}}",
|
||||||
|
{
|
||||||
|
"group": group,
|
||||||
|
"name": name,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (! (key in _template_cache)) {
|
||||||
content = (
|
content = (
|
||||||
(
|
(
|
||||||
await lib_plankton.file.read(
|
await lib_plankton.file.read(
|
||||||
lib_plankton.string.coin(
|
lib_plankton.string.coin(
|
||||||
"templates/{{name}}.html.tpl",
|
"templates/{{group}}/{{name}}.html.tpl",
|
||||||
{
|
{
|
||||||
|
"group": group,
|
||||||
"name": name,
|
"name": name,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -32,10 +40,10 @@ namespace _zeitbild.frontend_web.helpers
|
||||||
)
|
)
|
||||||
.toString()
|
.toString()
|
||||||
);
|
);
|
||||||
_template_cache[name] = content;
|
_template_cache[key] = content;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
content = _template_cache[name];
|
content = _template_cache[key];
|
||||||
}
|
}
|
||||||
return Promise.resolve<string>(
|
return Promise.resolve<string>(
|
||||||
lib_plankton.string.coin(
|
lib_plankton.string.coin(
|
||||||
|
|
|
@ -495,6 +495,7 @@ namespace _zeitbild.frontend_web.view
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return _zeitbild.frontend_web.helpers.template_coin(
|
return _zeitbild.frontend_web.helpers.template_coin(
|
||||||
|
"events",
|
||||||
"tableview",
|
"tableview",
|
||||||
{
|
{
|
||||||
"sources": (
|
"sources": (
|
||||||
|
@ -502,6 +503,7 @@ namespace _zeitbild.frontend_web.view
|
||||||
lib_plankton.map.dump(sources)
|
lib_plankton.map.dump(sources)
|
||||||
.map(
|
.map(
|
||||||
({"key": calendar_id, "value": data}) => async () => _zeitbild.frontend_web.helpers.template_coin(
|
({"key": calendar_id, "value": data}) => async () => _zeitbild.frontend_web.helpers.template_coin(
|
||||||
|
"events",
|
||||||
"tableview-sources-entry",
|
"tableview-sources-entry",
|
||||||
{
|
{
|
||||||
"name": data.name,
|
"name": data.name,
|
||||||
|
@ -518,6 +520,7 @@ namespace _zeitbild.frontend_web.view
|
||||||
stuff.rows
|
stuff.rows
|
||||||
.map(
|
.map(
|
||||||
(row) => async () => _zeitbild.frontend_web.helpers.template_coin(
|
(row) => async () => _zeitbild.frontend_web.helpers.template_coin(
|
||||||
|
"events",
|
||||||
"tableview-row",
|
"tableview-row",
|
||||||
{
|
{
|
||||||
"week": row.week.toFixed(0).padStart(2, "0"),
|
"week": row.week.toFixed(0).padStart(2, "0"),
|
||||||
|
@ -526,6 +529,7 @@ namespace _zeitbild.frontend_web.view
|
||||||
row.data
|
row.data
|
||||||
.map(
|
.map(
|
||||||
(cell) => async () => _zeitbild.frontend_web.helpers.template_coin(
|
(cell) => async () => _zeitbild.frontend_web.helpers.template_coin(
|
||||||
|
"events",
|
||||||
"tableview-cell",
|
"tableview-cell",
|
||||||
{
|
{
|
||||||
"extra_classes": (
|
"extra_classes": (
|
||||||
|
@ -580,6 +584,7 @@ namespace _zeitbild.frontend_web.view
|
||||||
cell.entries
|
cell.entries
|
||||||
.map(
|
.map(
|
||||||
(entry) => () => _zeitbild.frontend_web.helpers.template_coin(
|
(entry) => () => _zeitbild.frontend_web.helpers.template_coin(
|
||||||
|
"events",
|
||||||
"tableview-cell-entry",
|
"tableview-cell-entry",
|
||||||
{
|
{
|
||||||
"color": lib_plankton.color.output_hex(
|
"color": lib_plankton.color.output_hex(
|
||||||
|
|
|
@ -9,6 +9,7 @@ namespace _zeitbild.frontend_web.pages
|
||||||
target_element.innerHTML = "";
|
target_element.innerHTML = "";
|
||||||
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
|
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
|
||||||
"calendar_add",
|
"calendar_add",
|
||||||
|
"default",
|
||||||
{
|
{
|
||||||
"label": lib_plankton.translate.get("page.calendar_add.title")
|
"label": lib_plankton.translate.get("page.calendar_add.title")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace _zeitbild.frontend_web.pages
|
||||||
target_element.innerHTML = "";
|
target_element.innerHTML = "";
|
||||||
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
|
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
|
||||||
"calendar_edit",
|
"calendar_edit",
|
||||||
|
"default",
|
||||||
{
|
{
|
||||||
"label": lib_plankton.translate.get("page.calendar_edit.title.regular")
|
"label": lib_plankton.translate.get("page.calendar_edit.title.regular")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
|
|
|
@ -54,6 +54,7 @@ namespace _zeitbild.frontend_web.pages
|
||||||
target_element.innerHTML = "";
|
target_element.innerHTML = "";
|
||||||
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
|
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
|
||||||
"event_add",
|
"event_add",
|
||||||
|
"default",
|
||||||
{
|
{
|
||||||
"label": lib_plankton.translate.get("page.event_add.title")
|
"label": lib_plankton.translate.get("page.event_add.title")
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ namespace _zeitbild.frontend_web.pages
|
||||||
target_element.innerHTML = "";
|
target_element.innerHTML = "";
|
||||||
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
|
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
|
||||||
"event_edit",
|
"event_edit",
|
||||||
|
"default",
|
||||||
{
|
{
|
||||||
"label": (
|
"label": (
|
||||||
read_only
|
read_only
|
||||||
|
|
|
@ -154,6 +154,7 @@ namespace _zeitbild.frontend_web.pages
|
||||||
|
|
||||||
target_element.innerHTML = "";
|
target_element.innerHTML = "";
|
||||||
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
|
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
|
||||||
|
"events",
|
||||||
"events",
|
"events",
|
||||||
{
|
{
|
||||||
"label_control_year": lib_plankton.translate.get("page.events.controls.year"),
|
"label_control_year": lib_plankton.translate.get("page.events.controls.year"),
|
||||||
|
|
19
source/pages/events/templates/events.html.tpl
Normal file
19
source/pages/events/templates/events.html.tpl
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<div id="events">
|
||||||
|
<div id="events_controls">
|
||||||
|
<label id="events_control_year">
|
||||||
|
<span>{{label_control_year}}</span>
|
||||||
|
<input type="number"/>
|
||||||
|
</label>
|
||||||
|
<label id="events_control_week">
|
||||||
|
<span>{{label_control_week}}</span>
|
||||||
|
<input type="number"/>
|
||||||
|
</label>
|
||||||
|
<label id="events_control_count">
|
||||||
|
<span>{{label_control_count}}</span>
|
||||||
|
<input type="number"/>
|
||||||
|
</label>
|
||||||
|
<input type="submit" id="events_control_apply" value="{{label_control_apply}}"/>
|
||||||
|
</div>
|
||||||
|
<div id="events_table">
|
||||||
|
</div>
|
||||||
|
</div>
|
26
source/pages/events/templates/tableview.html.tpl
Normal file
26
source/pages/events/templates/tableview.html.tpl
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<div class="calendar">
|
||||||
|
<div class="calendar-pane calendar-pane-left">
|
||||||
|
<ul class="tableview-sources">
|
||||||
|
{{sources}}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="calendar-pane calendar-pane-right">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="calendar-cell"></th>
|
||||||
|
<th class="calendar-cell calendar-cell-day">Mo</th>
|
||||||
|
<th class="calendar-cell calendar-cell-day">Di</th>
|
||||||
|
<th class="calendar-cell calendar-cell-day">Mi</th>
|
||||||
|
<th class="calendar-cell calendar-cell-day">Do</th>
|
||||||
|
<th class="calendar-cell calendar-cell-day">Fr</th>
|
||||||
|
<th class="calendar-cell calendar-cell-day">Sa</th>
|
||||||
|
<th class="calendar-cell calendar-cell-day">So</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{rows}}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -16,6 +16,7 @@ namespace _zeitbild.frontend_web.pages
|
||||||
case "internal": {
|
case "internal": {
|
||||||
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
|
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
|
||||||
"login",
|
"login",
|
||||||
|
"default",
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
<div id="events">
|
|
||||||
<div id="events_controls">
|
|
||||||
<label id="events_control_year">
|
|
||||||
<span>{{label_control_year}}</span>
|
|
||||||
<input type="number"/>
|
|
||||||
</label>
|
|
||||||
<label id="events_control_week">
|
|
||||||
<span>{{label_control_week}}</span>
|
|
||||||
<input type="number"/>
|
|
||||||
</label>
|
|
||||||
<label id="events_control_count">
|
|
||||||
<span>{{label_control_count}}</span>
|
|
||||||
<input type="number"/>
|
|
||||||
</label>
|
|
||||||
<input type="submit" id="events_control_apply" value="{{label_control_apply}}"/>
|
|
||||||
</div>
|
|
||||||
<div id="events_table">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
|
@ -1,9 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8"/>
|
|
||||||
<link rel="stylesheet" type="text/css" href="style.css"/>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,27 +0,0 @@
|
||||||
<div class="calendar">
|
|
||||||
<div class="calendar-pane calendar-pane-left">
|
|
||||||
<ul class="tableview-sources">
|
|
||||||
{{sources}}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div class="calendar-pane calendar-pane-right">
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th class="calendar-cell"></th>
|
|
||||||
<th class="calendar-cell calendar-cell-day">Mo</th>
|
|
||||||
<th class="calendar-cell calendar-cell-day">Di</th>
|
|
||||||
<th class="calendar-cell calendar-cell-day">Mi</th>
|
|
||||||
<th class="calendar-cell calendar-cell-day">Do</th>
|
|
||||||
<th class="calendar-cell calendar-cell-day">Fr</th>
|
|
||||||
<th class="calendar-cell calendar-cell-day">Sa</th>
|
|
||||||
<th class="calendar-cell calendar-cell-day">So</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{{rows}}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
61
tools/make-index
Executable file
61
tools/make-index
Executable file
|
@ -0,0 +1,61 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sys as _sys
|
||||||
|
import argparse as _argparse
|
||||||
|
|
||||||
|
|
||||||
|
def file_read(
|
||||||
|
path
|
||||||
|
):
|
||||||
|
handle = open(path, "r")
|
||||||
|
content = handle.read()
|
||||||
|
handle.close()
|
||||||
|
return content
|
||||||
|
|
||||||
|
|
||||||
|
def string_coin(
|
||||||
|
template,
|
||||||
|
arguments
|
||||||
|
):
|
||||||
|
result = template
|
||||||
|
for (key, value, ) in arguments.items():
|
||||||
|
result = result.replace("{{%s}}" % key, value)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def main(
|
||||||
|
):
|
||||||
|
## args
|
||||||
|
argument_parser = _argparse.ArgumentParser()
|
||||||
|
argument_parser.add_argument(
|
||||||
|
dest = "index_template_path",
|
||||||
|
type = str,
|
||||||
|
)
|
||||||
|
argument_parser.add_argument(
|
||||||
|
"-t",
|
||||||
|
"--template",
|
||||||
|
dest = "template_paths",
|
||||||
|
type = str,
|
||||||
|
action = "append",
|
||||||
|
default = []
|
||||||
|
)
|
||||||
|
args = argument_parser.parse_args()
|
||||||
|
|
||||||
|
## exec
|
||||||
|
_sys.stdout.write(
|
||||||
|
string_coin(
|
||||||
|
file_read(args.index_template_path),
|
||||||
|
{
|
||||||
|
"templates": "".join(
|
||||||
|
map(
|
||||||
|
file_read,
|
||||||
|
args.template_paths
|
||||||
|
)
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
|
@ -23,17 +23,63 @@ default: index templates style logic data
|
||||||
index: ${dir_build}/index.html
|
index: ${dir_build}/index.html
|
||||||
|
|
||||||
${dir_build}/index.html: \
|
${dir_build}/index.html: \
|
||||||
${dir_source}/index.html
|
${dir_source}/index.html.tpl
|
||||||
@ ${cmd_log} "index …"
|
@ ${cmd_log} "index …"
|
||||||
@ ${cmd_mkdir} $(dir $@)
|
@ ${cmd_mkdir} $(dir $@)
|
||||||
@ ${cmd_cp} -u -v $^ $@
|
@ tools/make-index \
|
||||||
|
${dir_source}/index.html.tpl \
|
||||||
|
> $@
|
||||||
|
|
||||||
.PHONY: templates
|
.PHONY: templates
|
||||||
templates: \
|
templates: \
|
||||||
$(wildcard ${dir_source}/templates/*)
|
templates-pages-calendar_add \
|
||||||
@ ${cmd_log} "templates …"
|
templates-pages-calendar_edit \
|
||||||
@ ${cmd_mkdir} ${dir_build}/templates
|
templates-pages-event_add \
|
||||||
@ ${cmd_cp} -r -u -v ${dir_source}/templates/* ${dir_build}/templates/
|
templates-pages-event_edit \
|
||||||
|
templates-pages-events \
|
||||||
|
templates-pages-login
|
||||||
|
|
||||||
|
.PHONY: templates-pages-calendar_add
|
||||||
|
templates-pages-calendar_add: \
|
||||||
|
$(wildcard ${dir_source}/pages/calendar_add/templates/*)
|
||||||
|
@ ${cmd_log} "templates:calendar_add …"
|
||||||
|
@ ${cmd_mkdir} ${dir_build}/templates/calendar_add
|
||||||
|
@ ${cmd_cp} -r -u -v ${dir_source}/pages/calendar_add/templates/* ${dir_build}/templates/calendar_add/
|
||||||
|
|
||||||
|
.PHONY: templates-pages-calendar_edit
|
||||||
|
templates-pages-calendar_edit: \
|
||||||
|
$(wildcard ${dir_source}/pages/calendar_edit/templates/*)
|
||||||
|
@ ${cmd_log} "templates:calendar_edit …"
|
||||||
|
@ ${cmd_mkdir} ${dir_build}/templates/calendar_edit
|
||||||
|
@ ${cmd_cp} -r -u -v ${dir_source}/pages/calendar_edit/templates/* ${dir_build}/templates/calendar_edit/
|
||||||
|
|
||||||
|
.PHONY: templates-pages-event_add
|
||||||
|
templates-pages-event_add: \
|
||||||
|
$(wildcard ${dir_source}/pages/event_add/templates/*)
|
||||||
|
@ ${cmd_log} "templates:event_add …"
|
||||||
|
@ ${cmd_mkdir} ${dir_build}/templates/event_add
|
||||||
|
@ ${cmd_cp} -r -u -v ${dir_source}/pages/event_add/templates/* ${dir_build}/templates/event_add/
|
||||||
|
|
||||||
|
.PHONY: templates-pages-event_edit
|
||||||
|
templates-pages-event_edit: \
|
||||||
|
$(wildcard ${dir_source}/pages/event_edit/templates/*)
|
||||||
|
@ ${cmd_log} "templates:event_edit …"
|
||||||
|
@ ${cmd_mkdir} ${dir_build}/templates/event_edit
|
||||||
|
@ ${cmd_cp} -r -u -v ${dir_source}/pages/event_edit/templates/* ${dir_build}/templates/event_edit/
|
||||||
|
|
||||||
|
.PHONY: templates-pages-events
|
||||||
|
templates-pages-events: \
|
||||||
|
$(wildcard ${dir_source}/pages/events/templates/*)
|
||||||
|
@ ${cmd_log} "templates:events …"
|
||||||
|
@ ${cmd_mkdir} ${dir_build}/templates/events
|
||||||
|
@ ${cmd_cp} -r -u -v ${dir_source}/pages/events/templates/* ${dir_build}/templates/events/
|
||||||
|
|
||||||
|
.PHONY: templates-pages-login
|
||||||
|
templates-pages-login: \
|
||||||
|
$(wildcard ${dir_source}/pages/login/templates/*)
|
||||||
|
@ ${cmd_log} "templates:login …"
|
||||||
|
@ ${cmd_mkdir} ${dir_build}/templates/login
|
||||||
|
@ ${cmd_cp} -r -u -v ${dir_source}/pages/login/templates/* ${dir_build}/templates/login/
|
||||||
|
|
||||||
.PHONY: style
|
.PHONY: style
|
||||||
style: \
|
style: \
|
||||||
|
|
Loading…
Add table
Reference in a new issue