Class: Gluttonberg::PageLocalization

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/gluttonberg/page_localization.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) content_needs_saving

Returns the value of attribute content_needs_saving



17
18
19
# File 'app/models/gluttonberg/page_localization.rb', line 17

def content_needs_saving
  @content_needs_saving
end

- (Object) paths_need_recaching

Returns the value of attribute paths_need_recaching



17
18
19
# File 'app/models/gluttonberg/page_localization.rb', line 17

def paths_need_recaching
  @paths_need_recaching
end

Instance Method Details

- (Object) contents

Returns an array of content localizations



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/gluttonberg/page_localization.rb', line 26

def contents
  @contents ||= begin
    # First collect the localized content
    contents_data = Gluttonberg::Content.localization_associations.inject([]) do |memo, assoc|
      memo += send(assoc).all
    end
    # Then grab the content that belongs directly to the page
    Gluttonberg::Content.non_localized_associations.inject(contents_data) do |memo, assoc|
      contents_data += page.send(assoc).all
    end
    contents_data
  end   
  @contents 
end

- (Object) contents=(params)

Updates each localized content record and checks their validity



42
43
44
45
46
47
48
# File 'app/models/gluttonberg/page_localization.rb', line 42

def contents=(params)
  self.content_needs_saving = true
  contents.each do |content|
    update = params[content.association_name][content.id.to_s]
    content.attributes = update if update
  end
end

- (Object) name_and_code



54
55
56
# File 'app/models/gluttonberg/page_localization.rb', line 54

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

- (Boolean) paths_need_recaching?

Returns:

  • (Boolean)


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

def paths_need_recaching?
  @paths_need_recaching
end

- (Object) public_path



58
59
60
61
62
63
64
# File 'app/models/gluttonberg/page_localization.rb', line 58

def public_path
    if Gluttonberg.localized?
      "/#{self.locale.slug}/#{self.path}"
    else
      "/#{self.path}"
    end
end

- (Object) regenerate_path

Forces the localization to regenerate it's full path. It will firstly look to see if there is a parent page that it need to derive the path prefix from. Otherwise it will just use the slug, with a fall-back to it's page's default.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/models/gluttonberg/page_localization.rb', line 71

def regenerate_path
  page.reload #forcing that do not take cached page object
  slug = nil if slug.blank?
  if page.parent_id && page.parent.home != true
    localization = page.parent.localizations.find(:first,
      :conditions => {
        :locale_id  => locale_id 
      }
    )
    new_path = "#{localization.path}/#{slug || page.slug}"
  else
    new_path = "#{slug || page.slug}"
  end
  write_attribute(:path, new_path)
end

- (Object) regenerate_path!

Regenerates and saves the path to this localization.



88
89
90
91
# File 'app/models/gluttonberg/page_localization.rb', line 88

def regenerate_path!
  regenerate_path
  save
end

- (Object) slug=(new_slug)

Write an explicit setter for the slug so we can check it???s not a blank value. This stops it being overwritten with an empty string.



21
22
23
# File 'app/models/gluttonberg/page_localization.rb', line 21

def slug=(new_slug)
  write_attribute(:slug, new_slug) unless new_slug.blank?
end