Monday, June 22, 2009

More Affordances

‹prev | My Chain | next›

Today I continue working on affordances that I have built up in the legacy version of the site over the years. I made progress yesterday, but still have a few remaining:

  • Meals on odd numbered days have right-aligned thumbnails on the homepage (added "depth")

  • Text links to older meals at the bottom of the meals section of the homepage

  • Category links on all pages (I only have them on the meal and recipe pages)

Even/Odd Meal Thumbnail Alignment

I will accomplish the actual alignment via CSS (as opposed to an align attribute on the thumbnail's <img> tag). To get the odd/even day of the month to drive the alignment of the thumbnail, I only need a simple modulo 2 of the day:
    %div{:class => "meal meal#{date.day % 2}"}
No tests are needed for this—there is no semantic information or behavior being driven. Just a little something to break up the monotony of the homepage.

Older Meals

In addition to the 10 meal summaries on the homepage, we also provide 3 additional links to older meals. In the Sinatra application, I am already pulling back 13 meals:
  url = "#{@@db}/_design/meals/_view/by_date?limit=13&descending=true"
data = RestClient.get url
@meal_view = JSON.parse(data)['rows']
I had been ignoring the last three meals. Instead, I pull back all 13 meals and then slice the last 3 from the list:
  @older_meals = @meals.slice!(10,3) || []
With the Sinatra app pulling back the older meals, it is time to drive the homepage view. The @older_meals instance variable should hold meals such as:
      assigns[:older_meals] =
[{ "_id" => "2009-04-15",
"date" => "2009-04-15",
"title" => "Foo"
}] * 3
Given that, the homepage should include links to those meals:
    it "should link to the next 3" do
render("/views/index.haml")
response.should have_selector("a",
:href => "/meals/2009/04/15",
:content => "Foo")
end
I implement that in Haml with:
  .other-meals
%i Older meals:
- @older_meals.each do |meal|
- date = Date.parse(meal['date'])
%a{:href => date.strftime("/meals/%Y/%m/%d")}= meal["title"]
,

Universal Category Links

Last up today is adding category links to all pages other than the homepage. Happily, that is a simple matter of adding the categories helper to the top of a few Haml templates.

That does it for affordances for now. Tomorrow, it will be back onto the last few Cucumber scenarios.
(commit)

No comments:

Post a Comment