The issue is that the regular expression can't balance "{", so it tries 
to make the attributes hash out of everything between the first "{" and 
the last "}". Thus, if you do something like %td{:colspan => "2"}= 
h("Invoice #{invoice.remote_number}") it tries to make an attribute hash 
out of {:colspan => "2"}= h("Invoice #{invoice.remote_number}, which of 
course fails. I'm not sure why it wasn't failing for you; try this 
simpler example:

%p{:foo => 'bar'} {}

This is something we plan to fix before 2.0.

- Nathan

Russell Norris wrote:
> Pardon my ignorance but what exactly _is_ the bug here? I was trying 
> to help Spongy on #rubyonrails with this problem. I'm willing to poke 
> around more if I understood why it's failing there. I use the same 
> exact %tr{:colspan => 6}= line in my code and it works fine. I 
> couldn't figure out the problem.
>
> RSL
>
> On 7/23/07, *Nathan Weizenbaum* <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
>
>
>     Unfortunately, this is a known bug that's very hard to solve. Since we
>     use a regular expression to parse tags, there's no way to handle
>     balanced characters like '{' and '}'. The only way to really solve
>     this
>     would be to move to manually parsing the tag. This is something
>     we'd be
>     interested in, so if you want to work up a patch for it, go for it
>     (check out render_tag in lib/haml/engine.rb).
>
>     - Nathan
>
>     Spongy wrote:
>     > I've been having some problems with one of my templates.
>     >
>     > These are the template sections and errors I've been getting
>     (also at
>     > http://pastie.caboo.se/81401 <http://pastie.caboo.se/81401>)
>     >
>     > ## HAML snippet
>     >       - payment.invoices.each do |invoice|
>     >         %tr.invoice
>     >           %td{:colspan => "2"}= h("Invoice
>     #{invoice.remote_number}")
>     >           %td= number_to_currency(invoice.amount, :unit =>
>     "&pound;")
>     >           %td
>     >
>     > ## Error
>     > (eval):43:in `compile': compile error
>     > (eval):32: syntax error, unexpected '}', expecting ')'
>     > _hamlout.open_tag("td", nil, true, {}, nil, "\")", :colspan => "2"}=
>     > h("Invoice #{invoice.remote_number)
>     >                                                                    ^
>
>     > (eval):32: syntax error, unexpected ')', expecting '}'
>     > (eval):38: syntax error, unexpected kEND, expecting '}'
>     > (eval):42: syntax error, unexpected kEND, expecting '}'
>     >
>     > ## Full Template
>     > - page_title "Your Payments"
>     >
>     > %table
>     >   %thead
>     >     %tr
>     >       %th ID
>     >       %th Invoices
>     >       %th Amount
>     >       %th Paid on
>     >   %tbody
>     >     - @payments.each do |payment|
>     >       %tr.payment
>     >         %td= h "Payment #{payment.id <http://payment.id>}"
>     >         %td= h payment.invoices.count
>     >         %td= h payment.amount
>     >         %td= payment.paid_at ?
>     payment.paid_at.strftime("%m/%d/%Y") :
>     > 'UNPAID'
>     >       - payment.invoices.each do |invoice|
>     >         %tr.invoice
>     >           %td{:colspan => 2}= h("Invoice #{invoice.remote_number}")
>     >           %td= number_to_currency(invoice.amount, :unit =>
>     "&pound;")
>     >           %td blank
>     >
>     > ## Attempt 2 Template
>     > - page_title "Your Payments"
>     >
>     > %table
>     >   %thead
>     >     %tr
>     >       %th ID
>     >       %th Invoices
>     >       %th Amount
>     >       %th Paid on
>     >   %tbody
>     >     - @payments.each do |payment|
>     >       %tr.payment
>     >         %td{:test => :thing}= h "Payment #{payment.id
>     <http://payment.id>}"
>     >         %td= h payment.invoices.count
>     >         %td= h payment.amount
>     >         %td= payment.paid_at ?
>     payment.paid_at.strftime("%m/%d/%Y") :
>     > 'UNPAID'
>     >       - payment.invoices.each do |invoice|
>     >         %tr.invoice
>     >           %td{:colspan => 2}= h("Invoice #{invoice.remote_number}")
>     >           %td= number_to_currency(invoice.amount, :unit =>
>     "&pound;")
>     >           %td blank
>     >
>     > ## Attempt 2 Error
>     > (eval):42:in `compile': compile error
>     > (eval):13: syntax error, unexpected '}', expecting ')'
>     > _hamlout.open_tag("td", nil, true, {}, nil, "\"", :test =>
>     :thing}= h
>     > "Payment #{payment.id <http://payment.id>)
>     >                                                                   ^
>     > (eval):13: syntax error, unexpected ')', expecting '}'
>     > (eval):28: syntax error, unexpected kDO_BLOCK, expecting '}'
>     >  payment.invoices.each do |invoice|
>     >                          ^
>     > (eval):31: syntax error, unexpected '}', expecting ')'
>     > _hamlout.open_tag("td", nil, true, {}, nil, "\")", :colspan => 2}=
>     > h("Invoice #{invoice.remote_number)
>     >                                                                  ^
>     > (eval):31: syntax error, unexpected ')', expecting '}'
>     > (eval):37: syntax error, unexpected kEND, expecting '}'
>     > (eval):41: syntax error, unexpected kEND, expecting '}'
>     >
>     > Eventually I tried changing the "Payment" and "Invoice" strings to
>     >     ["Payment", payment.id <http://payment.id>].join(' ')
>     > and the errors have disappeared.
>     >
>     > I am using r570 and also had the same problem on r566
>     >
>     > Any ideas on how or what this is caused by and I can poke around in
>     > the engine.
>     >
>     > Cheers,
>     > Geoff
>     >
>     >
>     > >
>     >
>     >
>
>
>
>     >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Haml" 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/haml?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to