On Aug 16, 2011, at 8:11 PM, Arthur Baldwin wrote:

> I would very much like to hear from an expert in regard to this problem.  At 
> least let me know if this is considered a bug or not.
> At least that way, I can focus my attention on something else until it is 
> resolved.
> 
> Arthur
> 
> From: Arthur Baldwin <[email protected]>
> To: "[email protected]" <[email protected]>
> Sent: Tuesday, August 16, 2011 2:25 PM
> Subject: Re: [Hobo Users] Possible Bug in Hobo 1.3
> 
> If anyone knows of another addition that I can add to the following code in 
> order to make the "show page" display "Arthur E. Baldwin" instead of 
> "Customer"....I would appreciate it very much if you could let me know what 
> that syntax looks like.
> 
> fields do
>    fullname    :string, :name => true
>    address     :string
>    timestamps
> end

Alright, got some time to poke around and here's what I found. The generated 
code (from pages.dryml) looks like this:

            <h2 param="heading">
              <ht key="<%= model_key %>.show.heading" 
name="&this.respond_to?(:name) ? this.name : ''">
                <name/>
              </ht>
            </h2>

The relevant part from the generated hobo.en.yml:

    show:
      title: "%{model}"
      heading: "%{model} %{name}"

The first problem is that the code that sets the name attribute being passed to 
ht isn't nearly as general as the code that <name /> would run in the absence 
of a translation. (the name tag handles name_attribute correctly)

The second issue is that, even given a model that actually responds to 'name', 
the translation doesn't match the un-translated version since there's that 
extra %{model} in there.

To resolve the first problem, I think we need a new helper 'name_for':

def name_for(obj)
  if (name_attr = obj.class.try_name_attribute)
    obj.send(name_attr)
  else
    obj.try.name
  end
end

This would convert the pages.dryml code to:

            <h2 param="heading">
              <ht key="<%= model_key %>.show.heading" name="&name_for(this)">
                <name/>
              </ht>
            </h2>

As to the second one, that's mostly a question of style. It would match the 
code inside the <ht> if we changed en.hobo.show.heading to just '%{name}' - 
thoughts?

--Matt Jones

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