Module: ExpressAdmin::Menu
- Defined in:
- lib/express_admin/menu.rb
Overview
Provide menus for Express Admin addon engines.
To use:
1) include ExpressAdmin::Menu::Loader in your engine.rb 2) add a config/menu.yml defining the menu structure
Example:
title: 'Blog'
path: 'express_blog.admin_blog_posts_path'
items:
-
title: 'Posts'
path: 'express_blog.admin_blog_posts_path'
-
title: 'Categories'
path: 'express_blog.admin_blog_categories_path'
Defined Under Namespace
Modules: Loader Classes: MenuItem
Class Method Summary collapse
-
.[](addon_name) ⇒ Object
Return the top level MenuItem for the addon or defined in the supplied path.
- .from(yaml_path) ⇒ Object
Class Method Details
.[](addon_name) ⇒ Object
Return the top level MenuItem for the addon or defined in the supplied path.
Accepts an addon_name such as :express_admin or a path to a yaml file containing a menu definition.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/express_admin/menu.rb', line 26 def self.[](addon_name) ||= {} [addon_name.to_sym] ||= begin = if addon = Gem.loaded_specs[addon_name] File.join(addon.full_gem_path, 'config', 'menu.yml') else File.join(Rails.root, 'config', 'menu.yml') end from() end end |
.from(yaml_path) ⇒ Object
39 40 41 42 |
# File 'lib/express_admin/menu.rb', line 39 def self.from(yaml_path) raise "unable to locate #{yaml_path}" unless File.exists?(yaml_path) MenuItem.new YAML.load_file(yaml_path).with_indifferent_access end |