Respect / Template

Experimental, HTML-only templating engine
Other
38 stars 6 forks source link

Developer API #12

Closed augustohp closed 12 years ago

augustohp commented 12 years ago

Actually we removed a lot of burden from the designer and threw a lot of work into the PHP developer. We really have to remove this burden to the maximum before we can continue, look at what about i'm saying:

Take a look to the example:

$template              = new Html('./cssZenGarden.html');
$template['title']     = 'Respect\Template: A different template engine';
$template['#pageHeader h1'] = 'Respect\Template';
$template['#pageHeader h2'] = 'A different template engine';

This does not imposes fear, but think of the CSS style importer, the links, the acronym and so on .... The markup to the developer will become messy.

A solution would be to have a "HTMLElement" class

$acronym = new HtmlElement('acronym');
$acronym->title = 'Respect Template Awesomeness';
$acronym->innerHtml = 'Template';
$template              = new Html('./cssZenGarden.html');
$template['.p1 acronym'] = $acronym;

What do you think about it? Can't come up with a better solution for this by now.

augustohp commented 12 years ago

@alganet show some love for this when you can =D

alganet commented 12 years ago

The developer should avoid writing HTML or declaring elements, but it may be necessary. We shouldn't spend much effort in this, but it is appropriate.

HtmlElement could also have a static builder:

HtmlElement::acronym(); //<acronym/>
HtmlElement::acronym('Hi there'); //<acronym>Hi there</acronym>
HtmlElement::acronym('Hi there')->title('How ya doin?'); //<acronym title="How ya doin?">Hi there</acronym>
HtmlElement::acronym('Hi there')->title('How ya doin?')->class("nice_class"); //you got it

Then, we import use HtmlElement as h and we can do some nice stuff:


print
    h::html(
        h::head(
            h::title('Hi!')
        ),
        h::body(
            h::h1('Hello')->id('oi'),
            h::ul(
                h::li('foo'),
                h::li('bar'),
                h::li('baz')
            ),
            h::input()->type('text')->name('username')->value('')
        )
    );

Couple months ago I've implemented this: https://gist.github.com/1138479 together with DOMDocumentFragments I believe we could use it.

augustohp commented 12 years ago

Consider it done, I forgot about this =D

augustohp commented 12 years ago

Added HtmlElement in ec770bbed9, test missing.

alganet commented 12 years ago

Awesome!

augustohp commented 12 years ago

Bwesome!

alganet commented 12 years ago

Threesome! Oh, wait...