From 536af7f0c3393ce2bc2c8d1f2b38b92a5730eae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Sat, 1 Jun 2024 18:53:24 +0200 Subject: [PATCH] [ini] --- .editorconfig | 27 +++++++++++++++++++++++ data.json | 10 +++++++++ entry.html.tpl | 1 + index.html.php | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ main.html.tpl | 22 ++++++++++++++++++ 5 files changed, 120 insertions(+) create mode 100644 .editorconfig create mode 100644 data.json create mode 100644 entry.html.tpl create mode 100644 index.html.php create mode 100644 main.html.tpl diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e82584a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,27 @@ +# see https://EditorConfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = tab +indent_style = tab +tab_width = 4 +insert_final_newline = true +max_line_length = 80 +trim_trailing_whitespace = true +curly_bracket_next_line = false +indent_brace_style = K&R +spaces_around_operators = true +spaces_around_brackets = false +quote_type = double + +[*.y{,a}ml{,lint}] +indent_style = space +indent_size = 2 + +[*.md] +indent_style = space +indent_size = 2 + diff --git a/data.json b/data.json new file mode 100644 index 0000000..45cda34 --- /dev/null +++ b/data.json @@ -0,0 +1,10 @@ +{ + "title": "Portal", + "entries": [ + { + "target": "https://example.org", + "label": "Example" + } + ] +} + diff --git a/entry.html.tpl b/entry.html.tpl new file mode 100644 index 0000000..42c076f --- /dev/null +++ b/entry.html.tpl @@ -0,0 +1 @@ +
  • {{label}}
  • diff --git a/index.html.php b/index.html.php new file mode 100644 index 0000000..0fd90b0 --- /dev/null +++ b/index.html.php @@ -0,0 +1,60 @@ + $value) { + $result = \str_replace(\sprintf('{{%s}}', $key), $value, $result); + } + return $result; +} + + +function template_render_by_name( + string $template_name, + array $arguments +) : string +{ + return string_coin( + \file_get_contents(\sprintf('%s/%s.html.tpl', __DIR__, $template_name)), + $arguments + ); +} + + +function main( +) : void +{ + $data = \json_decode( + \file_get_contents('data.json'), + true + ); + print( + template_render_by_name( + 'main', + [ + 'title' => $data['title'], + 'entries' => \implode( + "\n", + \array_map( + fn($entry) => template_render_by_name( + 'entry', + [ + 'label' => $entry['label'], + 'target' => $entry['target'], + ] + ), + $data['entries'] + ) + ), + ] + ) + ); +} + +main(); + + ?> diff --git a/main.html.tpl b/main.html.tpl new file mode 100644 index 0000000..f7932ce --- /dev/null +++ b/main.html.tpl @@ -0,0 +1,22 @@ + + + + + + + {{title}} + + + + + +