Class: Redmine::MenuManager::MenuItem

Inherits:
Object
  • 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

#initialize(name, url, options) ⇒ MenuItem



181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/redmine/menu_manager.rb', line 181

def initialize(name, url, options)
  raise "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call)
  raise "Invalid option :html for menu item '#{name}'" if options[:html] && !options[:html].is_a?(Hash)
  @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(' ')
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition



179
180
181
# File 'lib/redmine/menu_manager.rb', line 179

def condition
  @condition
end

#nameObject (readonly)

Returns the value of attribute name



179
180
181
# File 'lib/redmine/menu_manager.rb', line 179

def name
  @name
end

#paramObject (readonly)

Returns the value of attribute param



179
180
181
# File 'lib/redmine/menu_manager.rb', line 179

def param
  @param
end

#urlObject (readonly)

Returns the value of attribute url



179
180
181
# File 'lib/redmine/menu_manager.rb', line 179

def url
  @url
end

Instance Method Details

#caption(project = nil) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/redmine/menu_manager.rb', line 194

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



208
209
210
211
212
213
214
215
216
# File 'lib/redmine/menu_manager.rb', line 208

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