Jump to content

[REL] Object-Oriented HTML API


Deji

Recommended Posts

This is absolutely awful. That's why I'm throwing it out there for anyone who wants it: https://pastebin.com/C0WLbbmN It's an API for generating HTML code using object oriented programming. It sounds nice, but in reality OOP just doesn't fit with HTML. Here's an example of creating a simple page using this god forsaken API:


<?phprequire("html.inc.php");/*EXAMPLE 1: Nested Tags<div class="myImagePlaceholder"><a href="/myimage.png" title="click me!"><img src="/myimagethumb.png" alt="" /></a></div>*/$myImagePlaceholder = new html_tag_div(new html_tag_a("/myimage.png", new html_tag_img("/myimgthumb.png")));echo $myImagePlaceholder->build();/*EXAMPLE 2: Adding content without arrays.<div id="myDiv"><h3>Hello World</h3><br /><p>Do you know who I am?</p></div>*/$myDiv = new html_tag_div();$myHeader = new html_tag_header(3, "Hello World");$myParagraph = new html_tag_paragraph("Do you know who I am?");$myDiv->add_content($myHeader, new html_tag_linebreak(), $myParagraph);echo $myDiv->build();/*EXAMPLE 3: Adding content with arrays.<select name="religion"><option value="scifi">Star Trek</option><option value="pirate">Pastafarian</option><option value="normal" selected="selected">Sun Worship</option></select>*/$options = array(new html_tag_option("Star Trek", "scifi"),new html_tag_option("Pastafarian", "pirate"),new html_tag_option("Sun Worship", "normal"));$select = new html_tag_select();$select->add_option($options);$select->set_selected_option(2);$select->set_attr_name("religion");echo $select->build();// Apologies for missing out satanism?>

Yeah, for small bits of code, it's not that bad. But I'd advise against trying to create a site with it. It's incomplete but as you can see from the API code, it's very easy to expand with new tags and such. I stopped working on it when I started adding table classes as it just began to get ridiculous. Anyway, I'm not gonna use it myself and it's otherwise going to waste. So feel free to extend on it, use it, print it then burn it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...