2017 © Pedro Peláez
 

library html-builder

HTML Builder - Build HTML programatically.

image

best-served-cold/html-builder

HTML Builder - Build HTML programatically.

  • Sunday, March 12, 2017
  • by nark3d
  • Repository
  • 2 Watchers
  • 1 Stars
  • 53 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

Build Status Build Status Code Coverage Latest Stable Version Scrutinizer Code Quality SensioLabsInsight, (*1)

HTML Builder

Basic HTML builder for HTML5. We're not suggesting that you use this to build entire pages, but occasionally there is a need to create HTML programatically, like a table, and that's what this is for!, (*2)

Install

composer require best-served-cold/html-builder

Usage

Call in the Builder and Output classes:, (*3)

use BestServedCold\HTMLBuilder\Html;
use BestServedCold\HTMLBuilder\Output;

Create an element

$p = Html::p()->content('some content');
echo (new Output($p))->get(); 

Returns:, (*4)



some content , (*5)

Adding attributes

$div  = Html::div()->class('someClass')->id('someId');
echo (new Output($div))->get();

Returns:, (*6)



Adding children

$div2 = Html::div(
    Html::p()->content('child content')->class('someClass'),
    function () {
        return Html::input()
            ->type('text')
            ->name('test')
            ->disabled();
    }
)->onblur('somefunc();');
echo (new Output($div2))->get();

NB: Accepts arrays as well as Closures., (*7)

Returns:, (*8)

<div onblur="someFunc();">
    <p class="someClass">
        child content
    </p>
    <input type="text" name="test" disabled>
</div>

Change tab size and depth

$div3 = Html::div(
    Html::p(
        Html::span()
            ->data('bob')
            ->content('span content')
    ),
    Html::comment(' this is some comment ')

);
Output::setTabSize(2); // persistent
Output::setDepth(2); // persistent
echo (new Output($div3))->get();
Output::setTabSize(4);
Output::setDepth(0);

Returns:, (*9)

    <div>
      <p>
        <span data="bob">
          span content
        </span>
      </p>
      <!-- this is some comment -->
    </div>

Basic table

$table = Html::table(
    Html::thead(
        Html::tr(
            Html::th()->content('mary')->class('woman'),
            Html::th()->content('susan')->class('woman'),
            Html::th()->content('harry')->scope('col')
        )
    ),
    Html::tbody(
        Html::tr(
            Html::td()->content('margret')->class('woman'),
            Html::td()->content('bob')->onfocus('someFunction()'),
            Html::td()->content('skyscraper')->id('oddOneOut')
        ),
        Html::tr(
            Html::td()->content('brian')->colspan(3)
        )
    )
)->attribute('someNonStandardAttribute', 'mary');
echo (new Output($table))->get();

Returns:, (*10)

<table someNonStandardAttribute="mary">
    <thead>
        <tr>
            <th class="woman">
                mary
            </th>
            <th class="woman">
                susan
            </th>
            <th scope="col">
                harry
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class="woman">
                margret
            </td>
            <td onfocus="someFunction()">
                bob
            </td>
            <td id="oddOneOut">
                skyscraper
            </td>
        </tr>
        <tr>
            <td colspan="3">
                brian
            </td>
        </tr>
    </tbody>
</table>

Examples

To run the examples:, (*11)

$ cd example
$ php ./example.php

The Versions

12/03 2017

dev-master

9999999-dev http://bestservedcold.com

HTML Builder - Build HTML programatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

html builder best served cold html builder

12/03 2017

2.0.7

2.0.7.0 http://bestservedcold.com

HTML Builder - Build HTML programatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

html builder best served cold html builder

12/03 2017

2.0.6

2.0.6.0 http://bestservedcold.com

HTML Builder - Build HTML programatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

html builder best served cold html builder

12/03 2017

2.0.5

2.0.5.0 http://bestservedcold.com

HTML Builder - Build HTML programatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

html builder best served cold html builder

12/03 2017

2.0.4

2.0.4.0 http://bestservedcold.com

HTML Builder - Build HTML programatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

html builder best served cold html builder

12/03 2017

2.0.3

2.0.3.0 http://bestservedcold.com

HTML Builder - Build HTML programatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

html builder best served cold html builder

11/03 2017

2.0.2

2.0.2.0 http://bestservedcold.com

HTML Builder - Build HTML programatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

html builder best served cold html builder

10/03 2017

2.0.1

2.0.1.0 http://bestservedcold.com

HTML Builder - Build HTML programatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

html builder best served cold html builder

10/03 2017

2.0.0

2.0.0.0 http://bestservedcold.com

HTML Builder - Build HTML programatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

html builder best served cold html builder

04/03 2017

1.0.2

1.0.2.0 http://bestservedcold.com

HTML Builder - Build HTML programatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

html builder best served cold html builder

04/03 2017

1.0.1

1.0.1.0 http://bestservedcold.com

HTML Builder - Build HTML programatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

html builder best served cold html builder

04/03 2017

1.0.0

1.0.0.0 http://bestservedcold.com

HTML Builder - Build HTML programatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

html builder best served cold html builder