How about a helper:
%p= error_helper(error)
def pre_code
open(:pre) do
open(:code) do
yield
end
end
end
def error_helper(error)
pre_code{puts error.backtrace.join("\n")}
end
I haven't tested this, but it should oughta work, and you can user
pre_code for any other plain-text stuff you want.
Thoughts?
On Sep 20, 2007, at 3:03 PM, Bob Aman wrote:
>
> So I've got this chunk of HAML... and it sucks.
>
> %p An error has occurred while processing the request:
> %p= error.message
> - if error.respond_to?(:backtrace) && error.backtrace != nil
> %p
> ~ "<pre><code>" + error.backtrace.join("\\n") + "</code></pre>"
> - else
> %p Backtrace is unavailable.
>
> I'd really prefer not to have to resort to Ruby evaluation to get this
> to work. It seems to me that this should really Just Work. If I was
> working within Rails, I might clean this up with a pre_code_tag helper
> or something, but this is in an application that is independent of
> ActionView, Rails helper classes, etc., and I don't want to clutter up
> my execution context with a pre_code_tag method.
>
> This is really what I'd like to write instead (or something akin to
> it):
>
> %p An error has occurred while processing the request:
> %p= error.message
> - if error.respond_to?(:backtrace) && error.backtrace != nil
> %p
> :noautoindent
> %pre
> %code
> = preserve(error.backtrace.join("\\n"))
> - else
> %p Backtrace is unavailable.
>
> This is the output I need to be getting:
>
> <p>
> An error has occurred while processing the request:
> </p>
> <p>
> Unable to service request, no route found matching '/foo/bar/?
> query=baz'.
> </p>
> <p>
> <pre><code>(irb):2:in `irb_binding'
/usr/local/lib/ruby/1.8/
> irb/workspace.rb:52:in `irb_binding'
/usr/local/lib/ruby/1.8/
> irb/workspace.rb:52</code></pre>
> </p>
>
> Thoughts?
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---