A simple menubar
Jul 20, 2009
Recently I have been trying to prototype an application and have needed a way to set the navigation bar during the initial development. So, here is a simple menubar I use while I am building apps.
In my rails applib/eightsquarestudio/menu_bar_builder.rb
module EightSquareStudio::MenuBarBuilder
protected
def self.controller_list(skip_routes=[])
list = ActionController::Routing.possible_controllers
skip_routes.concat(%w( rails/info rails_info application)).each do |item|
list.delete(item)
end
return list
end
end
module ApplicationHelper
def menubar_builder(controller, *skip_routes, &block)
result = []
block ||= lambda do |c|
link_to_unless(controller.controller_name == c, c.singularize, {:controller => c}) do |name|
link_to(name, {:controller => c}, {:class => 'current'})
end
end
EightSquareStudio::MenuBarBuilder.controller_list(skip_routes).each do |c|
result << block.call(c)
end
return "<div class='tab'>#{result.join("</div><div class='tab'>")}</div>"
end
end
If I get a chance I will wrap it into a plugin. If you have any comments or suggestions. Please email me mail at eightsquarestudio dot com
Posted by Thomas Cowell
© Copyright 2009 Eight Square Limited. All Rights Reserved.
Is Cloud Computing Something New?
Merry Christmas and a Happy New Year