Haml creator releases make_breakfast
Hampton Catlin, creater of Haml and make_resourceful, announced Thursday the release of his latest plugin, make_breakfast, giving rails developers an elegant API to that most important meal of the day.
In a nutshell, make_breakfast is to breakfast what make_resourceful is to resources. It employs Ruby’s awesome meta-programming features to eliminate virtually all that “I need to hack together a controller that makes me breakfast… AGAIN” code that we’re all so sick of writing. The syntax is uber simple, and the results are super sweet – especially the pancakes.
In your controller:
class PostsController < ApplicationController
make_breakfast do
actions :cook, :serve, :clean
before :cook do
@oven_temp = 450
end
end
end
The plugin also comes with some sweet helper methods to use in your views (note that following examples use haml syntax):
# two eggs, fried
Breakfast::Maker.eggs(2, :fried)
# more eggs, this time using the plugin's dynamic method names
Breakfast::Maker.fried_eggs(2)
# two sausage links
Breakfast::Maker.sausage(2, :link)
You can also use the plugin to generate only the cleaning functionality:
class PostsController < ApplicationController
make_breakfast do
actions :clean
after :clean do
redirect_to "/"
end
end
end
The view helpers for Breakfast::Cleaner couldn’t be simpler:
# the default, an alias for clean(:all)
Breakfast::Cleaner.clean
# cleans up everything used by m_b. This includes pots, pans, dishes, silverware, glasses, linens, and more. For a full list of cleanable items, see the Breakfast::Cleanable rdoc
Breakfast::Cleaner::clean(:all)
# only cleanup pots and pans, leaving the rest for your roommate or whomever
Brekafast::Cleaner.clean([:pots, :pans])
What about RSpec? m_r has BDD support baked-in with snazzy, dynamic custom assertions. Observe:
@breakfast = Breakfast::Maker.cook(:eggs=>2, :pancakes=>3, :juice=>"orange", :toast=>"white")
@breakfast.should have_two_eggs
@breakfast.should have_white_toast
Do yourself a favor and check out make_breakfast today. You won’t be disappointed. Heck, when a rails plugin cooks you a delicious Western omelet, you’ll be downright ecstatic.
0
comments

