diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/defer.php | 12 | ||||
| -rw-r--r-- | include/layout.php | 20 |
2 files changed, 32 insertions, 0 deletions
diff --git a/include/defer.php b/include/defer.php new file mode 100644 index 0000000..ee01bbc --- /dev/null +++ b/include/defer.php @@ -0,0 +1,12 @@ +<?php + +function defer(&$context, $f): void { + $context ??= new class() { + public $funcs = []; + public function __destruct() + { + while (count($this->funcs)) array_pop($this->funcs)(); + } + }; + $context->funcs[] = $f; +} diff --git a/include/layout.php b/include/layout.php new file mode 100644 index 0000000..ba79595 --- /dev/null +++ b/include/layout.php @@ -0,0 +1,20 @@ +<?php + +include "defer.php"; + +function layout(&$context): void { + ?> +<!DOCTYPE html> +<html lang="sv"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Trädgårdstomten.se</title> + <link rel="stylesheet" href="/style.css"> + <script src="https://unpkg.com/hyperscript.org@0.9.14" crossorigin="anonymous" + integrity="sha384-NzchC8z9HmP/Ed8cheGl9XuSrFSkDNHPiDl+ujbHE0F0I7tWC4rUnwPXP+7IvVZv"></script> +</head> +<body> + <?php + defer($context, function () { echo "</body></html>"; }); +} |
