Change the way links are displayed in menus in front-end

This commit is contained in:
Christophe Vilayphiou 2012-05-14 21:43:10 +08:00
parent 6c83b3f9ae
commit 8fcb8ef8de
3 changed files with 16 additions and 4 deletions

View File

@ -21,7 +21,7 @@ class PagesController < ApplicationController
when 'Page'
render_page
when 'Link'
redirect_to "http://#{@item[:url]}"
redirect_to @item[:url]
end
else
render :file => "#{Rails.root}/public/404.html", :status => :not_found

View File

@ -2,10 +2,20 @@ class Link < Item
field :url
validates_presence_of :url
validates :url, :presence => true, :format => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
before_validation :add_http
def link
ApplicationController.helpers.link_to(self.name, self.url)
end
protected
def add_http
unless self.url[/^http?s:\/\//]
self.url = 'http://' + self.url
end
end
end

View File

@ -27,7 +27,8 @@ module ParserCommon
res << "_#{i}" if i
res << " active" if (current_page.id.eql?(page.id) || current_page.descendant_of?(page))
res << "'>"
res << "<a href='/#{edit ? admin_page_path(page.id) : page.path}'><span>#{page.i18n_variable[I18n.locale]}</span></a>"
root = "/"
res << "<a href='#{edit ? root + admin_page_path(page.id) : (page._type.eql?('Page') ? root + page.path : page.url)}'><span>#{page.i18n_variable[I18n.locale]}</span></a>"
if page.visible_children.size > 0 && current <= menu.levels
res << "<span class='dot'></span>"
res << menu_level(page, current_page, current + 1, menu, edit)
@ -119,7 +120,8 @@ module ParserCommon
res << "<ul class='list'>"
menu_page.visible_children.each do |child|
res << "<li class='#{page.id.eql?(child.id) ? 'active' : nil}'>"
res << "<a href='/#{edit ? admin_page_path(child.id) : child.path}'>#{child.i18n_variable[I18n.locale]}</a>"
root = "/"
res << "<a href='#{edit ? root + admin_page_path(child.id) : (child._type.eql?('Page') ? root + child.path : child.url)}'>#{child.i18n_variable[I18n.locale]}</a>"
res << "</li>"
end
res << "</ul>"