Tuesday, September 22, 2009

Minor Details, The End?

‹prev | My Chain | next›

More minor little details tonight. First up, links to Amazon.com cookbooks in Haml:
%div
Find cookbooks from
%a{:href => "http://www.amazon.com/exec/obidos/redirect-home/#{AMAZON_ASSOCIATE_ID}"}><
Amazon.com
\:
That produces slightly less than optimal display:



Sigh. Haml is awesome for some things, but messing about with whitespace is not one of them. I want to remove whitespace from after the link to Amazon.com (so that the colon is immediately after the link). There should be whitespace after the text "Find cookbooks from" and the link. There also should be no whitespace inside the link.

Haml uses a trailing > to remove whitespace around tags and a trailing < to remove whitespace inside the tag. There is a mnemonic to go with them, but I always have to look up which is which.

At any rate, I end up with this Haml to do the trick:
%div
Find cookbooks from
=" "
%a{:href => "http://www.amazon.com/exec/obidos/redirect-home/#{AMAZON_ASSOCIATE_ID}"}><
Amazon.com
\:
Like I said, Haml does not excel when dealing with whitespace.

To link to the actual cookbook searches, I create a helper with my Amazon referral ID embedded in it. Using that helper:
%div
Find cookbooks from
=" "
%a{:href => "http://www.amazon.com/exec/obidos/redirect-home/#{AMAZON_ASSOCIATE_ID}"}><
Amazon.com
\:
=" "
= @recipe['tag_names'].map{|tag| amazon_cookbook(tag)}.join(", ")
That gets the search links working as desired:




In addition to mucking with whitespace, I also get Google Ads placed at the bottom of the page.

That should just about do it for the minor cleanup. Tomorrow, I may do a little benchmarking and possibly explore implementing some caching on the site.

No comments:

Post a Comment