https://github.com/floofies/microvdom
A virtual Document Object Model for PHP and JavaScript
https://github.com/floofies/microvdom
classes html html-renderer minimalist php virtual-dom
Last synced: 6 months ago
JSON representation
A virtual Document Object Model for PHP and JavaScript
- Host: GitHub
- URL: https://github.com/floofies/microvdom
- Owner: Floofies
- License: mit
- Archived: true
- Created: 2017-05-05T19:48:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-21T16:47:47.000Z (about 8 years ago)
- Last Synced: 2025-03-23T17:35:18.998Z (10 months ago)
- Topics: classes, html, html-renderer, minimalist, php, virtual-dom
- Language: PHP
- Homepage:
- Size: 6.84 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# microVDom
**microVDom** is a tiny (under 300 lines) PHP Virtual DOM solution for minimalist creation and rendering of HTML.
Only the bare minimum of DOM methods are included to quickly write a presentation layer, completely eschewing parsing and query methods. Only a small subset of command methods are supported.
Due to the lack of mutating command methods, the `microDocument` is effectively WORM (Write Once, Read Many).
___
# Usage
Here is a small usage example:
```PHP
createElement("div", ["class" => "myClass"]);
// Add a text node to the div:
$myDiv->appendChild("Hello World!");
// Append the document body with the div:
$document->body->appendChild($myDiv);
// Render the HTML:
$myHTML = $document->render();
?>
```
When the code runs, `$myHTML` will contain the following HTML string:
```HTML
Hello World!
```
# Documentation
## `microDocument`
###### Class
```JavaScript
new microDocument( string $docType );
```
The primary controller/container class.
### Instantiating
Returns a new instance of the `microDocument` class. The new object has two children, the `DOCTYPE` declaration and ``; which then has two children as well, `` and ``.
```PHP
$document = new microDocument("html");
```
##### Constructor Parameters
- String **`docType`**
An arbitrary string used in the `` declaration.
### Member Variables
- String **`docType`**
An arbitrary string used in the `` declaration.
- Element **`documentElement`**
The direct child of the `microDocument`. Default is an `` element.
- Element **`body`**
The `` element of the `` element.
- Element **`head`**
The `` element of the `` element.
### Member Methods
#### `createAttribute`
###### Function
```PHP
microDocument->createAttribute( string $name , string $value );
```
Returns a clone of `object`.
##### Parameters
- String **`name`**
The name of the new attribute.
- String **`value`**
The value of the new attribute.
##### Example
```PHP
// Instantiate a new Attr Object
$myAttr = $document->createAttribute("myAttr", "myValue");
// Instantiate a new Element Object
$myDiv = $document->createElement("div");
// Set the new attribute on the Element Object
$myDiv->setAttribute($myAttr);
// Render the HTML
$myHTML = $myDiv->render();
```
`$myHTML` now contains an HTML string:
```HTML
```
# WIP