I am almost there with a working solution for DRYML to generate JSON -
so pleasy help me fix the last small issue...

index.dryml
---
        <ext-win a="a" d="d" f="f">
          <items: y="y">
            <x: xa="xa"/>
            <y: ya="ya"/>
          </items>
        </ext-win>
---

Generates:
a : a, d : d, f : f items: [ x : , y : ]


I can't seem to get the values generated for x and y. Somehow the
parameters hash is stripped of values when I call send(k, attributes,
parameters) from within my 'items' tag? :O

If I drop my boolean AND in my 'x' tag

<def tag="x" attrs="xa">
  <%= ext_config(all_attributes & attrs_for(:x), nil) %>
</def>

and it instead is changed into:

<def tag="x" attrs="xa">
  <%= ext_config(all_attributes, nil) %>
</def>

I get [x y : y y], so the y is generated fully (with key and value)
from within 'x' tag in this case! :O

Any ideas how to solve this? Suggestions for a different approach?

Kris
---
Using:

DRYML taglib, included in application.dryml
---
<def tag="ext-win" attrs="a,b,c">
  <% inhererit_attrs = (attrs_for(:beta) + attrs_for(:gamma)) %>
  <% inherit = all_attributes &  inhererit_attrs %>
  <% decl_values = all_attributes & attrs_for(:ext_win) %>
  <%= ext_config(decl_values, inherit) %>
  <beta merge-attrs="d,e,f,g"/>
  <items: param/>
</def>

<def tag="beta" attrs="d,e">
  <% inherit = all_attributes & attrs_for(:gamma) %>
  <%= ext_config(all_attributes & attrs_for(:beta), inherit) %>
  <gamma merge-attrs="f,g"/>
</def>

<def tag="gamma" attrs="f,g">
  <%= ext_config(all_attributes & attrs_for(:gamma), nil) %>
</def>


<def tag="items">
items:
<%
  params = all_parameters & [:x, :y]
  params_count = params.size
  symbols = wrapper_symbols(params_count) # "[ ]" or "{ }"
%>
<%= symbols[:start] %>
<%
ext_attrib_list = []
params.each do |key, value|
  k = key.to_s.gsub('-', '_')
  ext_attrib_list << "#{k}    : " + send(k, attributes, parameters)
end
%>
<%= ext_attrib_list.join(",\n") %>

<%#= do_list(all_parameters, [:x, :y]) %>
<%= symbols[:end] %>
</def>


<def tag="x" attrs="xa">
  <%= ext_config(all_attributes & attrs_for(:x), nil) %>
</def>

<def tag="y" attrs="ya">
  <%= ext_config(all_attributes & attrs_for(:y), nil) %>
</def>

---
Helper module
--

module ExtjsHelper

  def attrs_always_skip
    [:show]
  end

  def do_list(all_params, tag_symbols)
    ext_attrib_list = []
    all_params.each do |key, value|
      ext_attrib_list << "#{key.to_s}    : #{send(key, nil,
all_params)},"
    end
    ext_attrib_list.join(",\n")
  end

  def wrapper_symbols(c)
    if c > 1
      {:start => "[", :end => "]"}
    else
      {:start => "{", :end => "}"}

    end
  end

  def var_new_component(tag_decl_attrs, all_attr_values, params)
    s = ""
    s = "var #{var} = " if var
    s << "new Ext.#{name.humanize}({"
    s << component_config(tag_decl_attrs, all_attr_values, params)
  end

  def component_config(tag_decl_attrs, all_attr_values, params)
    tag_attr_values = all_attr_values & tag_decl_attrs
    config_attr_values = ext_attrs(tag_attr_values)
    ext_config(config_attr_values, params)
  end

  # subtract attrs_skip from attrs
  def ext_attrs(values, attrs_skip = [])
    result = values.except *attrs_always_skip
    return result
  end

  # take a map of symbol => value and convert to joined list
  # of "symbol1  : value1, symbol2  : value2, ..."
  def ext_config(values, params)
    ext_attrib_list = []
    if values
      values.each do |key, value|
        # value = special_rules(key, value)
        ext_attrib_list << "#{key.to_s}    : #{value}"
      end

      result = ext_attrib_list.join(",\n")
      # add comma conditionally
      result << "," if ext_attrib_list.size > 0 && (params &&
params.size > 0)
      return result
    else
      ""
    end
  end

  def special_rules(key, value)
    if key == 'renderTo' && value == '#body'
      value = "Ext.getBody()"
    elsif value[0] == '#'
      dom_id = value[0.value.size]
      value = "Ext.get(#{dom_id})"
    end
    value
  end

  def array_start(array_value)
    "#{key} : [" if array_value
  end

  def array_end(array_value)
    "]" if array_value
  end


end


--~--~---------~--~----~------------~-------~--~----~
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