Class: Lipsiadmin::AccessControl::Menu
- Inherits:
-
Object
- Object
- Lipsiadmin::AccessControl::Menu
- Includes:
- ActionController::UrlWriter, Helper
- Defined in:
- lib/access_control/base.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#add(name, path = nil, options = {}, &block) ⇒ Object
Add a new submenu to the menu.
-
#allowed ⇒ Object
Return allowed controllers.
-
#config ⇒ Object
Return ExtJs Config for this menu.
-
#human_name ⇒ Object
Return the original name or try to translate or humanize the symbol.
-
#initialize(name, path = nil, options = {}) {|_self| ... } ⇒ Menu
constructor
:nodoc:.
-
#uid ⇒ Object
Return a unique id for the given project module.
-
#url ⇒ Object
Return the url of this menu.
Methods included from Helper
Constructor Details
#initialize(name, path = nil, options = {}) {|_self| ... } ⇒ Menu
:nodoc:
187 188 189 190 191 192 193 194 195 |
# File 'lib/access_control/base.rb', line 187 def initialize(name, path=nil, ={}, &block)#:nodoc: @name = name @url = path = @allowed = [] @items = [] @allowed << { :controller => recognize_path(path)[:controller] } if @url yield self if block_given? end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
185 186 187 |
# File 'lib/access_control/base.rb', line 185 def items @items end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
185 186 187 |
# File 'lib/access_control/base.rb', line 185 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
185 186 187 |
# File 'lib/access_control/base.rb', line 185 def end |
Instance Method Details
#add(name, path = nil, options = {}, &block) ⇒ Object
Add a new submenu to the menu
203 204 205 |
# File 'lib/access_control/base.rb', line 203 def add(name, path=nil, ={}, &block) @items << Menu.new(name, path, , &block) end |
#allowed ⇒ Object
Return allowed controllers
208 209 210 211 |
# File 'lib/access_control/base.rb', line 208 def allowed @items.each { |i| @allowed.concat i.allowed } @allowed.uniq end |
#config ⇒ Object
Return ExtJs Config for this menu
224 225 226 227 228 229 230 231 232 233 |
# File 'lib/access_control/base.rb', line 224 def config if @url.blank? && @items.empty? = human_name else = .merge(:text => human_name) .merge!(:menu => @items.collect(&:config)) if @items.size > 0 .merge!(:handler => "function(){ Backend.app.load('#{url}') }".to_l) if !@url.blank? end end |
#human_name ⇒ Object
Return the original name or try to translate or humanize the symbol
214 215 216 |
# File 'lib/access_control/base.rb', line 214 def human_name @name.is_a?(Symbol) ? I18n.t("backend.menus.#{@name}", :default => @name.to_s.humanize) : @name end |
#uid ⇒ Object
Return a unique id for the given project module
219 220 221 |
# File 'lib/access_control/base.rb', line 219 def uid @name.to_s.downcase.gsub(/[^a-z0-9]+/, '').gsub(/-+$/, '').gsub(/^-+$/, '') end |
#url ⇒ Object
Return the url of this menu
198 199 200 |
# File 'lib/access_control/base.rb', line 198 def url @url.is_a?(Hash) ? url_for(@url.merge(:only_path => true)) : @url end |