Class: Decidim::DecidimAwesome::MenuHacker
- Inherits:
-
Object
- Object
- Decidim::DecidimAwesome::MenuHacker
- Includes:
- TranslatableAttributes
- Defined in:
- lib/decidim/decidim_awesome/menu_hacker.rb
Instance Method Summary collapse
-
#initialize(name, view) ⇒ MenuHacker
constructor
A new instance of MenuHacker.
-
#items(include_invisible: false) ⇒ Object
returns a combined array of the Decidim defined menu and the hacked stored as config vars.
Constructor Details
#initialize(name, view) ⇒ MenuHacker
Returns a new instance of MenuHacker.
8 9 10 11 12 13 |
# File 'lib/decidim/decidim_awesome/menu_hacker.rb', line 8 def initialize(name, view) @name = name @organization = view.try(:current_organization) @user = view.try(:current_user) @view = view end |
Instance Method Details
#items(include_invisible: false) ⇒ Object
returns a combined array of the Decidim defined menu and the hacked stored as config vars
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/decidim/decidim_awesome/menu_hacker.rb', line 16 def items(include_invisible: false) return @items if @items @items = default_items .each do |item| default = default_items.find { |i| i.url.gsub(/\?.*/, "") == item.url } if default item.send("overrided?=", true) item[:original_active] = default.active @items.reject! { |i| i.url.gsub(/\?.*/, "") == item.url } end @items << item end @items.select!(&:visible?) unless include_invisible @items.sort_by!(&:position) end |