2017 © Pedro Peláez
 

library elementary

An HTML generator for PHP.

image

asar/elementary

An HTML generator for PHP.

  • Thursday, October 3, 2013
  • by asartalo
  • Repository
  • 2 Watchers
  • 1 Stars
  • 40 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Elementary

Build Status, (*1)

An HTML generator for PHP., (*2)

The following example code:, (*3)

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., (*4)

<html>
    <head>
        <meta charset="utf-8" />
        <title>Elementary Example</title>
    </head>
    <body>
        <h1>Elementary Demonstration &amp; 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 '_'., (*5)

img_(array('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., (*6)

_($el->p('Foo.'), $el->p('Bar.'));

?>

You can then add add more elements to it if you like., (*7)

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:, (*8)

div($fragment);

?>

...becomes, (*9)

<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?, (*10)

Don't know. Haven't benchmarked it. I don't think it is but it's fast enough for me., (*11)

The Versions

03/10 2013

dev-master

9999999-dev

An HTML generator for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

30/09 2013

0.2

0.2.0.0

An HTML generator for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

29/09 2013

0.1

0.1.0.0

An HTML generator for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires