tagmaker/tagmaker

This package is abandoned and no longer maintained. No replacement package was suggested.

A dynamic builder of tag elements

0.5.1 2013-04-25 00:48 UTC

This package is not auto-updated.

Last update: 2020-02-07 15:09:19 UTC


README

This project is DEPRECATED and not being maintained anymore.

TagMaker

A dynamic builder of tag elements

Quick Start

Instalation

Add to your composer.json:

"require": {
  "tagmaker/tagmaker": "~0.5"
}

Example of Use

$element = TagMaker::create('a', 'Link', array('class' => 'btn'));
echo $element; // Output: '<a class="btn">Link</a>'
$element->set_href('#');
$element->append_class('btn-large');
echo $element; // Output: '<a href="#" class="btn btn-large">Link</a>'

CSS-Like element creation

$element = TagMaker::create('form.form-vertical#new-post[name=new-post,method=post]');
echo $element; // Output: '<form name="new-post" method="post" class="form-vertical" id="new-post"></form>'
$element = TagMaker::create('.row.span6#main {Lorem ipsum}');
echo $element; // Output: '<div class="row span6" id="main">Lorem ipsum</div>'

Magic methods for attributes manipulation

$element = TagMaker::create('.content', 'Lorem ipsum');
$element->set_id('main-content');
$element->prepend_class('span6');

// Output: <div class="span6 content" id="main-content">Lorem ipsum</div>

Available magic methods for attribute manipulation are: append_{$attribute}($value), prepend_{$attribute}($value), set_{$attribute}($value), add_{$attribute}() and get_{$attribute}().

add_{$attribute}() tries to add an attribute to an Element, throwing a ExistentAttributeException if that attribute already exists.

set_{$attribute}() add an attribute to an Element, overriding it if already exists.

HTML Decoder

TagMaker provides a way to decodes single HTML elements and transforms it to a TagMaker\Element. Examples:

$element = TagMaker::decode('<div class="main" id="content">Lorem ipsum...</div>');
// Will create a TagMaker\Element based at the given HTML

Decoder does not support multiple elements (see Limitations).

Limitations

The actual version does not support multiple elements.

Is pretended to support multiple elements (for decoding and creation) after 1.0 version.