I am trying to extend DRYML with the ability to define a join string
on a container tag to use to join between the rendering of each child
tag:

I found this in dryml.rb

    def render_tag(view, tag, options={})
      renderer = empty_page_renderer(view)
      renderer.render_tag(tag, options)
    end

Now tracking the renderer, I get to

    def page_renderer(view, local_names=[], page=nil, filename=nil)

which ends by returning

renderer_class.new(page, view)

which comes from

          renderer_class = make_renderer_class(File.read(filename),
filename, local_names,
                                               DEFAULT_IMPORTS,
included_taglibs)

and filename:
                       # Rails 2.3
                       view.view_paths.find_template(page +
".dryml").filename

    def make_renderer_class(template_src, template_path, locals,
imports, included_taglibs=[])
      renderer_class = Class.new(TemplateEnvironment)
      compile_renderer_class(renderer_class, template_src,
template_path, locals, imports, included_taglibs)
      renderer_class
    end

Which ends up creating a Hobo::Dryml::Template which is loaded and
used to compile (creating the final erb which is then executed!)...

template.rb

    def node_to_erb(node)
      case node

      # v important this comes before REXML::Text, as REXML::CData <
REXML::Text
      when REXML::CData
        REXML::CData::START + node.to_s + REXML::CData::STOP

      when REXML::Comment
        REXML::Comment::START + node.to_s + REXML::Comment::STOP

      when REXML::Text
        strip_suppressed_whiteaspace(node.to_s)

      when REXML::Element
        element_to_erb(node)
      end
    end

which ends up calling

    def def_element(el, extend_tag=false)
      require_toplevel(el)
      require_attribute(el, "tag", DRYML_NAME_RX)
      require_attribute(el, "attrs", /^\s*#{DRYML_NAME}(\s*,\s*#
{DRYML_NAME})*\s*$/, true)
      require_attribute(el, "alias-of", DRYML_NAME_RX, true)

So I guess I should extend here, inserting my 'join' attribute?

>>> join_str = el.attributes['join']

      alias_of = el.attributes['alias-of']

      res = if alias_of
              "<% #{tag_newlines(el)} %>"
            else
              src = tag_method(name, el, extend_tag) +
                "<% _register_tag_attrs(:#{ruby_name name}, #
{declared_attributes(el).inspect.underscore}) %>"

              logger.debug(restore_erb_scriptlets(src)) if
el.attributes["debug-source"]

              @builder.add_build_instruction(:def,
                                             :src =>
restore_erb_scriptlets(src),
                                             :line_num =>
element_line_num(el))
              # keep line numbers matching up
              "<% #{"\n" * src.count("\n")} %>"
            end

And tag_method ends with this,

      src = "<% def #{name}(all_attributes={}, all_parameters={}); " +
        "parameters = Hobo::Dryml::TagParameters.new(all_parameters, #
{param_names.inspect.underscore}); " +
        "all_parameters = Hobo::Dryml::TagParameters.new
(all_parameters); " +
        tag_method_body(el) +
        "; end#{alias_statement} %>"
      @extend_key = nil
      src

Where tag_method_body(el) looks interesting...

hmm... tracking further I find this in :     def
static_tag_to_method_call(el)

      if el.children.empty?
        dryml_exception("part attribute on empty static tag", el) if
part

        "<%= " + apply_control_attributes("element(:#{el.name}, #
{attrs}, nil, true, #{!el.has_end_tag?} #{tag_newlines(el)})", el) + "
%>"
      else
        if part
          body = part_element(el, children_to_erb(el))
        else
          body = children_to_erb(el)
        end

        output_tag = "element(:#{el.name}, #{attrs}, new_context { %>#
{body}<% })"
        "<% concat(" + apply_control_attributes(output_tag, el) + ")
%>"
      end

Which looks like it's exactly what I am looking for ;)
But why is this method called with el an NOT with el.children?

    def children_to_erb(nodes)
      nodes.map { |x| node_to_erb(x) }.join
    end

So maybe I need to extend this with a join character somehow? What is
in a node I wonder?

I guess it could be changed into something like this:

def children_to_erb(parent, nodes)
    if parent.join_string
      map { |x| node_to_erb(x) }.join(parent.join_string)
    else
      map { |x| node_to_erb(x) }.join
    end
  end
end

Except, currently this method doesn't take a parent argument

And in the DRYML builder I find the children

DOM.Builder = {
        tagFunc : function(tag) {
    return function() {
     var attrs, children;
     if (arguments.length>0) {
       if (arguments[0].constructor == Object) {
         attrs = arguments[0];
         children = Array.prototype.slice.call(arguments, 1);
       } else {
         children = arguments;
       };
       children = $A(children).flatten()
     }
     return DOM.Builder.create(tag, attrs, children);
    };
  },
        create : function(tag, attrs, children) {
                attrs = attrs || {}; children = children || []; tag = 
tag.toLowerCase
();
                var el = new Element(tag, attrs);

                for (var i=0; i<children.length; i++) {
                        if (typeof children[i] == 'string')
                          children[i] = document.createTextNode(children[i]);
                        el.appendChild(children[i]);
                }
                return $(el);
        }
};

So I am bit lost as how to approach this... anyone?

Kristian

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