Class: Redmine::MenuManager::MenuItem

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

Overview

– copyright ChiliProject is a project management system.

Copyright (C) 2010-2013 the ChiliProject Team

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

See doc/COPYRIGHT.rdoc for more details. ++

Instance Attribute Summary collapse

Attributes inherited from TreeNode

#last_items_count

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

Methods inherited from TreeNode

#add, #add_at, #add_last, #position, #prepend, #remove!

Constructor Details

#initialize(name, url, options) ⇒ MenuItem

Returns a new instance of MenuItem

Raises:

  • (ArgumentError)

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/redmine/menu_manager/menu_item.rb', line 19

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

#child_menusObject (readonly)

Returns the value of attribute child_menus


17
18
19
# File 'lib/redmine/menu_manager/menu_item.rb', line 17

def child_menus
  @child_menus
end

#conditionObject (readonly)

Returns the value of attribute condition


17
18
19
# File 'lib/redmine/menu_manager/menu_item.rb', line 17

def condition
  @condition
end

#lastObject (readonly)

Returns the value of attribute last


17
18
19
# File 'lib/redmine/menu_manager/menu_item.rb', line 17

def last
  @last
end

#nameObject (readonly)

Returns the value of attribute name


17
18
19
# File 'lib/redmine/menu_manager/menu_item.rb', line 17

def name
  @name
end

#paramObject (readonly)

Returns the value of attribute param


17
18
19
# File 'lib/redmine/menu_manager/menu_item.rb', line 17

def param
  @param
end

#parentObject (readonly)

Returns the value of attribute parent


17
18
19
# File 'lib/redmine/menu_manager/menu_item.rb', line 17

def parent
  @parent
end

#urlObject (readonly)

Returns the value of attribute url


17
18
19
# File 'lib/redmine/menu_manager/menu_item.rb', line 17

def url
  @url
end

Instance Method Details

#caption(project = nil) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/redmine/menu_manager/menu_item.rb', line 38

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

#html_options(options = {}) ⇒ Object


52
53
54
55
56
57
58
59
60
# File 'lib/redmine/menu_manager/menu_item.rb', line 52

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