2017 © Pedro PelĂĄez
 

library html-builder

Small and easy-to-use class for HTML generation using object-oriented approach.

image

ratrijs/html-builder

Small and easy-to-use class for HTML generation using object-oriented approach.

  • Tuesday, May 22, 2012
  • by rATRIJS
  • Repository
  • 2 Watchers
  • 1 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

 HTMLBuilder - best HTML generation class there is!

HTMLBuilder can be used to generate / build HTML using simple object-oriented interface., (*1)

Feature and usage run-through

Some code snippets that showcase the HTMLBuilder features and API., (*2)

Instance retrieval

To start building your HTML you first need to create HTMLBuilder object. Constructor doesn't need any arguments., (*3)

There are two ways that you can achieve this:, (*4)

  • new keyword
  • HTMLBuilder::dispatch() method

Both of them will achieve the same thing but HTMLBuilder::dispatch() method has the ability to be a one-liner (at least in PHP versions < 5.4)., (*5)

Initialization via new keyword

<?php
$html = new HTMLBuilder;
?>

Initialization via HTMLBuilder::dispatch() method

<?php
$html = HTMLBuilder::dispatch();
?>

HTML generation

Almost all instance methods will append a HTML tag to the generated HTML where tag name is method name. These methods support two arguments: * content - content inside the tag * attributes - tag attributes as key-value array where key is attribute name and value is attribute value, (*6)

Both arguments are optional. It's also possible to pass attributes as the only argument. Tag will automatically close., (*7)

To keep the tag open you have two options: * use HTMLBuilder::open() method before the tag method * use HTMLBuilder::open() method and pass tag name and attributes as arguments for this method, (*8)

Instance methods as tags

php, (*9)

<?php
echo HTMLBuilder::dispatch()->p("Hello World");
?>

html, (*10)

<p>Hello World</p>

Keeping tags open to build nested HTML

Using HTMLBuilder::open() before tag method

php, (*11)

<?php
echo HTMLBuilder::dispatch()->open()->div()->p("Hello World");
?>

html, (*12)

<div><p>Hello World</p></div>
Using HTMLBuilder::open() and pass tag arguments inside it

php, (*13)

<?php
echo HTMLBuilder::dispatch()->open("div")->p("Hello World");
?>

html, (*14)

<div><p>Hello World</p></div>

The Versions

22/05 2012

dev-master

9999999-dev https://github.com/rATRIJS/HTMLBuilder

Small and easy-to-use class for HTML generation using object-oriented approach.

  Sources   Download

MIT

generator html simple oop builder

22/05 2012

1.0.0-alpha1

1.0.0.0-alpha1 https://github.com/rATRIJS/HTMLBuilder

Small and easy-to-use class for HTML generation using object-oriented approach.

  Sources   Download

MIT

generator html simple oop builder