Class: Redmine::MenuManager::MenuItem

Inherits:
Tree::TreeNode
  • Object
show all
Includes:
I18n
Defined in:
lib/redmine/menu_manager.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

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

- (MenuItem) initialize(name, url, options)

Returns a new instance of MenuItem

Raises:

  • (ArgumentError)


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, options)
  raise ArgumentError, "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call)
  raise ArgumentError, "Invalid option :html for menu item '#{name}'" if options[:html] && !options[:html].is_a?(Hash)
  raise ArgumentError, "Cannot set the :parent to be the same as this item" if options[:parent] == name.to_sym
  raise ArgumentError, "Invalid option :children for menu item '#{name}'" if options[:children] && !options[:children].respond_to?(:call)
  @name = name
  @url = url
  @condition = options[:if]
  @param = options[:param] || :id
  @caption = options[:caption]
  @html_options = 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 = options[:parent]
  @child_menus = options[:children]
  @last = options[:last] || false
  super @name.to_sym
end

Instance Attribute Details

- (Object) child_menus (readonly)

Returns the value of attribute child_menus



402
403
404
# File 'lib/redmine/menu_manager.rb', line 402

def child_menus
  @child_menus
end

- (Object) condition (readonly)

Returns the value of attribute condition



402
403
404
# File 'lib/redmine/menu_manager.rb', line 402

def condition
  @condition
end

- (Object) last (readonly)

Returns the value of attribute last



402
403
404
# File 'lib/redmine/menu_manager.rb', line 402

def last
  @last
end

- (Object) name (readonly)

Returns the value of attribute name



402
403
404
# File 'lib/redmine/menu_manager.rb', line 402

def name
  @name
end

- (Object) param (readonly)

Returns the value of attribute param



402
403
404
# File 'lib/redmine/menu_manager.rb', line 402

def param
  @param
end

- (Object) parent (readonly)

Returns the value of attribute parent



402
403
404
# File 'lib/redmine/menu_manager.rb', line 402

def parent
  @parent
end

- (Object) url (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

- (Object) caption(project = nil)



423
424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/redmine/menu_manager.rb', line 423

def caption(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

- (Object) html_options(options = {})



437
438
439
440
441
442
443
444
445
# File 'lib/redmine/menu_manager.rb', line 437

def html_options(options={})
  if options[:selected]
    o = @html_options.dup
    o[:class] += ' selected'
    o
  else
    @html_options
  end
end