This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: Markaby's Magic-Permeation Branch
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
So, Markaby is so magical it hurts, right? Well, you’ll be glad to hear that Markaby is getting a big dose of more magic! It’s our magic-permeation branch (aka xhtml-careful.)
Markaby has two big problems that really get in the way. The biggest problem is method_missing. Solution forthcoming. The second problem is helper methods in Rails.
link_to "Total is: #{number_to_human_size @file_bytes}",
:action => 'more_totals'
In current Markaby, the above won’t work. The link_to method and the number_to_human_size are both helpers methods. Markaby, by default, prefers to print out helper methods. So you’ll end up with:
10K
<a href="http://redhanded.hobix.com/c/more_totals">Total is: 10K</a>
But we want to print one out and we want to get the other back as a string. (In ERB, you differentiate with <% and <%=.) So to get the bytes back as a string:
link_to "Total is: #{@helpers.number_to_human_size @file_bytes}",
:action => 'more_totals'
By calling the @helpers var, you call the method directly and Markaby can’t intercept. However, in the saturated-with-magic branch, we’ve hooked the to_str for fragments of HTML. This means that we can tell when you’re using a helper like a string. And things get handled right. So, now you can do:
link_to "Total is: #{number_to_human_size @file_bytes}",
:action => 'more_totals'
In a couple days, we’ll talk about the solution to our method_missing problems and you can help decide if the extra voodoo is paying off.
Oh, and this also means that this will work: div { h1 { "Welcome to #{strong 'RedHanded'}" } }