danielharan / semantic-menu Goto Github PK
View Code? Open in Web Editor NEWA plugin to make rails menus easier to write
License: MIT License
A plugin to make rails menus easier to write
License: MIT License
Hi there,
I've just installed the plugin, but when i try out the example code in my view:
<%= semantic_menu :class => 'top_level_nav' do |root|
root.add "overview", "root_path"
end %>
I get the following error:
uninitialized class variable @@controller in MenuItem
Any help would be greatly appreciated, i'm hoping i've done something daft.
Thanks in advance
This is due to how the controller instance is passed into the SemanticMenu intializer. Still, to get this instance to each
module MenuHelper
def semantic_menu(opts={}, &block)
# controller is not available in this context, but @controller is
SemanticMenu.new(opts, &block).to_s(controller)
end
end
#...
ActionView::Base.send :include, MenuHelper
Additionally, we need to fix how the child menu items are being passed a controller instance.
class SemanticMenu < MenuItem
def initialize(opts={},&block)
@opts = {:class => 'menu'}.merge opts
@level = 0
@children = []
yield self if block_given?
end
def to_s(controller=nil)
@controller = controller
# we need to pass the @controller instance to each child as well
content_tag(:ul, @children.collect(&:to_s).join, @opts)
end
end
The current version is sadly incompatible with Rails 3. The following stack is displayed when attempting to use it:
"undefined local variable or method request' for #<MenuItem:0xa1c9c88>" actionpack (3.0.0.beta4) lib/action_view/helpers/url_helper.rb:570:in
current_page?'
vendor/plugins/semantic-menu/lib/semantic_menu.rb:42:in on_current_page?' vendor/plugins/semantic-menu/lib/semantic_menu.rb:37:in
active?'
vendor/plugins/semantic-menu/lib/semantic_menu.rb:25:in to_s' vendor/plugins/semantic-menu/lib/semantic_menu.rb:58:in
collect'
vendor/plugins/semantic-menu/lib/semantic_menu.rb:58:in to_s' vendor/plugins/semantic-menu/lib/menu_helper.rb:19:in
semantic_menu'
actionpack (3.0.0.beta4) lib/action_view/template.rb:134:in `block in render'
...
Hopefully this can be fixed, I'll update this issue in case I come across any!
Hello.
I am using semantic-menu in my application. Right now, when I click on one of the options in the menu, it will expand and it is going to show all the children. What I would like to do, is to set a default link once it is clicked, so it will go to a link and then it will expand the rest of the options? I have tried to add the link in the root, the same was as the links without children, but I am not getting the result I expect to have.
Hi there,
I've just set this up with 1 level of sub nav items and selecting one of the child links it's parent isn't being flagged as an active link.
Thanks again in advance,
Alan
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.