hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

Markaby's Magic-Permeation Branch #

by why in inspect

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="/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'}" } }

said on 18 May 2006 at 12:00

And are we going to get a nice way to html escape too? Please? At one time—I think 0.3—text did it, but in 0.4 it does not do that anymore. And this is just ugly:

div.note { @helpers.simple_format CGI::escapeHTML(@organisation.note) }
said on 18 May 2006 at 12:10
 div.note @organisation.note
said on 18 May 2006 at 13:09

Which is to say:

 div.note @helpers.simple_format(@organisation.note)
said on 18 May 2006 at 14:52

sooperb, look forward to this appearing in my svn up

said on 18 May 2006 at 16:48

I love Markaby!

However, it seems to output an XML string before the doctype declaration that forces Internet Explorer into quirks mode.

Has anyone else experienced this? Is there a way to turn it off, or is it part of the builder?

Example: My Site, Narmo

said on 18 May 2006 at 18:12

Thanks, topfunky.

said on 18 May 2006 at 19:47

that NARMO site, is sending 1+ meg of crappy images on every load. that is just wrong!

said on 19 May 2006 at 00:24

It would be super awesome if you didn’t ignore every single mail I send you, why.

said on 19 May 2006 at 12:20

Ouch. I deserved that. It’s true that I am totally undisciplined in every way which can be conceived off. (Off to find tilman’s messages…)

said on 19 May 2006 at 13:05

I love the idea behind markaby, though I’ve yet to actually use it for anything (I hope to use it in the near future). It inspired me to create the Artisan library for swift creation of DSLs. (Not entirely shameless plug!)

said on 19 May 2006 at 14:26

@topfunky: you can also use

Markaby::Builder.set :output_xml_instruction, false
said on 19 May 2006 at 14:28

Scott Barron started a CSS builder library that is currently in the XML Builder trunk. I’m debating between using that and using the ideas of Markaby to make a CSS generator (Starkaby?).

Scott’s library is a little bit different than Markaby and it would be nice to have a similar syntax instead of switching between the two.

And I’ll use the trac next time for the bugs. Thanks, why!

said on 19 May 2006 at 18:48

mmh. I can’t understand how this new streams thing is working. looking at the code did not help. please reveal the magic :)

unfortunately, it didn’t solve this:
a :href => @helpers.home_url do
  image_tag logo, :id => 'logo'
end

still doesn’t work without @helpers.

how exactly does Markaby decide “when you’re using a helper like a string”?

I found out that @helpers in the Rails plugin is nothing more than the ActionView instance rendering the template. so it provides more than helper methods, eg. the method controller. while very useful, the name “helpers” is misleading in this case. a synonym (@view? @my?) might help.

Markaby is great. I use it on my website.

said on 20 May 2006 at 00:03

Bravo, Max!

said on 20 May 2006 at 10:41

Thankyou, murphy! I’d only been testing this branch with Camping. Rails helpers weren’t done right, svn up and give it another swing please.

said on 20 May 2006 at 11:16

nope, still doesn’t work. perhaps it is something very deep; I post the exact code bit.

td.logo do
  link_to capture { image_tag(logo, :alt => 'CodeRay logo', :id => 'logo') }, home_url
end

prints the home_url before the link.

actually, the whole thing doesn’t work here: your div-h1-string example above only prints out empty div and h1 tags in my document. the output seems to depend on where you put it.

maybe it’s a Rails-only problem.

said on 20 May 2006 at 16:27

Okay, we’re going to try the Fragment as an absolute delegate for the String class it holds. You call any method and the trap is sprung. Hang in there, murph, this may continue to take some revisions.

But update and, please use this instead:

 td.logo do
   link_to image_tag(logo, :alt => 'CodeRay logo', :id => 'logo'), home_url
 end
said on 21 May 2006 at 19:21

I love markaby but I can not find it’s home. I have some patches (One which fixes the doctype error in markaby’s output that may fix topfunky’s IE woes) but have no place to share my changes. The rubyforge project page seems to be a dead end. Please tell us where the secret dev site is so we can contribute!

said on 21 May 2006 at 23:28

The home of.

Tim and I have been pounding out the new branch all weekend. This is so much better than any previous version.

Comments are closed for this entry.