I think something along these lines would work. I am taking the flight
home soon, and too tired to test it just now... but it looks pretty
promising! :)
Am I finally beginning to understand the DRYML rendering process
internals...?

template_environment.rb
-----------------------
    def call_tag_parameter_with_default_content(the_tag, attributes,
default_content, overriding_content_proc)

      if the_tag.is_one_of?(String, Symbol) && the_tag.to_s.in?
(Hobo.static_tags)
        body = if overriding_content_proc
                 new_context { overriding_content_proc.call(proc
{ default_content._?.call(nil) }) }
               elsif default_content
                 new_context { default_content.call(nil) }
               else
                 nil
               end
        element(the_tag, attributes, body)
      else
        d = if overriding_content_proc
              proc { |default| overriding_content_proc.call(proc
{ default_content._?.call(default) }) }
            else
              proc { |default| default_content._?.call(default) }
            end
>>>>
            # save separator (if present) as instance variabel so it
is not lost in scope change
            @separator = attributes.key?(:separator) ? attributes
[:separator] : ""

            # create default content
            out = send(the_tag, attributes, { :default => d })

            if [email protected]?
              # 1. remove empty content
              out.gsub!(/:##:/, '')

              # 2. replace end marker (with any non-whitespace coming
after), with the separator (fx ",")
              #    alternatively replace #::# with separator?
              # out.gsub!(/#::#/, @separator)

              out.gsub!(/#:\S+/, @separator)

              # 3. remove any remaining meta markers (output cleanup)
              out.gsub!(/#:/, '')
              out.gsub!(/:#/, '')
              # reset separator (state clean up!)
              @separator = ""
            else
              # output cleanup!
              out.gsub!(/#:/, '')
              out.gsub!(/:#/, '')
            end
        # render out
        out
>>>>
      end
    end


    def call_tag_parameter(the_tag, attributes, parameters,
caller_parameters, param_name)
      overriding_proc = caller_parameters[param_name]
      replacing_proc  = caller_parameters[:"#{param_name}
_replacement"]

      unless param_name == the_tag || param_name == :default
        classes = attributes[:class]
        param_class = param_name.to_s.gsub('_', '-')
        attributes[:class] = if classes
                               classes =~ /\b#{param_class}\b/ ?
classes : "#{classes} #{param_class}"
                             else
                               param_class
                             end
      end

      if param_name == :default && overriding_proc
        # :default content is handled specially

        call_tag_parameter_with_default_content(the_tag, attributes,
parameters[:default], overriding_proc)

      elsif replacing_proc
        # The caller is replacing this parameter. Don't call the tag
        # at all, just the overriding proc, but pass the restorable
        # tag as a parameter to the overriding proc

        tag_restore = proc do |restore_attrs, restore_params|
          # Call the replaced tag with the attributes and parameters
          # as given in the original tag definition, and with the
          # specialisation given on the 'restore' call

          if overriding_proc
            overriding_attributes, overriding_parameters =
overriding_proc.call
            restore_attrs  = overriding_attributes.merge
(restore_attrs)
            restore_params = overriding_parameters.merge
(restore_params)
          end

          override_and_call_tag(the_tag, attributes, parameters,
restore_attrs, restore_params)
        end
        replacing_proc.call(tag_restore)

      else
        overriding_attributes, overriding_parameters =
overriding_proc._?.call
>>>>
        # prepend and append metadata markers to output
        ":#" + override_and_call_tag(the_tag, attributes, parameters,
overriding_attributes, overriding_parameters) + "#:"
>>>>
      end
    end

Any comments to this approach?
--~--~---------~--~----~------------~-------~--~----~
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