app/models/ecm/cms/navigation_item.rb in ecm_cms2-1.1.1 vs app/models/ecm/cms/navigation_item.rb in ecm_cms2-2.0.2
- old
+ new
@@ -1,49 +1,51 @@
+require_dependency 'model/ecm/cms/navigation_item/properties_concern'
+
module Ecm::Cms
class NavigationItem < ActiveRecord::Base
- include Properties
+ include Model::Ecm::Cms::NavigationItem::PropertiesConcern
# associations
belongs_to :ecm_cms_navigation,
- :class_name => 'Ecm::Cms::Navigation',
- :foreign_key => 'ecm_cms_navigation_id'
+ class_name: 'Ecm::Cms::Navigation',
+ foreign_key: 'ecm_cms_navigation_id'
belongs_to :ecm_cms_page,
- :class_name => 'Ecm::Cms::Page',
- :foreign_key => 'ecm_cms_page_id'
+ class_name: 'Ecm::Cms::Page',
+ foreign_key: 'ecm_cms_page_id'
# awesome nested set
- acts_as_nested_set :dependent => :destroy, :counter_cache => :children_count, :scope => :ecm_cms_navigation_id
+ acts_as_nested_set dependent: :destroy, counter_cache: :children_count, scope: :ecm_cms_navigation_id
# callbacks
- before_validation :update_navigation_from_parent, :if => Proc.new { |ni| ni.child? }
- before_validation :update_url_form_page, :if => Proc.new { |ni| ni.ecm_cms_page.present? && ni.url.blank? }
+ before_validation :update_navigation_from_parent, if: proc { |ni| ni.child? }
+ before_validation :update_url_form_page, if: proc { |ni| ni.ecm_cms_page.present? && ni.url.blank? }
after_save :update_children_navigations!
# default_scope
default_scope { order(:ecm_cms_navigation_id, :lft) }
# validations
- validates :key, :presence => true
- validates :name, :presence => true
- validates :url, :presence => true
- validates :ecm_cms_navigation, :presence => true, :if => :root?
+ validates :key, presence: true
+ validates :name, presence: true
+ validates :url, presence: true
+ validates :ecm_cms_navigation, presence: true, if: :root?
def params_for_new_page
return {} if self.new_record?
- match = self.url.scan(/(#{I18n.available_locales.join('|')})$/)
- return { :locale => match[0][0], :pathname => '/', :basename => 'home', :title => self.name, :ecm_cms_navigation_item_ids => [ self.to_param ] } if match.size > 0
- match = self.url.scan(/(#{I18n.available_locales.join('|')})(.*)\/(.*)/)
+ match = url.scan(/(#{I18n.available_locales.join('|')})$/)
+ return { locale: match[0][0], pathname: '/', basename: 'home', title: name, ecm_cms_navigation_item_ids: [to_param] } if match.size > 0
+ match = url.scan(/(#{I18n.available_locales.join('|')})(.*)\/(.*)/)
return {} unless match.first.respond_to?(:size) # && match.first.size != 3
params = match.first
return {} if params.size != 3
params[1] << '/' unless params[1].end_with?('/')
- return { :locale => params[0], :pathname => params[1], :basename => params[2], :title => self.name, :ecm_cms_navigation_item_ids => [ self.to_param ] }
+ { locale: params[0], pathname: params[1], basename: params[2], title: name, ecm_cms_navigation_item_ids: [to_param] }
end
def to_label
if depth > 0
- "#{' ' * depth} ▶ #{name}".html_safe
+ "#{' ' * depth} ▶ #{name}".html_safe
else
name
end
end
@@ -55,11 +57,11 @@
update_navigation_from_parent
save!
end
def update_children_navigations!
- self.descendants.map(&:"update_navigation_from_parent!")
+ descendants.map(&:"update_navigation_from_parent!")
end
def update_url_form_page!
# self.url = build_url_from_page(ecm_cms_page.locale, ecm_cms_page.pathname, ecm_cms_page.basename, ecm_cms_page.home_page?)
update_url_form_page
@@ -75,14 +77,13 @@
"/#{locale}#{pathname}#{basename}"
end
end
def update_navigation_from_parent
- self.ecm_cms_navigation = self.parent.ecm_cms_navigation
+ self.ecm_cms_navigation = parent.ecm_cms_navigation
end
def update_url_form_page
self.url = build_url_from_page(ecm_cms_page.locale, ecm_cms_page.pathname, ecm_cms_page.basename, ecm_cms_page.home_page?)
end
end
end
-