Added initial hello-world module.

This commit is contained in:
Lewin Probst 2020-12-22 18:39:57 +01:00
parent 7e85f8a1a0
commit 04d445534f
5 changed files with 151 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/var/tmp

22
css/000-modulewrapper.css Normal file
View file

@ -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;
}

37
css/001-main.css Normal file
View file

@ -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;
}

5
etc/config.php Normal file
View file

@ -0,0 +1,5 @@
<?php
return [
"this-key" => "has been added in the module etc/config.php file.",
];

86
module.php Normal file
View file

@ -0,0 +1,86 @@
<?php
return new class extends \Lewp\Module {
private function createOptionsTable(array $options)
{
// create head row
$head_cells = [
$this->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 {
}
};