PHP Classes

File: jml_to_html_renderer.php

Recommend this page to a friend!
  Packages of Christos Drogidis   JML to HTML Renderer   jml_to_html_renderer.php   Download  
File: jml_to_html_renderer.php
Role: Example script
Content type: text/plain
Description: Example script
Class: JML to HTML Renderer
Convert documents in JML format to HTML
Author: By
Last change:
Date: 4 months ago
Size: 5,395 bytes
 

Contents

Class file image Download
<?php
/**
 * @ASCOOS-NAME : Ascoos OS
 * @ASCOOS-VERSION : 26.0.0
 * @ASCOOS-SUPPORT : support@ascoos.com
 * @ASCOOS-BUGS : https://issues.ascoos.com
 *
 * @CASE-STUDY : jml_to_html_renderer.php
 * @fileNo : ASCOOS-OS-CASESTUDY-SEC00268
 *
 * @desc <English> Parses JML syntax into HTML using THTML, generates full page from nested structure.
 * @desc <Greek> ??????? JML syntax ?? HTML ???? THTML, ??????? ????? ?????? ??? nested ????.
 *
 * @since PHP 8.2.0
 */
declare(strict_types=1);

use
ASCOOS\OS\Kernel\HTML\THTML;
use
ASCOOS\OS\Kernel\Files\TFilesHandler;

$properties = [
   
'output' => './generated_page.html'
];

try {
   
$html = new THTML();
   
$files = new TFilesHandler();

   
// -----------------------------------------------------------------------------
    // <English> JML as string.
    // <Greek> JML ?? ????????????.
    // -----------------------------------------------------------------------------
   
$jmlString = <<<'JML'
html:lang('en') {
  head {
    meta:charset('UTF-8')
    meta:name('viewport'),content('width=device-width, initial-scale=1.0')
    title {`Advanced Sample Page`}
    style {
      `.container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f4f4f4;
        }
        .header {
            text-align: center;
            color: #333;
            padding: 10px;
            border-bottom: 2px solid #000;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            font-weight: bold;
        }
        .form-group input, .form-group select {
            width: 100%;
            padding: 8px;
            margin-top: 5px;
        }`
    }
    script {
      `function validateForm() {
            let name = document.getElementById("name").value;
            let email = document.getElementById("email").value;
            if (name === "" || email === "") {
                alert("Please fill out all fields!");
                return false;
            }
            return true;
        }`
    }
  }
  body {
    div:class('container') {
      div:class('header') {
        h1 {`Welcome to Ascoos OS Demo`}
        p {`This is a complex demo with nested elements and interactivity.`}
      }
      div:class('content') {
        h2 {`User Registration`}
        form:onsubmit('return validateForm()'),method('POST'),action('/submit') {
          div:class('form-group') {
            label:for('name') {`Name:`}
            input:type('text'),id('name'),name('name'),required('')
          }
          div:class('form-group') {
            label:for('email') {`Email:`}
            input:type('email'),id('email'),name('email'),required('')
          }
          div:class('form-group') {
            label:for('country') {`Country:`}
            select:id('country'),name('country') {
              option:value('us') {`United States`}
              option:value('gr') {`Greece`}
              option:value('de') {`Germany`}
            }
          }
          button:type('submit') {`Submit`}
        }
        br
        div:class('footer') {
          p {`© 2025 Ascoos OS. All rights reserved.`}
          br
          a:href('https://ascoos.com') {`Visit our site`}
        }
      }
    }
  }
}
JML;

   
// -----------------------------------------------------------------------------
    // <English> Parse JML string to HTML
    // <Greek> ??????? ????????????? JML ?? HTML
    // -----------------------------------------------------------------------------
   
$fullHtml = $html->fromJMLString($jmlString);
   
   
// -----------------------------------------------------------------------------
    // <English> Adds DOCTYPE manually (JML focuses on body).
    // <Greek> ????????? ??????????? ?? DOCTYPE (?? JML ?????????????? ??? body).
    // -----------------------------------------------------------------------------
   
$output = '<!DOCTYPE html>' . $fullHtml;

   
// -----------------------------------------------------------------------------
    // <English> Save to file.
    // <Greek> ?????????? ?? ??????.
    // -----------------------------------------------------------------------------
   
$files->writeToFileWithCheck($output, $properties['output']);
   
   
// -----------------------------------------------------------------------------
    // <English> Preview.
    // <Greek> ?????????????.
    // -----------------------------------------------------------------------------
   
echo "JML Parsed! Generated HTML:\n";
    echo
$output . "\n";
    echo
"Saved to: " . $properties['output'] . "\n";

   
// -----------------------------------------------------------------------------
    // <English> Free resources
    // <Greek> ???????????? ????? ??? ?????????
    // -----------------------------------------------------------------------------
   
$html->Free();
   
$files->Free();
   
} catch (
Exception $e) {
    echo
"Error: " . $e->getMessage() . "\n";
}
?>