Re: [Phphtmllib-devel] Usability issues
Status: Beta
Brought to you by:
hemna
|
From: Walter A. B. I. <wab...@bu...> - 2002-06-06 17:34:40
|
On Thu, 2002-06-06 at 04:09, David McNab wrote:
> Hi,
>
> Following up from previous email, I've come up with a solution - a set
> of function wrappers that constructs tag objects and populates them on
> the fly with an arbitrary number of elements.
---This is a really good suggestion. I kinda have something like this
already, but not exactly. There are a bunch of wrapper functions under
phphtmllib/tag_utils that I use more often then creating the object w/
the constructor itself. I named all of the functions as html_*
The one thing they don't have is the ability to set the attributes AND
push n #'s of content items. But one of the nice things about some of
the html_* functions is the api of params for most common things.
Such as the html_a() function which has the params of
function html_a($url, $content, $class=NULL, $target=NULL);
This by no means covers ALL the possible attributes of the
a tag, but it covers most of em. I pretty much use that call
exclusively when constructing an A tag. There is also the
other wrapper function for a common thing of wrapping an IMG tag
inside an A tag. this is done with the
function html_img_href( $url, $image, $width='', $height='', $border=0,
$alt="", $usemap=NULL, $target=NULL);
But I guess there isn't a reason why we could have the
TRtag() function along w/ the other helpers. Most of the html_*()
functions only accept content items, so creating the new style
wrapper would be a benefit.
So the only issue is, what to do w/ the existing html_* functions?
If we create the new wrappers, I want to maintain compatibilty with the
old html_* functions so ppl that are using the libs don't have issues
upgrading to 2.0.0.
This is really a great request tho David. Thanks!
I'll get right on it.
Walt
>
> For example:
>
> function TRtag($attribs)
> {
> $tag = new TRtag($attribs);
> $n = func_num_args();
> for ($i = 1; $i < $n; $i++)
> $tag->push(func_get_arg($i));
> return $tag;
> }
>
> That way, I'm able to take advantages of the strengths of phpHtmlLib and
> generate some quite readable code.
>
> Example from previous messages then converts to:
>
> $cmdstyle = array('size'=>'1',
> 'face'=>'arial,helvetica,sans-serif');
> $row1 = TRtag("",
> TDtag(array('align'=>'right'),
> FONTtag($cmdstyle,
> "Commands:")),
> TDtag("",
> FONTtag($cmdstyle,
> Atag(array("href"=>"$urlPrefix&dbCommand=newTask",
> "title"=>"Create New Task"),
> "Create New"))));
> print $row1->render();
>
> That's a whole lot more readable (well, to me anyway).
>
> I forgot to say - thanks guys for developing phpHtmlLib - it really is
> an excellent tool. Great building-block towards HTML abstraction in PHP.
>
> Cheers
> David
>
>
> On Thu, 2002-06-06 at 22:17, David McNab wrote:
> > Hi,
> >
> > I've just tried out phpHtmlLib on a part of a web app I've written.
> >
> > As much as I hate to say this, after all the work you guys have put into
> > it, I've found that the phpHtmlLib-ised code is twice as long and half
> > as readable, compared to plain echo statements.
> >
> > Code snippets follow.
> >
> > Before phpHtmlLib:
> >
> > $ff = "<td><font size=1 face='arial,helvetica,sans-serif'>";
> > $ffr = "<td align=right>"
> > . <font size=1 face='arial,helvetica,sans-serif'>";
> > $ffend = "</font></td>";
> >
> > echo "<tr>";
> > echo "$ffr" . "Commands:</td>$ff";
> > writeLink("$urlPrefix&dbCommand=newTask", "Create New Task",
> > "Create New", "", "");
> > echo "$ffend";
> > echo "</tr>";
> >
> > phpHtmlLib-ised version which does exactly the same:
> >
> > $row1 = new TRtag();
> > $fflabel = new FONTtag(array('size'=>'1',
> > 'face'=>'arial,helvetica,sans-serif'));
> > $col1 = new TDtag(array('align'=>'right'));
> > $fff = $fflabel;
> > $fff->push("Commands:");
> > $col1->push($fff);
> > $row1->push($col1);
> > $col1 = new TDtag(array('align'=>'left'));
> > $fff = $fflabel;
> > $link1 = new Atag(array("href"=>"$urlPrefix&dbCommand=newTask",
> > "title"=>"Create New Task"));
> > $link1->push("Create New");
> > $fff->push($link1);
> > $col1->push($fff);
> > $row1->push($col1);
> > print $row1->render();
> >
> > To me, it's about as clear as mud compared to the raw version.
> >
> > I tried to make it more readable by creating tags on the fly, within
> > constructors for enclosing tags. Thus the previous code looks more like:
> >
> > $row1 = new TRtag(
> > "",
> > new TDtag(array('align'=>'right'),
> > new FONTtag(array('size'=>'1',
> > 'face'=>'arial,helvetica,sans-serif'),
> > "Commands:")));
> > $row1->push(new TDtag("",
> > new FONTtag(array('size'=>'1',
> > 'face'=>'arial,helvetica,sans-serif'),
> > new Atag(array("href"=>"$urlPrefix&dbCommand=newTask",
> > "title"=>"Create New Task"),
> > "Create New"))));
> > print $row1->render();
> >
> > Pardon the shitty formatting - blame my email client.
> >
> > But alas, the readability has not improved.
> >
> > I might humbly suggest that phpHtmlLib would allow for more readable
> > code if the constructors could take an arbitrary number of content
> > arguments.
> >
> > Or, better, if there were global functions with the same name as the
> > phpHtmlLib classes, which take an arbitrary number of arguments and
> > return a new instance of a tag object.
> >
> > For example:
> >
> > $row1 = TRtag("",
> > TDtag(array('align'=>'right'),
> > FONTtag(array('size'=>'1','face'=>'arial etc'),
> > "Commands:")),
> > TDtag(array("",
> > FONTtag(array('size'=>'1','face'=>'arial etc'),
> > Atag(array('href'=>'somegoddamurl', 'title'=>'myshit'),
> > "Create New"))));
> >
> > With code like *that*, I could scan over it with even the most tired
> > eyes and still see clearly what's going on, without having to follow
> > gazillions of different variables.
> >
> > Thoughts anyone?
> >
> > Cheers
> > David
> >
> >
> >
> > _______________________________________________________________
> >
> > Don't miss the 2002 Sprint PCS Application Developer's Conference
> > August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm
> >
> > _______________________________________________
> > Phphtmllib-devel mailing list
> > Php...@li...
> > https://lists.sourceforge.net/lists/listinfo/phphtmllib-devel
>
>
>
> _______________________________________________________________
>
> Don't miss the 2002 Sprint PCS Application Developer's Conference
> August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm
>
> _______________________________________________
> Phphtmllib-devel mailing list
> Php...@li...
> https://lists.sourceforge.net/lists/listinfo/phphtmllib-devel
|