phy/markup

Dynamic HTML builder, nothing super worth while. It does supports default HTML3, HTML4, HTML5, and XHTML tags.

1.0.2 2014-01-08 02:47 UTC

This package is not auto-updated.

Last update: 2024-04-22 11:44:23 UTC


README

PHY\Markup gives you a nice little HTML builder. You can append/prepend elements to your main HTML element and they'll all render out on echo.

Uses a little black magic with a few __call and __get methods but they do make it nicer on the eyes.

Usage

<?php

use PHY\Markup\HTML5 as Markup;

/*
 * Create an article tag with a class of "article".
 */
$markup = new Markup;
$article = $markup->article;
$article->class('article');

/*
 * Use our HTML helper to create some elements for us.
 */
$helper = $markup->helper();
$url = $helper->url('Our Link\'s title!', [
    '/rest.php',
    'key' => 'value'
]);

/*
 * Add some extra content to our article.
 */
$article
    ->append($markup->header($markup->h2('H2 Heading!'),['class' => 'header'))
    ->append($markup->section($markup->p('Inner P tag!')))
    ->append($markup->footer->append($url));

/*
 * Recursively generate our HTML on echo.
 * Produces: <article class="article"><header class="header"><h2>H2 Heading!</h2></header><section><p>Inner P tag!</p></section><footer><a href="/rest.php?key=value">Our Link's Title!</a></footer></article>
 */
echo $article;

/*
 * Also, you can use the Markup::create('HTML5');
 */
use \PHY\Markup;
$markup = Markup::create('HTML5');

/*
 * Now for some example usage of using the Markup class itself.
 */
var_dump($markup->isTagVoid('br'));
var_dump($markup->has('div'));

$markup->add('banana', [], true);
$markup->has('banana');
var_dump($markup->isTagVoid('banana'));

$markup->remove('canvas', 'height');
var_dump($markup->has('canvas', 'height'));

$markup->remove('video');
var_dump($markup->has('video'));

About

Created this so I could dynamically create HTML blocks and link them together without having to worry about creating the actual HTML strings until it was time to push it to the server. Found it very helpful to create anchor tags as well as dynamic lists this way.

Requirements

  • PHP 5.4+

Submitting bugs and feature requests

Please send bugs to me via GitHub

Author

John Mullanaphy - john@jo.mu - http://jo.mu/ That's it for now...

License

PHY\Markup is licensed under the DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE - see the LICENSE file for details

Acknowledgements

This library was based on an old perl HTML builder I used many eons ago. I liked it then so I wanted to continue it's sexiness in PHP.

TODO

  • Finish writing tests for this.
  • Finish my other projects that utilize this class.
  • Add some more documentation and examples.
  • Maybe buff up the Factory class a bit.