2017 © Pedro Peláez
 

library html-object

A set of classes to create and manipulate HTML objects abstractions

image

anahkiasen/html-object

A set of classes to create and manipulate HTML objects abstractions

  • Wednesday, May 31, 2017
  • by Anahkiasen
  • Repository
  • 5 Watchers
  • 95 Stars
  • 544,060 Installations
  • PHP
  • 18 Dependents
  • 0 Suggesters
  • 17 Forks
  • 4 Open issues
  • 12 Versions
  • 5 % Grown

The README.md

HTMLObject

Build Status Latest Stable Version Total Downloads Scrutinizer Quality Score Code Coverage Support via Gittip, (*1)

HTMLObject is a set of classes to create and manipulate HTML objects abstractions., (*2)

Static calls to the classes

echo Element::p('text')->class('foobar');
// <p class="foobar">text</p>
$list = List::ul(array('foo', 'bar'));

$link = Link::create('#', 'Someone');
$list->getChild(0)->addClass('active')->setValue('by '.$link);
// 

echo Link::create('#foo', 'link')->class('btn btn-success')->blank();
// <a href="#foo" class="btn btn-primary" target="_blank">link</a>

Extending the core classes

The core classes are meant to be extended and used to create complex patterns. All classes implement tree-crawling properties such as the following :, (*3)

$element = Element::figure();

$element->nest('content') // <figure>content</figure>

$element->nest('p', 'content') // <figure>

content, (*4)

</figure> $image = Image::create('img.jpg')->alt('foo'); // <img src="img.jpg" alt="foo" /> $element->setChild($image, 'thumb'); $element->getChild('thumb') // HtmlObject\Image $element->nest(array( 'caption' => Element::figcaption()->nest(array( 'text' => Element::p('foobar'), )), )); $element->getChild('caption.text')->getValue() // foobar // OR $element->captionText->getValue() // foobar $element->captionText->getParent(0) // figure->caption $element->captionText->getParent(1) // figure $element->wrap('div') //
...
$element->wrapValue('div') // <figure>
...
</figure>

You can see examples implementations in the examples folder., (*5)

Properties injection

If your class use properties that are at meant to be added to the final array of attributes, you can inject them using the injectProperties method. Say you have a Link class that has an url property, you can overwrite the method like this, and the $this->url will get added in the href attribute :, (*6)

protected function injectProperties()
{
  return array(
    'href' => $this->url,
  );
}

Or if the property bears the property's name you can simply add it to the array of automatically injected properties :, (*7)

protected $injectedProperties = array('href', 'title');

// Will be added as href="#foo"
protected $href = '#foo';

// Will be added as title="title"
protected $title = 'title';

Altering a precreated tree

HtmlObject allows to use the open and close to open tags but when your tag has children you sometimes want to open the tree at a particular point to inject data at runtime, you can do it like this :, (*8)

$mediaObject = Element::div([
  'title' => Element::h2('John Doe'),
  'body'  => Element::div(),
]);

echo $mediaObject->openOn('body').'My name is John Doe'.$mediaObject->close();
<div>
  <h2>John Doe</h2>
  <div>My name is John Doe</div>
</div>

Configuration

You can change whether to follow xHMTL or HTML5 specification by doing the following :, (*9)

Tag::$config['doctype'] = '{xhtml|html}';

The Versions

31/05 2017

dev-master

9999999-dev

A set of classes to create and manipulate HTML objects abstractions

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar Anahkiasen

31/05 2017

1.4.4

1.4.4.0

A set of classes to create and manipulate HTML objects abstractions

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar Anahkiasen

30/05 2017

1.4.3

1.4.3.0

A set of classes to create and manipulate HTML objects abstractions

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar Anahkiasen

04/03 2015

1.4.2

1.4.2.0

A set of classes to create and manipulate HTML objects abstractions

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar Anahkiasen

16/01 2015

1.4.1

1.4.1.0

A set of classes to create and manipulate HTML objects abstractions

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar Anahkiasen

27/01 2014

1.4.0

1.4.0.0

A set of classes to create and manipulate HTML objects abstractions

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

14/01 2014

1.3.0

1.3.0.0

A set of classes to create and manipulate HTML objects abstractions

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

14/01 2014

1.2.0

1.2.0.0

A set of classes to create and manipulate HTML objects abstractions

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

19/11 2013

1.1.2

1.1.2.0

A set of classes to create and manipulate HTML objects abstractions

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

19/11 2013

1.1.1

1.1.1.0

A set of classes to create and manipulate HTML objects abstractions

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

05/11 2013

1.1.0

1.1.0.0

A set of classes to create and manipulate HTML objects abstractions

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

06/06 2013

0.1.0

0.1.0.0

A set of classes to create and manipulate HTML objects abstractions

  Sources   Download

MIT

The Requires

  • php >=5.3.0