Jano Svitok
5/2/2008 7:08:00 AM
On Fri, May 2, 2008 at 4:11 AM, James Nykiel <lmv314@gmail.com> wrote:
> Thanks for the help with this, do you know if or how I can combine the
> following:
>
> ## menu.rhtml
>
> <% fname = File.basename ENV['SCRIPT_FILENAME']
>
> if fname == 'index.rhtml' %>
> Home ::
> <% else %>
> <a href="index.rhtml" title="Home">Home</a> ::
> <% end %>
>
> <% fname = File.basename ENV['SCRIPT_FILENAME']
> if fname == 'contact.rhtml' %>
> Contact ::
> <% else %>
> <a href="contact.rhtml" title="Contact">Contact</a>
>
> ::
> <% end %>
<%
def menu_item(current_filename, page_filename, page_title)
if current_filename == page_filename
page_title
else
"<a href=\"#{page_filename}\" title=\"#{page_title}\">#{page_title}</a>"
end
end
fname = File.basename ENV['SCRIPT_FILENAME']
%>
<%= menu_item(fname, "index.rhtml", "Home") %> ::
<%= menu_item(fname, "contact.rhtml", "Contact" %> ::
You can continue with storing the menu in an array, i.e.
<%
def make_menu(menu, separator)
fname = File.basename ENV['SCRIPT_FILENAME']
menu.map {|page_file, page_title| menu_item(fname, page_file,
page_title)}.join(separator)
end
MENU = [
['index.rhtml, 'Home'],
['contact.rhtml', 'Contact']
]
%>
<%= make_menu(MENU, " :: ") %>