Class: Zen::Package::Menu
- Inherits:
-
Object
- Object
- Zen::Package::Menu
- Includes:
- Ramaze::Helper::ACL, Ramaze::Trinity
- Defined in:
- lib/zen/package/menu.rb
Overview
Class that represents a single navigation item that optionally contains a number of sub elements.
Instance Attribute Summary (collapse)
-
- (Object) children
readonly
All the child elements of the current navigation element.
-
- (Object) url
readonly
A string containing the URL of the current element.
Instance Method Summary (collapse)
-
- (String|NilClass) html(permissions = [])
Builds the HTML for the current navigation menu using Ramaze::Gestalt.
-
- (Menu) initialize(title, url, options = {}) {|self| ... }
constructor
Creates a new instance of the class and optionally processes all sub navigation items.
-
- (Object) menu(title, url, options = {}, &block)
Adds a new child element to the navigation menu.
-
- (String) title
Returns the title of the navigation item.
Methods included from Ramaze::Helper::ACL
#authorize_user!, #get_permissions, #user_authorized?
Constructor Details
- (Menu) initialize(title, url, options = {}) {|self| ... }
Creates a new instance of the class and optionally processes all sub navigation items.
36 37 38 39 40 41 42 |
# File 'lib/zen/package/menu.rb', line 36 def initialize(title, url, = {}) @title, @url = title, url @children = [] @options = yield(self) if block_given? end |
Instance Attribute Details
- (Object) children (readonly)
All the child elements of the current navigation element.
20 21 22 |
# File 'lib/zen/package/menu.rb', line 20 def children @children end |
- (Object) url (readonly)
A string containing the URL of the current element.
17 18 19 |
# File 'lib/zen/package/menu.rb', line 17 def url @url end |
Instance Method Details
- (String|NilClass) html(permissions = [])
Builds the HTML for the current navigation menu using Ramaze::Gestalt.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/zen/package/menu.rb', line 77 def html( = []) # Skip the navigation menu and all it's child elements if the user isn't # allowed to view it. return if !(@options[:permission]) g = Ramaze::Gestalt.new children = [] g.li do g.a(title, :href => url, :title => title) unless @children.empty? @children.each do |child| html = child.html() unless html.nil? children << html end end unless children.empty? g.ul do g.out << children end end end end return g.to_s end |
- (Object) menu(title, url, options = {}, &block)
Adds a new child element to the navigation menu.
50 51 52 |
# File 'lib/zen/package/menu.rb', line 50 def (title, url, = {}, &block) @children << self.class.new(title, url, , &block) end |
- (String) title
Returns the title of the navigation item. If possible it will be translated, otherwise the original value will be used.
61 62 63 64 65 66 67 |
# File 'lib/zen/package/menu.rb', line 61 def title begin return lang(@title) rescue return @title end end |