asar/elementary
Composer 安装命令:
composer require asar/elementary
包简介
An HTML generator for PHP.
README 文档
README
An HTML generator for PHP.
The following example code:
<?php $el = new Elementary\ElementBuilder; echo $el->html( $el->head( $el->meta_(array('charset'=> 'utf-8')), $el->title('Elementary Example') ), $el->body( $el->h1('Elementary Demonstration & Examples'), $el->div( array('id' => 'contents'), $el->p('This is an example paragraph.') ) ) ); ?>
Produces the following structure without the indentation and line-breaks.
<html> <head> <meta charset="utf-8" /> <title>Elementary Example</title> </head> <body> <h1>Elementary Demonstration & Examples</h1> <div id="contents"> <p>This is an example paragraph.</p> </div> </body> </html>
Empty Elements
To create an empty element like <br />, or <img />, append the element name with an underscore '_'.
<?php echo $el->img_(array('src' => 'bartman.png')); // <img src="bartman.png" /> ?>
Fragments
Sometimes you might want to hold elements temporarily before adding them to a node. The way to do this is by creating Fragments similar in spirit to DOM's HTML Fragments.
<?php $fragment = $el->_($el->p('Foo.'), $el->p('Bar.')); ?>
You can then add add more elements to it if you like.
<?php $fragment->add($el->p('Baz.')); ?>
When you add the fragment to an element and print it, it will take the contents of the fragment as if they were its own. Like how:
<?php $el->div($fragment); ?>
...becomes
<div> <p>Foo.</p> <p>Bar.</p> <p>Baz</p> </div>
Caveats
- Default serialization is xml (i.e. it looks like XHTML with empty elements closed with '/')
- Does not create comments
- Right now, Elementary produces 'ugly' HTML. 'Ugly' means no line-breaks and no indentations.
- To force a leading or trailing space, you can add an empty space (' ') before or after the elements
FAQ
Q. Is it fast?
Don't know. Haven't benchmarked it. I don't think it is but it's fast enough for me.
统计信息
- 总下载量: 114
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-09-29