https://github.com/undercloud/leaf
PHP DOM Generator
https://github.com/undercloud/leaf
Last synced: 7 months ago
JSON representation
PHP DOM Generator
- Host: GitHub
- URL: https://github.com/undercloud/leaf
- Owner: undercloud
- Created: 2015-04-19T18:31:24.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-04-10T05:41:54.000Z (almost 10 years ago)
- Last Synced: 2025-01-31T00:18:17.884Z (about 1 year ago)
- Language: PHP
- Size: 19.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# leaf
PHP DOM Generator
##install
```composer require unercloud/leaf```
##simple example
```PHP
$l = new \Undercloud\Leaf();
$l->el('html')
->el('body')
->el('h1#id.classname','Heading')->end
->el('p',array('class' => 'article'),'Lorem ipsum...')->end
->el('input:text',array('value'=>'text'))
->end
->end;
echo $l;
```
##constructor
```PHP
$l = new \Undercloud\Leaf(
array(
//format tree
'format' => true,
//indent in formatted tree, default two spaces
'indent' => ' ',
//define own single tags
'selfclosing' => array(...)
)
);
```
##methods
**el** - create element
```PHP
$l->el('tag')
```
or
```PHP
$l->el('tag','text')
```
or
```PHP
$l->el('tag',array $attr)
```
or
```PHP
$l->el('tag',array $attr,'text')
```
You can combine tag with #id and .classname shortcut e.g.
```PHP
$l->el('span#id.classname.anotherclass')
```
Input[type] attr helper for button,checkbox,file,hidden,image,password,radio,reset,submit,text e.g.
```PHP
$l->el('input:text')
```
Single attr helper for 'checked','disabled','readonly','required','multiple e.g.
```PHP
$l->el('select:multiple')
```
**text** - create text node
```PHP
$l->text('any content')
```
**raw** - add raw data wihout escaping
```PHP
$l->raw('raw content')
```
**end** - close tag
```PHP
$l->end() // or $l->end
```
##helpers
**init** - create instance
```PHP
Undercloud\Leaf::init($opt = array())
```
**escape** - escape special chars
```PHP
Undercloud\Leaf::escape($s)
```