diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba98a06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.geany +/build/ diff --git a/source/helpers.php b/source/helpers.php new file mode 100644 index 0000000..e8086e4 --- /dev/null +++ b/source/helpers.php @@ -0,0 +1,70 @@ + $value) + { + $result = \str_replace(\sprintf('{{%s}}', $key), $value, $result); + } + return $result; +} + + +/** + */ +function render(string $template_name, array $arguments) : string +{ + return string_coin( + cache_get( + string_coin( + 'template.{{name}}', + [ + 'name' => $template_name, + ] + ), + fn() => \file_get_contents( + string_coin( + '{{directory}}/templates/{{name}}.html.tpl', + [ + 'directory' => __DIR__, + 'name' => $template_name, + ] + ) + ) + ), + $arguments + ); +} + + ?> diff --git a/source/index.html.php b/source/index.html.php new file mode 100644 index 0000000..f96639a --- /dev/null +++ b/source/index.html.php @@ -0,0 +1,102 @@ + + + +
+ + + + + \implode( + "\n", + \array_map( + fn ($entry) => \rosavox\helpers\render( + 'docs-list-entry', + [ + 'link' => \rosavox\helpers\string_coin( + '?mode=edit&id={{id}}', + [ + 'id' => $entry['id'], + ] + ), + 'text' => $entry['doc']['title'], + ] + ), + \rosavox\logic\docs_list() + ) + ), + 'link_new' => '?mode=make', + ] + ) + ); + break; + } + case 'make': + { + echo( + \rosavox\helpers\render( + 'docs-edit', + [ + 'id' => '', + 'title' => '', + 'authors' => '', + 'content' => '', + 'reasoning' => '', + 'link_back' => '?mode=list', + ] + ) + ); + break; + } + case 'edit': + { + $doc = \rosavox\logic\docs_read($id); + echo( + \rosavox\helpers\render( + 'docs-edit', + [ + 'id' => $id_encoded, + 'title' => $doc['title'], + 'authors' => \implode(', ', $doc['authors']), + 'content' => $doc['content'], + 'reasoning' => $doc['reasoning'], + 'link_back' => '?mode=list', + ] + ) + ); + break; + } + case 'save': + { + throw (new \Exception('not implemented yet')); + break; + } + default: + { + throw (new \Exception(\sprintf('invalid mode: %s', $mode))); + break; + } + } + ?> + + diff --git a/source/logic.php b/source/logic.php new file mode 100644 index 0000000..4c9b8de --- /dev/null +++ b/source/logic.php @@ -0,0 +1,129 @@ +} + */ + public static array $pool = []; +} + + +/** + */ +function docs_id_encode(int $id) : string +{ + return \sprintf('%u', $id); +} + + +/** + */ +function docs_id_decode(string $id_encoded) : int +{ + return intval($id_encoded); +} + + +/** + */ +function docs_list() : array +{ + return \array_map( + fn ($id_encoded) => [ + 'id' => docs_id_decode($id_encoded), + 'doc' => docs_state::$pool[$id_encoded], + ], + \array_keys(docs_state::$pool) + ); +} + + +/** + */ +function docs_read(int $id) : array +{ + $id_encoded = docs_id_encode($id); + if (! \array_key_exists($id_encoded, docs_state::$pool)) + { + throw (new Error('not found')); + } + else + { + return docs_state::$pool[$id_encoded]; + } +} + + +/** + */ +function docs_create(array $doc) : int +{ + docs_state::$current_id += 1; + $id = docs_state::$current_id; + $id_encoded = docs_id_encode($id); + docs_state::$pool[$id_encoded] = $doc; + return $id; +} + + +/** + */ +function docs_update(int $id, array $doc) : void +{ + $id_encoded = docs_id_encode($id); + if (! \array_key_exists($id_encoded, docs_state::$pool)) + { + throw (new Error('not found')); + } + else + { + docs_state::$pool[$id_encoded] = $doc; + } +} + + +/** + */ +function docs_delete(int $id) : void +{ + $id_encoded = docs_id_encode($id); + if (! \array_key_exists($id_encoded, docs_state::$pool)) + { + throw (new Error('not found')); + } + else + { + docs_state::$pool[$id_encoded] = null; + unset(docs_state::$pool[$id_encoded]); + } +} + + +/** + */ +function docs_add_examples() : void +{ + docs_create( + [ + 'title' => 'Freibier bei Parteitagen', + 'authors' => [ + 'Björn Biernot', + 'Doreen Dauerdurst', + ], + 'content' => 'Wir haben Durst!', + 'reasoning' => null, + ] + ); +} + + ?> diff --git a/source/style.css b/source/style.css new file mode 100644 index 0000000..9ebd55d --- /dev/null +++ b/source/style.css @@ -0,0 +1,72 @@ +:root +{ + --hue: 0; +} + +html +{ + background-color: hsl(var(--hue), 0%, 0%); + color: hsl(var(--hue), 0%, 100%); + + font-family: sans-serif; +} + +body +{ + max-width: 960px; + margin: auto; + padding: 16px; + + background-color: hsl(var(--hue), 0%, 12.5%); + color: hsl(var(--hue), 0%, 87.5%); +} + +a +{ + background-color: hsl(var(--hue), 0%, 12.5%); + color: hsl(var(--hue), 50%, 50%); + + text-decoration: none; +} + +a:hover +{ + background-color: hsl(var(--hue), 0%, 12.5%); + color: hsl(var(--hue), 50%, 75%); +} + +label +{ + display: block; + margin-bottom: 16px; +} + +label > span +{ + display: block; + font-weight: bold; + margin-bottom: 4px; +} + +input[type="text"] +{ + min-width: 480px; + padding: 4px; + + background-color: hsl(var(--hue), 0%, 25%); + color: hsl(var(--hue), 0%, 100%); + + border: none; +} + +textarea +{ + min-width: 480px; + min-height: 120px; + padding: 4px; + + background-color: hsl(var(--hue), 0%, 25%); + color: hsl(var(--hue), 0%, 100%); + + border: none; +} diff --git a/source/templates/docs-edit.html.tpl b/source/templates/docs-edit.html.tpl new file mode 100644 index 0000000..856cd07 --- /dev/null +++ b/source/templates/docs-edit.html.tpl @@ -0,0 +1,26 @@ +