The idea is to allow for nested ExtJS component structures using
DRYML, something like:
---
<ext-window title="Panel window" show>
  <ext-panel title="Panel A"/>
  <ext-panel title="Panel B">
    <ext-panel title="Panel B.1"/>
  </ext-panel>
</ext-window>


Generating ExtJS code, like:
------
new Ext.Window({
        title    : 'Panel window',
        items    : [{
                xtype : 'panel',
                title : 'Panel A',
        },
        {
                xtype : 'panel',
                title : 'Panel B',
                items : [{
                  xtype : 'panel',
                  title : 'Panel B.1',
                }]
        }]
}).show();


---

Unfortunately I am still very much a newbie when it comes to creating
custom DRYML tags from scratch. It did help a little to look at the
Hobo source code...
The ExtJS code follows a clear pattern.

The idea is to generate a string like:

"title : 'Child Panel 1',
html  : 'Panels can contain Children',
frame : true"

>From an attributes hash like:
{:title => 'Child Panel 1', :html => 'Panels can contain
Children', :frame => true}

How do I get the hash for the current tag call? Fx if I call
<ext-window title="abc"/>

Do I use attributes_for[:ext-window] to get {:title => 'abc'} ?

For ext-window (and other custom tags), some attributes are control
tags, and should not be rendered in the default fashion (as shown
above). I want to be able to easily exclude these.
This is where the calc_attrs function could be useful (see below). It
could exclude some attributes by default (that should always be
excluded for this particular use) and then also exclude those passed
in as a second optional parameter.

Pseudo code (Hobo / DRYML)
---

<def tag="ext-window" attrs="title, width, height, show">
  new Ext.Window({
    <%
    tag_attrs = attributes_for[:ext-window]
    window_atrs = calc_attrs(tag_attrs, [:show])
    show = tag_attrs[:show]
    %>
    <%= ext-attributes(window_attrs) %>
        items    : <%=  params.default %>
  })<%= ".show();" if show %>
</def>

<def tag="ext-panel" attrs="title, width, height, frame, html">
  {
    xtype    : 'panel',
    <%= ext-attributes(attributes_for[:ext-panel]) %>,
        items    : <%= params.default %>
  }
</def>

# subtract from attrs key/value pairs where key matches any symbol in
attrs_skip
def calc_attrs(attrs, attrs_skip)
  attrs - attrs_skip
end

# take a map of symbol => value and convert to joined list
# of "symbol1  : value1, symbol2  : value2, ..."
def ext-attributes(values)
  ext_attrib_list = []
  vaules.each do |key, value|
    ext_attrib_list << "#{key.to_s}    : #{value}"
  end
  ext_attrib_list.join(",\n")
end

--

PS:
The above code has not been tested, not even sure if it is entirely
valid Ruby - just some ideas (pseudo code).
Anyone has some useful suggestions
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo 
Users" 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/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to