Class: Redmine::MenuManager::MenuItem
- Inherits:
-
Tree::TreeNode
- Object
- Tree::TreeNode
- Redmine::MenuManager::MenuItem
- Includes:
- I18n
- Defined in:
- lib/redmine/menu_manager.rb
Instance Attribute Summary collapse
-
#child_menus ⇒ Object
readonly
Returns the value of attribute child_menus.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#param ⇒ Object
readonly
Returns the value of attribute param.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #caption(project = nil) ⇒ Object
- #html_options(options = {}) ⇒ Object
-
#initialize(name, url, options) ⇒ MenuItem
constructor
A new instance of MenuItem.
Methods included from I18n
#current_language, #day_name, #find_language, #format_date, #format_time, included, #l, #l_hours, #l_or_humanize, #ll, #month_name, #set_language_if_valid, #valid_languages
Constructor Details
#initialize(name, url, options) ⇒ MenuItem
Returns a new instance of MenuItem.
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/redmine/menu_manager.rb', line 404 def initialize(name, url, ) raise ArgumentError, "Invalid option :if for menu item '#{name}'" if [:if] && ![:if].respond_to?(:call) raise ArgumentError, "Invalid option :html for menu item '#{name}'" if [:html] && ![:html].is_a?(Hash) raise ArgumentError, "Cannot set the :parent to be the same as this item" if [:parent] == name.to_sym raise ArgumentError, "Invalid option :children for menu item '#{name}'" if [:children] && ![:children].respond_to?(:call) @name = name @url = url @condition = [:if] @param = [:param] || :id @caption = [:caption] @html_options = [:html] || {} # Adds a unique class to each menu item based on its name @html_options[:class] = [@html_options[:class], @name.to_s.dasherize].compact.join(' ') @parent = [:parent] @child_menus = [:children] @last = [:last] || false super @name.to_sym end |
Instance Attribute Details
#child_menus ⇒ Object (readonly)
Returns the value of attribute child_menus.
402 403 404 |
# File 'lib/redmine/menu_manager.rb', line 402 def @child_menus end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
402 403 404 |
# File 'lib/redmine/menu_manager.rb', line 402 def condition @condition end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
402 403 404 |
# File 'lib/redmine/menu_manager.rb', line 402 def last @last end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
402 403 404 |
# File 'lib/redmine/menu_manager.rb', line 402 def name @name end |
#param ⇒ Object (readonly)
Returns the value of attribute param.
402 403 404 |
# File 'lib/redmine/menu_manager.rb', line 402 def param @param end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
402 403 404 |
# File 'lib/redmine/menu_manager.rb', line 402 def parent @parent end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
402 403 404 |
# File 'lib/redmine/menu_manager.rb', line 402 def url @url end |
Instance Method Details
#caption(project = nil) ⇒ Object
423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/redmine/menu_manager.rb', line 423 def (project=nil) if @caption.is_a?(Proc) c = @caption.call(project).to_s c = @name.to_s.humanize if c.blank? c else if @caption.nil? l_or_humanize(name, :prefix => 'label_') else @caption.is_a?(Symbol) ? l(@caption) : @caption end end end |
#html_options(options = {}) ⇒ Object
437 438 439 440 441 442 443 444 445 |
# File 'lib/redmine/menu_manager.rb', line 437 def (={}) if [:selected] o = @html_options.dup o[:class] += ' selected' o else @html_options end end |