| Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2025-12-18 (2 days ago)  | | Not yet rated by the users | | Total: Not yet counted | | Not yet ranked |
| Version | | License | | PHP version | | Categories |
| jml-to-html-renderer 1.0 | | Custom (specified... | | 8.2 | | HTML, Parsers, PHP 8 |
|
| Description | | Author |
This package can convert documents in JML (JSON Markup Language) format to HTML.
It provides an HTML document class that can parse a string that has a document in JML format.
The class can also output the document in HTML format.
Converting JML Code to HTML
Demonstrates how Ascoos OS takes a clean, small, safe "JML" string and automatically converts it into complete and valid HTML5. | |
 |
|
Innovation award
 Nominee: 17x
Winner: 2x |
|
Instructions
Example
<?php
/**
* @ASCOOS-NAME : Ascoos OS
* @ASCOOS-VERSION : 26.0.0
* @ASCOOS-SUPPORT : [email protected]
* @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";
}
?>
|
Details
Converting JML Code to HTML
This case study demonstrates how Ascoos OS takes a clean, small, safe .jml file and automatically converts it into complete and valid HTML5.
Purpose
-
Automatic conversion of JML to HTML5
-
Reduction of code compared to manual HTML
JML Documentation
Main Classes of Ascoos OS
-
THTML : JML parser + HTML generator
-
TFilesHandler : Secure writing of the generated HTML to a file
File Structure
The implementation is contained in a single PHP file:
- jml_to_html_renderer.php
It includes all the logic: interpreting JML, converting to HTML, and saving to an HTML file.
Prerequisites
-
PHP ? 8.2
-
Installed Ascoos OS or
AWES 26
Execution Flow
-
Configure operational properties.
-
Initialize the classes.
-
Declare the `JML` string.
-
Parse the JML string into HTML.
-
Manually add the DOCTYPE.
-
Save the generated HTML to a file.
-
Display the generated HTML code.
-
Release resources and handlers.
Code Example
html:lang('en') {
head {
title {`Untitled-1`}
meta:charset('utf-8')
meta:name('description'),content('')
link:rel('icon'),type('image/x-icon'),href('./favicon.ico')
}
body {
h1{`Hello JML World`}
}
}
Expected Result
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Untitled-1</title>
<meta name="description" content="">
<link rel="icon" type="image/x-icon" href="./favicon.ico">
</head>
<body>
<h1>Hello JML World</h1>
</body>
</html>
Resources
License
This study is covered by the Ascoos General License (AGL). See LICENSE.md.
| |
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.