Class: Ramenu::Menus::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/ramenu/menus.rb

Overview

Represents a navigation element in the menu collection.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path, options = {}) ⇒ Element

Initializes the Element with given parameters.

Parameters:

  • name (String)

    The element/link name.

  • path (String)

    The element/link URL.

  • options (Hash) (defaults to: {})

    The element/link URL.



139
140
141
142
143
144
145
146
# File 'lib/ramenu/menus.rb', line 139

def initialize(name, path, options = {})
  self.name     = name
  self.path     = path
  self.childs   = []
  #self.parent   = @options[:parent]
  self.parent   = options.delete(:parent)
  self.options  = options
end

Instance Attribute Details

#childsHash

Returns The element/link childs.

Returns:

  • (Hash)

    The element/link childs



126
127
128
# File 'lib/ramenu/menus.rb', line 126

def childs
  @childs
end

#nameString

Returns The element/link name.

Returns:

  • (String)

    The element/link name.



122
123
124
# File 'lib/ramenu/menus.rb', line 122

def name
  @name
end

#optionsHash

Returns The element/link URL.

Returns:

  • (Hash)

    The element/link URL.



130
131
132
# File 'lib/ramenu/menus.rb', line 130

def options
  @options
end

#parentElement

Returns The element/link parent.

Returns:

  • (Element)

    The element/link parent



128
129
130
# File 'lib/ramenu/menus.rb', line 128

def parent
  @parent
end

#pathString

Returns The element/link URL.

Returns:

  • (String)

    The element/link URL.



124
125
126
# File 'lib/ramenu/menus.rb', line 124

def path
  @path
end

Instance Method Details

#add_menu(name, path, options = {}, &block) ⇒ Object Also known as: add_child



160
161
162
163
164
# File 'lib/ramenu/menus.rb', line 160

def add_menu(name, path, options = {}, &block)
  opts = options.merge({:parent => self})
  opts.merge!(self.options.slice(:flag_for_menu))
  self.childs << Ramenu.new_ramenu_element(name, path, opts, &block)
end

#translation_keyObject



148
149
150
151
152
153
154
155
156
157
158
# File 'lib/ramenu/menus.rb', line 148

def translation_key
  key = ''
  elem = self
  while !elem.nil? do
    key = '.' + elem.name.to_s + key if elem.name.is_a?(Symbol)
    key = '.' + elem.name.to_sym.to_s + key if elem.name.is_a?(String)
    elem = elem.parent
  end
  key += '.root' if self.childs.count > 0
  return key
end