Class: NoCms::Menus::MenuItem
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- NoCms::Menus::MenuItem
- Extended by:
- Enumerize
- Includes:
- Concerns::TranslationScopes
- Defined in:
- app/models/no_cms/menus/menu_item.rb
Instance Method Summary collapse
- #active_for?(options = {}) ⇒ Boolean
- #active_for_action?(action) ⇒ Boolean
- #active_for_external_url?(external_url) ⇒ Boolean
- #active_for_object?(object) ⇒ Boolean
- #copy_parent_menu ⇒ Object
- #draft ⇒ Object
- #draft? ⇒ Boolean
- #menu_kind ⇒ Object
- #position ⇒ Object
- #route_set ⇒ Object
- #set_leaf_with_draft ⇒ Object
- #url_for ⇒ Object
Instance Method Details
#active_for?(options = {}) ⇒ Boolean
49 50 51 52 53 54 55 56 57 |
# File 'app/models/no_cms/menus/menu_item.rb', line 49 def active_for?( = {}) return active_for_object?([:object]) unless [:object].nil? return active_for_action?([:action]) unless [:action].nil? return active_for_external_url?([:url]) unless [:url].nil? false end |
#active_for_action?(action) ⇒ Boolean
63 64 65 |
# File 'app/models/no_cms/menus/menu_item.rb', line 63 def active_for_action? action !action.nil? && ( == action) end |
#active_for_external_url?(external_url) ⇒ Boolean
67 68 69 |
# File 'app/models/no_cms/menus/menu_item.rb', line 67 def active_for_external_url? external_url !external_url.nil? && (self.external_url == external_url) end |
#active_for_object?(object) ⇒ Boolean
59 60 61 |
# File 'app/models/no_cms/menus/menu_item.rb', line 59 def active_for_object? object !object.nil? && ( == object) end |
#copy_parent_menu ⇒ Object
97 98 99 |
# File 'app/models/no_cms/menus/menu_item.rb', line 97 def self. = parent. unless parent.nil? end |
#draft ⇒ Object
111 112 113 |
# File 'app/models/no_cms/menus/menu_item.rb', line 111 def draft [:hidden] ? true : translation.draft end |
#draft? ⇒ Boolean
115 116 117 |
# File 'app/models/no_cms/menus/menu_item.rb', line 115 def draft? draft end |
#menu_kind ⇒ Object
93 94 95 |
# File 'app/models/no_cms/menus/menu_item.rb', line 93 def NoCms::Menus.[self.kind] end |
#position ⇒ Object
89 90 91 |
# File 'app/models/no_cms/menus/menu_item.rb', line 89 def position self[:position] || 0 end |
#route_set ⇒ Object
85 86 87 |
# File 'app/models/no_cms/menus/menu_item.rb', line 85 def route_set [:route_set] end |
#set_leaf_with_draft ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'app/models/no_cms/menus/menu_item.rb', line 101 def set_leaf_with_draft translations.each do |translation| I18n.with_locale(translation.locale) do previous_leaf_flag = translation.leaf_with_draft translation.update_column :leaf_with_draft, !draft && (leaf? || !descendants.no_drafts.exists?) self.parent.set_leaf_with_draft unless root? || (previous_leaf_flag == self.leaf_with_draft) end end end |
#url_for ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/models/no_cms/menus/menu_item.rb', line 71 def url_for case when ![:object_class].nil? .respond_to?(:path) ? .path : when ![:action].nil? controller, action = .split('#') # When we are inside an engine we need to prepend '/' to the controller, or else it would search the controller in the current engine locale = NoCms::Menus.localize_urls ? {locale: I18n.locale.to_s} : {} { controller: "/#{controller}", action: action }.merge locale else external_url end end |