From 819e8cde08388b2d207190da673539cc4bfb7709 Mon Sep 17 00:00:00 2001 From: jamerno Date: Thu, 5 Mar 2026 14:00:26 +0100 Subject: [PATCH] gawo2025-ws-json-html --- 10398 bytes Simple.json | 23 +++++++++ check.php | 16 +++++++ debug.php | 3 ++ index.php | 75 +++++++++++++++++++++++++++++ innstructions.txt | 31 ++++++++++++ output.html | 40 ++++++++++++++++ output2.html | 15 ++++++ parser.php | 89 ++++++++++++++++++++++++++++++++++ parser2.php | 89 ++++++++++++++++++++++++++++++++++ test.php | 10 ++++ testing.php | 120 ++++++++++++++++++++++++++++++++++++++++++++++ 15 files changed, 710 insertions(+) create mode 100755 buildHtml($jsonData); + } +} +?> \ No newline at end of file diff --git a/Examplary.html b/Examplary.html new file mode 100755 index 0000000..e141c36 --- /dev/null +++ b/Examplary.html @@ -0,0 +1,109 @@ + + + + Examplary + + + + +
+ +

Facharbeitswebsite

+ + + +
+ +
+
+
+
+
+
+

Special Card Section

+

This card has a gradient background and an image holder.

+ Learn More +
+
+
+
+
+ +
+ +

This is a card.

+

Here could be a card text.

+ +
+

Schlechte Facharbeitswebsite

+
+
+ + + diff --git a/Examplary.json b/Examplary.json new file mode 100755 index 0000000..973fc91 --- /dev/null +++ b/Examplary.json @@ -0,0 +1,67 @@ +{ + "head": { + "title": "Examplary", + "styles": "body { font-family: Arial, sans-serif; margin: 0; padding: 0; background-color: red; text-align: center; }\n.container { width: 80%; margin: 20px auto; padding: 20px; background: green; border-radius: 10px; box-shadow: 0 128px 512px rgba(100,100,200,50); }\n.nav-list { list-style-type: none; padding: 0; text-align: left; width: fit-content; margin: 0 auto 20px 0; }\n.nav-list li { padding: 5px 0; font-size: 18px; }\n.card { width: 60%; margin: 20px auto; background: white; border-radius: 10px; overflow: hidden; box-shadow: 0 128px 1024px rgba(200,50,100,40); }\n.card-body { padding: 20px; }\n.card-title { font-size: 24px; font-weight: bold; }\n.bg-card-gradient { background: linear-gradient(45deg, green, purple); color: white; padding: 30px; }\n.bg-holder { height: 150px; background: url('https://via.placeholder.com/150') no-repeat center center; background-size: cover; border-radius: 10px; }\n.button { display: inline-block; padding: 10px 20px; background: green; color: white; text-decoration: none; border-radius: 5px; margin-top: 10px; }" + }, + "body": { + "content": [ + { + "element": "div", + "attributes": { "class": "container" }, + "content": [ + { "element": "h1", "value": "Examplary Website." }, + { "element": "p", "value": "Facharbeitswebsite" }, + { + "element": "ul", + "attributes": { "class": "nav-list" }, + "content": [ + { "element": "li", "value": "Basic" }, + { "element": "li", "value": "Elements" } + ] + }, + { "element": "hr" }, + { + "element": "div", + "attributes": { "class": "col-md-5 text-center bg-card-gradient" }, + "content": [ + { + "element": "div", + "attributes": { "class": "card-body" }, + "content": [ + { + "element": "div", + "attributes": { "class": "card-body" }, + "content": [ + { + "element": "div", + "attributes": { "class": "nav-list" }, + "content": [ + { "element": "h2", "attributes": { "class": "card-title" }, "value": "Special Card Section" }, + { "element": "p", "value": "This card has a gradient background and an image holder." }, + { + "element": "a", + "attributes": { "href": "output2.html", "class": "button" }, + "value": "Learn Less" + } + ] + } + ] + } + ] + } + ] + }, + { "element": "hr" }, + { "element": "h2", "value": "This isn`t a card." }, + { "element": "p", "value": "Here couldn`t be a card text." }, + { + "element": "footer", + "content": [ + { "element": "p", "value": "Schlechte Facharbeit" } + ] + } + ] + } + ] + } +} diff --git a/Examplary.zip b/Examplary.zip new file mode 100755 index 0000000000000000000000000000000000000000..b9a38fc2d359fb00174b505d5a88a52f77be425c GIT binary patch literal 10398 zcmb`NWl&t(^7bM4;O_43?oM!r-~@MfcL_m*h2ZW9BuHS;;2Jzwa3{D2_z$_~9>~eL z^?rGWn(EoquKlakYdyVtbuVQ(2uKVFFwke&Ia=qz{`Ug_{gCuDwsW*KcJ^Xc{_8$i zunpr-oel1!X+dx>u+PuHz|eoYPe9nw(vb=D^;2Dt?PS4d`L6aZS^r~>P@C&q7@H|J z--KMQX`dDTP-5ac9?|n3Ttk-AiUL~1YrX-`e`vaCC^ftsZtupuH7ByFt{de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uD!K2NKK1sp;mCGbGEJ1g`-^&Jt*k`q?iH{w1jn< zKH?srLa21_nG5eu zRiS7gvD-y|^q`~Xaiez9sFTINz{#86&XJ}`a+;xk(@&vLmq?v1#^1TWT!Fpb8uPk| z@oZ!`d=kGXt`%v!W01U##6_hNL@? z*hk)co-0ckw;d`EIa91MnQH`glMiA`I%OIZ7Xi-^Oj?edJGvnbvc64z>1-fX73ydO;@)33UgxRvF=p9w?!ucIgwpcwn`K?&R! zeXxHYd|(EEkv#kZ3>Z4CF zfwJ(>4^#h7`*aEXSv`7+kq6aF9>?^wmh>B^KR4?a2accWm;LMdDd*2Z%p<2Q$O^P~ zd*nQpWu8*NX61Q*1)P7_r<6apgik4wxPMZ9Z4iIM^jS&$!u-QN#r&C-K4J=jXbGQU z{+pvdWdxG)%|3q!YYWuO|7-sLOb(wipo#v;_$yU>iUEs_KK~Ux0WVm7$3THf>|kKX Opuc-i)QTc|xcWabXWOm- literal 0 HcmV?d00001 diff --git a/Simple.json b/Simple.json new file mode 100755 index 0000000..0f0885e --- /dev/null +++ b/Simple.json @@ -0,0 +1,23 @@ +{ + "head": { + "title": "Box Example", + "styles": ".box { border: 2px solid black; padding-top: 20px; margin: 20px; }\n .button {padding: 100px; background-color: red}" + }, + "body": { + "content": [ + { + "element": "div", + "attributes": { + "class": "box" + }, + "value": "This is a simple outlined box with some text inside." + + }, + { + "element": "a", + "attributes": {"href": "output.html", "class": "button"}, + "value": "Press me" + } + ] + } +} diff --git a/check.php b/check.php new file mode 100755 index 0000000..a4ad6cd --- /dev/null +++ b/check.php @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/debug.php b/debug.php new file mode 100755 index 0000000..4f9f708 --- /dev/null +++ b/debug.php @@ -0,0 +1,3 @@ + "working"]); +?> diff --git a/index.php b/index.php new file mode 100755 index 0000000..405d96a --- /dev/null +++ b/index.php @@ -0,0 +1,75 @@ +buildHtml($jsonData); + } + + private function buildHtml($data) { + $html = "\n\n"; + if (isset($data['head'])) { + $html .= $this->parseHead($data['head']); + } + if (isset($data['body'])) { + $html .= "\n" . $this->parseContent($data['body']['content']) . "\n\n"; + } + $html .= ""; + return $html; + } + + private function parseHead($headData) { + $html = "\n"; + if (isset($headData['title'])) { + $html .= "{$headData['title']}\n"; + } + $html .= "\n"; // Include a CSS file + $html .= "\n"; + return $html; + } + + private function parseContent($contentArray) { + $html = ""; + foreach ($contentArray as $element) { + $html .= $this->createElement($element); + } + return $html; + } + + private function createElement($element) { + if (!isset($element['element'])) return ""; + + $tag = $element['element']; + $attributes = isset($element['attributes']) ? $this->parseAttributes($element['attributes']) : ""; + $value = isset($element['value']) ? $element['value'] : ""; + $innerHtml = isset($element['content']) ? $this->parseContent($element['content']) : ""; + + return "<$tag $attributes>$value$innerHtml\n"; + } + + private function parseAttributes($attributes) { + $htmlAttributes = ""; + foreach ($attributes as $key => $value) { + $htmlAttributes .= "$key=\"$value\" "; + } + return trim($htmlAttributes); + } +} + +// Generate the HTML from JSON +$parser = new JsonToHtmlParser(); +$htmlOutput = $parser->parseJsonFile("data.json"); + +// Save the output to an HTML file +file_put_contents("output.html", $htmlOutput); +echo "HTML file generated successfully! Open 'output.html' to view the website."; + +?> diff --git a/innstructions.txt b/innstructions.txt new file mode 100755 index 0000000..5946d7c --- /dev/null +++ b/innstructions.txt @@ -0,0 +1,31 @@ +How to Install and Run the Examplary Website with PHP + +1. Install PHP (if not already installed) + - Windows: + 1. Download PHP from https://windows.php.net/download/ + 2. Extract the files to C:\php + 3. Add C:\php to the system PATH environment variable + - Linux (Debian/Ubuntu): + 1. Open a terminal + 2. Run: sudo apt update && sudo apt install php + - macOS: + 1. Open a terminal + 2. Run: brew install php (if Homebrew is installed) + 3. Alternatively, install PHP manually from https://www.php.net/downloads + +2. Save the project files in the same folder: + - parser.php + - examplary.json + +3. Open a terminal or command prompt and navigate to the folder: + - Example: cd path/to/folder + +4. Run the PHP script to generate the HTML file: + php parser.php + +5. Start a local PHP server: + php -S localhost:8000 + +6. Open a web browser and go to: + http://localhost:8000/output.html + diff --git a/output.html b/output.html new file mode 100755 index 0000000..77f8da0 --- /dev/null +++ b/output.html @@ -0,0 +1,40 @@ + + + +Examplary + + + +

Examplary Website.

+

Facharbeitswebsite

+ +
+
+
+
+
+
+

This isn`t a card.

+

Here couldn`t be a card text.

+

Schlechte Facharbeit

+
+
+ + + \ No newline at end of file diff --git a/output2.html b/output2.html new file mode 100755 index 0000000..1999572 --- /dev/null +++ b/output2.html @@ -0,0 +1,15 @@ + + + +Box Example + + + +
This is a simple outlined box with some text inside.
+Press me + + + \ No newline at end of file diff --git a/parser.php b/parser.php new file mode 100755 index 0000000..48d08d5 --- /dev/null +++ b/parser.php @@ -0,0 +1,89 @@ +buildHtml($jsonData); + } + + private function buildHtml($data) { + $html = "\n\n"; + if (isset($data['head'])) { + $html .= $this->parseHead($data['head']); + } + if (isset($data['body'])) { + $html .= "\n" . $this->parseContent($data['body']['content']) . "\n\n"; + } + $html .= ""; + return $html; + } + + private function parseHead($headData) { + $html = "\n"; + + // Title + if (isset($headData['title'])) { + $html .= "{$headData['title']}\n"; + } + + // Inline CSS Styles + if (isset($headData['styles'])) { + $html .= "\n"; + } + + $html .= "\n"; + return $html; + } + + private function parseContent($contentArray) { + $html = ""; + foreach ($contentArray as $element) { + $html .= $this->createElement($element); + } + return $html; + } + + private function createElement($element) { + if (!isset($element['element'])) return ""; + + $tag = $element['element']; + $attributes = isset($element['attributes']) ? $this->parseAttributes($element['attributes']) : ""; + $value = isset($element['value']) ? $element['value'] : ""; + $innerHtml = isset($element['content']) ? $this->parseContent($element['content']) : ""; + + return "<$tag $attributes>$value$innerHtml\n"; + } + + private function parseAttributes($attributes) { + $htmlAttributes = ""; + foreach ($attributes as $key => $value) { + $htmlAttributes .= "$key=\"$value\" "; + } + return trim($htmlAttributes); + } +} + +// Instantiate and use the class outside the class definition +$parser = new JsonToHtmlParser(); +$htmlOutput = $parser->parseJsonFile("/home/ortelbachf/Schreibtisch/Examplary/Examplary.json"); + +// Automatically save the HTML to output.html in the same directory +$outputFilePath = getcwd() . "/output.html"; +file_put_contents($outputFilePath, $htmlOutput); + +echo "HTML file generated successfully! Open 'output.html' to view the website."; +?> diff --git a/parser2.php b/parser2.php new file mode 100755 index 0000000..1ff9dfb --- /dev/null +++ b/parser2.php @@ -0,0 +1,89 @@ +buildHtml($jsonData); + } + + private function buildHtml($data) { + $html = "\n\n"; + if (isset($data['head'])) { + $html .= $this->parseHead($data['head']); + } + if (isset($data['body'])) { + $html .= "\n" . $this->parseContent($data['body']['content']) . "\n\n"; + } + $html .= ""; + return $html; + } + + private function parseHead($headData) { + $html = "\n"; + + // Title + if (isset($headData['title'])) { + $html .= "{$headData['title']}\n"; + } + + // Inline CSS Styles + if (isset($headData['styles'])) { + $html .= "\n"; + } + + $html .= "\n"; + return $html; + } + + private function parseContent($contentArray) { + $html = ""; + foreach ($contentArray as $element) { + $html .= $this->createElement($element); + } + return $html; + } + + private function createElement($element) { + if (!isset($element['element'])) return ""; + + $tag = $element['element']; + $attributes = isset($element['attributes']) ? $this->parseAttributes($element['attributes']) : ""; + $value = isset($element['value']) ? $element['value'] : ""; + $innerHtml = isset($element['content']) ? $this->parseContent($element['content']) : ""; + + return "<$tag $attributes>$value$innerHtml\n"; + } + + private function parseAttributes($attributes) { + $htmlAttributes = ""; + foreach ($attributes as $key => $value) { + $htmlAttributes .= "$key=\"$value\" "; + } + return trim($htmlAttributes); + } +} + +// Instantiate and use the class outside the class definition +$parser = new JsonToHtmlParser(); +$htmlOutput = $parser->parseJsonFile("/home/ortelbachf/Schreibtisch/Examplary/Simple.json"); + +// Automatically save the HTML to output.html in the same directory +$outputFilePath = getcwd() . "/output2.html"; +file_put_contents($outputFilePath, $htmlOutput); + +echo "HTML file generated successfully! Open 'output.html' to view the website."; +?> diff --git a/test.php b/test.php new file mode 100755 index 0000000..00001ca --- /dev/null +++ b/test.php @@ -0,0 +1,10 @@ + diff --git a/testing.php b/testing.php new file mode 100755 index 0000000..1259f2d --- /dev/null +++ b/testing.php @@ -0,0 +1,120 @@ +$jsonFilePath<\n"; + echo "CWD inside class: " . getcwd() . "\n"; + + echo "Debugging" ; # debug process + echo "Current working dir is " . getcwd() . "\n"; + if (!file_exists($jsonFilePath)) { + die("json not found at $jsonFilePath ") ; + } + echo "file found" ; + if (!is_readable($jsonFilePath)) { + die("json is not readable at $jsonFilePath"); + } + echo "reading $jsonFilePath" ; + $jsonData = json_decode($jsonData, true) ; + if ($jsonData == null) { + die("Couldnt decode json" . json_last_error_msg()) ; + } + echo "json decoded succesfully " ; + echo "Testing absolute path inside class: " . $jsonFilePath . "\n"; + if (!file_exists($jsonFilePath)) { + die("JSON file not found at $jsonFilePath\n"); + } + + + + if (!file_exists($jsonFilePath)) { + echo("JSON file not found."); + } + + $jsonData = json_decode(file_get_contents($jsonFilePath), true); + if (!$jsonData) { + die("Invalid JSON format."); + } + + return $this->buildHtml($jsonData); + } + + private function buildHtml($data) { + $html = "\n\n"; + if (isset($data['head'])) { + $html .= $this->parseHead($data['head']); + } + if (isset($data['body'])) { + $html .= "\n" . $this->parseContent($data['body']['content']) . "\n\n"; + } + $html .= ""; + return $html; + } + + private function parseHead($headData) { + $html = "\n"; + + // Title + if (isset($headData['title'])) { + $html .= "{$headData['title']}\n"; + } + + // Inline CSS Styles + if (isset($headData['styles'])) { + $html .= "\n"; + } + + $html .= "\n"; + return $html; + } + + private function parseContent($contentArray) { + $html = ""; + foreach ($contentArray as $element) { + $html .= $this->createElement($element); + } + return $html; + } + + private function createElement($element) { + if (!isset($element['element'])) return ""; + + $tag = $element['element']; + $attributes = isset($element['attributes']) ? $this->parseAttributes($element['attributes']) : ""; + $value = isset($element['value']) ? $element['value'] : ""; + $innerHtml = isset($element['content']) ? $this->parseContent($element['content']) : ""; + + return "<$tag $attributes>$value$innerHtml\n"; + } + + private function parseAttributes($attributes) { + $htmlAttributes = ""; + foreach ($attributes as $key => $value) { + $htmlAttributes .= "$key=\"$value\" "; + } + return trim($htmlAttributes); + } +} + +// Generate the HTML from JSON +$parser = new JsonToHtmlParser(); +$htmlOutput = $parser->parseJsonFile(__DIR__ . "/examplary.json"); + + +// Save the output to an HTML file +file_put_contents("output.html", $htmlOutput); +echo "HTML file generated successfully! Open 'output.html' to view the website."; + +?>