Sirius HTML
Framework agnostic HTML rendering utility with an API inspired by jQuery and React.
$h = new Sirius\Html\Builder;
// at this point the builder knows only about the HTML tags defined in the library
// ie: paragraph, div, radio, select, checkbox, img, textarea etc
// start writting HTML
echo $h->make('paragraph', ['href' => 'http://www.bing.com'], 'Go to Bing!']
// or use the power of magic methods
echo $h->h1(['class' => 'main'], ['Main title', $h->em(null, '!!!')]);
// the library is smart enough to handle special requests
echo $h->someComponent(['class' => 'web-component'], 'content of the component');
// will render <some-component class="web-component">content of the component</some-component>
Build your own HTML components
// register your component as classes or callbacks
$h->registerTag('my-component', '\\MyProject\\Html\\MyComponent');
$h->registerTag('my-component', $someCallable);
echo $h->myComponent(null, 'My component content');
The end goal of the library is to allow you write compose your HTML views like so
echo $h->make('blog-article', ['_entry' => $someBlogPost]);
// which would be equivalent of
echo $h->make(
'article',
['class' => 'post post-123 post-story'],
[
['heading', $post->post_name],
['section', $post->content],
['footer', 'Written by ' . $post->author],
['aside', [
['h3', 'Similar articles'],
['ul', [
// ... you can guess what happens here
]]
]]
]
);