Class: Mmmenu
- Inherits:
-
Object
- Object
- Mmmenu
- Defined in:
- lib/mmmenu.rb,
lib/mmmenu/level.rb,
lib/mmmenu/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
'0.1'
Instance Attribute Summary collapse
-
#current_item ⇒ Object
Returns the value of attribute current_item.
Instance Method Summary collapse
- #build ⇒ Object
- #current_item_markup(level, options = {}, &block) ⇒ Object
-
#initialize(options, &block) ⇒ Mmmenu
constructor
A new instance of Mmmenu.
-
#item_markup(level, options = {}, &block) ⇒ Object
The following two methods define the markup for each menu item on the current and lower levels (unless lower levels are not redefined later).
-
#level_markup(level = 1, &block) ⇒ Object
Defines the markup wrapper for the current menu level and lower menu levels (unless lower levels are not redefined later).
Constructor Details
#initialize(options, &block) ⇒ Mmmenu
Returns a new instance of Mmmenu.
8 9 10 11 12 13 14 15 16 |
# File 'lib/mmmenu.rb', line 8 def initialize(, &block) @items = [:items] || Mmmenu::Level.new(&block).to_a @current_path = [:request].path.chomp('/') @request_params = [:request].params @request_type = [:request].method.to_s.downcase @item_markup = [] @current_item_markup = [] @level_markup = [] end |
Instance Attribute Details
#current_item ⇒ Object
Returns the value of attribute current_item.
6 7 8 |
# File 'lib/mmmenu.rb', line 6 def current_item @current_item end |
Instance Method Details
#build ⇒ Object
43 44 45 46 47 |
# File 'lib/mmmenu.rb', line 43 def build result = build_level[:output] @current_item = @deepest_current_item result end |
#current_item_markup(level, options = {}, &block) ⇒ Object
29 30 31 32 |
# File 'lib/mmmenu.rb', line 29 def current_item_markup(level, ={}, &block) level -= 1 @current_item_markup[level] = { :block => block, :options => } end |
#item_markup(level, options = {}, &block) ⇒ Object
The following two methods define the markup for each menu item on the current and lower levels (unless lower levels are not redefined later). Example:
@menu.item_markup(0, ) do |link, text, |
"<a href=\"#{link}\" #{}>#{text}</a>"
end
25 26 27 28 |
# File 'lib/mmmenu.rb', line 25 def item_markup(level, ={}, &block) level -= 1 @item_markup[level] = { :block => block, :options => } end |
#level_markup(level = 1, &block) ⇒ Object
Defines the markup wrapper for the current menu level and lower menu levels (unless lower levels are not redefined later). Example:
@menu.level_markup(0) { |level_content| "<div>#{level_content}</div>" }
38 39 40 41 |
# File 'lib/mmmenu.rb', line 38 def level_markup(level=1, &block) level -= 1 @level_markup[level] = block end |