From 04d445534f512e413623b8bb9a751a196e5264d9 Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Tue, 22 Dec 2020 18:39:57 +0100 Subject: [PATCH] Added initial hello-world module. --- .gitignore | 1 + css/000-modulewrapper.css | 22 ++++++++++ css/001-main.css | 37 +++++++++++++++++ etc/config.php | 5 +++ module.php | 86 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 151 insertions(+) create mode 100644 .gitignore create mode 100644 css/000-modulewrapper.css create mode 100644 css/001-main.css create mode 100644 etc/config.php create mode 100644 module.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6187a84 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/var/tmp diff --git a/css/000-modulewrapper.css b/css/000-modulewrapper.css new file mode 100644 index 0000000..e953c17 --- /dev/null +++ b/css/000-modulewrapper.css @@ -0,0 +1,22 @@ +.modulewrapper { + position: relative; + width: 100%; + padding: 1em 0; +} + +.modulewrapper::before, .modulewrapper::after { + content: ""; + width: 100%; + height: 1px; + background: lightgray; + position: absolute; + left: 0; +} + +.modulewrapper::before { + top: 0; +} + +.modulewrapper::after { + bottom: 0; +} diff --git a/css/001-main.css b/css/001-main.css new file mode 100644 index 0000000..12aaf54 --- /dev/null +++ b/css/001-main.css @@ -0,0 +1,37 @@ +table { + position: relative; + width: 80ch; + margin: 2em 0; +} + +thead::after { + content: ""; + width: 100%; + height: 1px; + position: absolute; + background: black; +} + +td, tr, th { + margin: 0; + padding: .2em; + position: relative; +} + +th:first-child { + width: 30%; +} + +th:last-child { + width: 70%; +} + +td:last-child::before { + content: ""; + position: absolute; + left: 0; + top: 0; + width: 1px; + height: calc(100% + .4em); + background: black; +} diff --git a/etc/config.php b/etc/config.php new file mode 100644 index 0000000..6d26ed8 --- /dev/null +++ b/etc/config.php @@ -0,0 +1,5 @@ + "has been added in the module etc/config.php file.", +]; diff --git a/module.php b/module.php new file mode 100644 index 0000000..6b54f68 --- /dev/null +++ b/module.php @@ -0,0 +1,86 @@ +createElement("th", "Key"), + $this->createElement("th", "Value") + ]; + $head_row = $this->createElement("tr"); + foreach ($head_cells as $cell) { + $head_row->appendChild($cell); + } + // create table body + $tbody = $this->createElement("tbody"); + foreach ($options as $key => $value) { + $tr = $this->createElement("tr"); + $td = $this->createElement("td", $key); + $tr->appendChild($td); + if (is_array($value)) { + $td = $this->createElement("td", "[".implode(", ", $value)."]"); + } elseif ($value === true) { + $td = $this->createElement("td", "true"); + } elseif ($value === false) { + $td = $this->createElement("td", "false"); + } else { + $td = $this->createElement("td", $value); + } + $tr->appendChild($td); + $tbody->appendChild($tr); + } + // construct the table + $thead = $this->createElement("thead"); + $thead->appendChild($head_row); + $thead->appendChild($tbody); + + $table = $this->createElement("table", "", [ + "class" => "table" + ]); + $table->appendChild($thead); + $table->appendChild($tbody); + + return $table; + } + + private function addPageId() { + $div = $this->createElement("div", null, [ + "class" => "page-id-wrapper" + ]); + $h2 = $this->createElement("h2", "Current page id: \"".$this->getPageId()."\""); + $p = $this->createElement("p"); + $text = $this->createTextNode("Click on this "); + $p->appendChild($text); + $href = "/".$this->getPageId()."/hello/dynamic_uri/123456"; + $a = $this->createElement("a", "link (".$href.")", [ + "href" => $href + ]); + $p->appendChild($a); + $text = $this->createTextNode(" to see dynamic_uri_parts option at work."); + $p->appendChild($text); + $p->appendChild($this->createElement("br")); + $italic = $this->createElement("i", "Please notice that the separation of \"dynamic_uri\" is due to the file hierarchy convention. It is intended, not a bug."); + $p->appendChild($italic); + + $div->appendChild($h2); + $div->appendChild($p); + return $div; + } + + public function run(array $options = []) : bool + { + $this->appendChild($this->addPageId()); + $this->appendChild($this->createElement("h2", "\$options content")); + $this->appendChild($this->createOptionsTable($options)); + $this->appendChild($this->createElement("h2", "\$this->configuration->get() content")); + $this->appendChild($this->createOptionsTable($this->configuration->get())); + return true; + } + + public function onWebsocketRequest( + \Lewp\Websocket\Message $message + ) : \Lewp\Websocket\Message { + } +};