require 'rubygems'
require 'action_view'
require 'active_support'
class MenuItem
include ActionView::Helpers::TagHelper,
ActionView::Helpers::UrlHelper
attr_accessor :children, :link
cattr_accessor :request
def initialize(title, link, level, link_opts={})
@title, @link, @level, @link_opts = title, link, level, link_opts
@children = []
end
def add(title, link, link_opts={}, &block)
returning(MenuItem.new(title, link, @level +1, link_opts)) do |adding|
@children << adding
yield adding if block_given?
end
end
def to_s
content_tag(:li, content_tag(:div, link_to(@title, @link, @link_opts), :class => "menu_header_level_"+@level.to_s) + child_output, ({:class => 'active'} if active?)).html_safe
end
def level_class
"menu_level_#{@level}"
end
def child_output
children.empty? ? '' : content_tag(:ul, @children.collect(&:to_s).join.html_safe, :class => level_class)
end
def active?
children.any?(&:active?) || on_current_page?
end
def on_current_page?
# set it for current_page? defined in UrlHelper
# current_page?(@link)
false
end
# def request
# @@request
# end
end
class SemanticMenu < MenuItem
def initialize(rq, opts={},&block)
@@request = rq
@opts = {:class => 'menu'}.merge opts
@level = 0
@children = []
yield self if block_given?
end
def to_s
content_tag(:ul, @children.collect(&:to_s).join.html_safe, @opts).html_safe
end
end
您好。我试图改变语义菜单根的行为。当我单击其中一个根时,菜单会下拉并显示所有子项。我想要的是当我点击它,它进入默认页面,然后显示孩子。语义菜单似乎只允许链接到较低级别而不是主要链接。根链接仅在没有孩子的情况下起作用。
下面的代码是Ruby中插件中的代码。我认为是需要修改的那个。那里有html代码,但我不认为它与它有关。
你能否告诉我在父亲触发他们的链接时需要添加什么?
谢谢。
答案 0 :(得分:0)
我不知道你问题的直接答案,但SemanticMenu似乎已经过时了。
查看SimpleNavigation
gem:https://github.com/andi/simple-navigation/wiki