Class: Gluttonberg::PageLocalization

Inherits:
ActiveRecord::Base
  • Object
show all
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

Instance Method Summary collapse

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_savingObject

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_pathObject

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_recachingObject

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

#contentsObject

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_contentObject



51
52
53
# File 'app/models/gluttonberg/page_localization.rb', line 51

def first_content
  contents.first
end

#localized_contentsObject

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_codeObject



93
94
95
# File 'app/models/gluttonberg/page_localization.rb', line 93

def name_and_code
  "#{name} (#{locale.name})"
end

#non_localized_contentsObject

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