Class: Gluttonberg::PageLocalization
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gluttonberg::PageLocalization
- Includes:
- Content::PageLocalizationSlug
- Defined in:
- app/models/gluttonberg/page_localization.rb
Overview
PageLocalization model stores meta information regarding localization of page.
Instance Attribute Summary collapse
-
#content_needs_saving ⇒ Object
Returns the value of attribute content_needs_saving.
-
#current_path ⇒ Object
Returns the value of attribute current_path.
-
#paths_need_recaching ⇒ Object
Returns the value of attribute paths_need_recaching.
Instance Method Summary collapse
-
#contents ⇒ Object
Returns an array of all contents (for localized contents its return content localizations).
-
#contents=(params) ⇒ Object
Updates each content record and checks their validity.
- #first_content ⇒ Object
-
#localized_contents ⇒ Object
Returns an array of content localizations.
- #name_and_code ⇒ Object
-
#non_localized_contents ⇒ Object
Returns an array of non localized contents.
Methods included from Content::PageLocalizationSlug
#find_potential_duplicates, #path_without_self_slug, #paths_need_recaching?, #public_path, #regenerate_path, #regenerate_path!, #slug=
Instance Attribute Details
#content_needs_saving ⇒ Object
Returns the value of attribute content_needs_saving.
33 34 35 |
# File 'app/models/gluttonberg/page_localization.rb', line 33 def content_needs_saving @content_needs_saving end |
#current_path ⇒ Object
Returns the value of attribute current_path.
15 16 17 |
# File 'app/models/gluttonberg/page_localization.rb', line 15 def current_path @current_path end |
#paths_need_recaching ⇒ Object
Returns the value of attribute paths_need_recaching.
33 34 35 |
# File 'app/models/gluttonberg/page_localization.rb', line 33 def paths_need_recaching @paths_need_recaching end |
Instance Method Details
#contents ⇒ Object
Returns an array of all contents (for localized contents its return content localizations)
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/gluttonberg/page_localization.rb', line 37 def contents @contents ||= begin # First collect the localized content contents_data = localized_contents contents_data = [] if contents_data.blank? # Then grab the content that belongs directly to the page contents_data << non_localized_contents unless contents_data.blank? contents_data = contents_data.flatten.sort{|a,b| a.section_position <=> b.section_position} end end @contents end |
#contents=(params) ⇒ Object
Updates each content record and checks their validity
82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/gluttonberg/page_localization.rb', line 82 def contents=(params) self.content_needs_saving = true contents.each do |content| content_page_publishing_info(content) content_association = params[content.association_name] content_association = params[content.association_name.to_s] if content_association.blank? update = content_association[content.id.to_s] content.attributes = update if update end end |
#first_content ⇒ Object
51 52 53 |
# File 'app/models/gluttonberg/page_localization.rb', line 51 def first_content contents.first end |
#localized_contents ⇒ Object
Returns an array of content localizations
56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/gluttonberg/page_localization.rb', line 56 def localized_contents @localized_contents ||= begin # First collect the localized content contents_data = Gluttonberg::Content.localization_associations.inject([]) do |memo, assoc| memo += send(assoc).all end contents_data = contents_data.delete_if {|a| a.section_position.blank? } contents_data = contents_data.sort{|a,b| a.section_position <=> b.section_position} end @localized_contents end |
#name_and_code ⇒ Object
93 94 95 |
# File 'app/models/gluttonberg/page_localization.rb', line 93 def name_and_code "#{name} (#{locale.name})" end |
#non_localized_contents ⇒ Object
Returns an array of non localized contents
69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/gluttonberg/page_localization.rb', line 69 def non_localized_contents @non_localized_contents ||= begin # grab the content that belongs directly to the page contents_data = Gluttonberg::Content.non_localized_associations.inject([]) do |memo, assoc| memo += page.send(assoc).all end contents_data = contents_data.delete_if {|a| a.section_position.blank? } contents_data = contents_data.sort{|a,b| a.section_position <=> b.section_position} end @non_localized_contents end |