On May 7, 10:53 am, Rod <[EMAIL PROTECTED]> wrote:
> I really like what Dan Webb has done in LowPro (http://www.danwebb.net/
> lowpro) for making DOM building easier. His site isn't responding just
> at the moment so I can't grab his exact code, but since I still prefer
> scripty's Builder.node() I have this in my extensions that achieves
> the same result:
>
> ("p|div|span|strong|em|img|table|tr|td|th|thead|tbody|tfoot|pre|
> code|" +
>
> "h1|h2|h3|h4|h5|h6|ul|ol|li|form|input|textarea|legend|fieldset|"
> +
>
> "select|option|blockquote|cite|br|hr|dd|dl|dt|address|a|button|abbr|
> acronym|" +
>
> "script|link|style|bdo|ins|del|object|param|col|colgroup|optgroup|
> caption|" +
> "label|dfn|kbd|samp|var").split("|").each(
> function(el) {
> window['$' + el] = function() {
> return
> Element.extend(Builder.node.apply(Builder,
> [el].concat(Array.prototype.slice.apply(arguments))));
> };
> });
>
> And you end up with a $-prefixed function for each different type of
> element, so you could do your above table something like this:
>
> var table = $table({ id: 'myTable' }, {
> $thead({
> $tr({ $th('Title A'), $th('Title B') })
> }),
> $tbody({
> $tr({ $td('Cell A'), $td('Cell B') })
> })
> });
>
> Which I reckon makes it pretty readable.
Compared to the equivalent HTML:
<table id="myTable">
<thead>
<tr><th>Title A<th>Title B
<tbody>
<tr><td>A<td>B
</table>
It seems verbose.
--
Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---