Class: Dust::MenuItem
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Dust::MenuItem
- Defined in:
- app/models/dust/menu_item.rb
Constant Summary collapse
- REGEX =
'^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$'
Class Method Summary collapse
Instance Method Summary collapse
- #children_urls ⇒ Object
- #destroy_linkable ⇒ Object
- #edit_linkable ⇒ Object
- #html_options?(uri) ⇒ Boolean
- #is_active?(uri) ⇒ Boolean
Class Method Details
.manage(search) ⇒ Object
17 18 19 |
# File 'app/models/dust/menu_item.rb', line 17 def self.manage(search) roots.search(search).order("title") end |
.menu ⇒ Object
29 30 31 32 |
# File 'app/models/dust/menu_item.rb', line 29 def self. list = self.roots list.where("active = ?", true) end |
.page(search, page) ⇒ Object
13 14 15 |
# File 'app/models/dust/menu_item.rb', line 13 def self.page(search, page) search(search).order("title").paginate(:per_page => 12, :page => page) end |
.search(search) ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/models/dust/menu_item.rb', line 21 def self.search(search) if search where("title LIKE ?", "%#{search}%") else scoped end end |
Instance Method Details
#children_urls ⇒ Object
42 43 44 |
# File 'app/models/dust/menu_item.rb', line 42 def children_urls self.descendants.map{ |item| item.url } end |
#destroy_linkable ⇒ Object
38 39 40 |
# File 'app/models/dust/menu_item.rb', line 38 def destroy_linkable "/#{root.linkable_type.downcase.pluralize}/#{root.linkable_id}" end |
#edit_linkable ⇒ Object
34 35 36 |
# File 'app/models/dust/menu_item.rb', line 34 def edit_linkable "/#{root.linkable_type.downcase.pluralize}/#{root.linkable_id}/edit" end |
#html_options?(uri) ⇒ Boolean
48 49 50 51 52 53 54 55 56 |
# File 'app/models/dust/menu_item.rb', line 48 def (uri) mash = Hashie::Mash.new mash.class = "last" if self == self.self_and_siblings.all(:conditions => ['active = ?', true]).last mash.target = "_blank" if url.match(REGEX) mash.class = "active" if self.is_active? uri mash.class = "active last" if (self.is_active? uri) and self == self.self_and_siblings.last mash end |
#is_active?(uri) ⇒ Boolean
58 59 60 |
# File 'app/models/dust/menu_item.rb', line 58 def is_active?(uri) true if uri == url or children_urls.include?(uri) or (uri == "/" and self.url == "/welcome") end |