The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Markaby's Magic-Permeation Branch

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Markaby's Magic-Permeation Branch Posted: May 18, 2006 10:32 AM
Reply to this message Reply

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
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

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

 http://code.whytheluckystiff.net/svn/markaby/branches/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'}" } }

Read: Markaby's Magic-Permeation Branch

Topic: DDJ: "Rails may [be a] historic tipping point" ! Previous Topic   Next Topic Topic: Orlando Ruby Users Group meeting tonight

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use