Module: Gluttonberg::Content::PageLocalizationSlug

Extended by:
ActiveSupport::Concern
Included in:
PageLocalization
Defined in:
lib/gluttonberg/content/page_localization_slug.rb

Instance Method Summary collapse

Instance Method Details

#find_potential_duplicates(_path) ⇒ Object



63
64
65
66
# File 'lib/gluttonberg/content/page_localization_slug.rb', line 63

def find_potential_duplicates(_path)
  potential_duplicates = self.class.where([ "path = ? AND page_id != ?", _path, page.id]).all
  potential_duplicates = potential_duplicates.find_all{|l| l.page.parent_id == self.page.parent_id}
end

#path_without_self_slugObject



54
55
56
57
58
59
60
61
# File 'lib/gluttonberg/content/page_localization_slug.rb', line 54

def path_without_self_slug
  if page.parent_id && !page.parent.blank? && page.parent.home != true
    localization = page.parent.localizations.where(:locale_id  => locale_id).first
    "#{localization.path}/"
  else
    ""
  end
end

#paths_need_recaching?Boolean

slug=

Returns:

  • (Boolean)


21
22
23
# File 'lib/gluttonberg/content/page_localization_slug.rb', line 21

def paths_need_recaching?
  self.paths_need_recaching
end

#public_pathObject



25
26
27
28
29
30
31
# File 'lib/gluttonberg/content/page_localization_slug.rb', line 25

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

#regenerate_pathObject

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.



38
39
40
41
42
43
44
45
46
# File 'lib/gluttonberg/content/page_localization_slug.rb', line 38

def regenerate_path
  self.current_path = self.path
  page.reload #forcing that do not take cached page object
  slug = nil if slug.blank?
  new_path = prepare_new_path

  self.previous_path = self.current_path
  write_attribute(:path, new_path)
end

#regenerate_path!Object

Regenerates and saves the path to this localization.



49
50
51
52
# File 'lib/gluttonberg/content/page_localization_slug.rb', line 49

def regenerate_path!
  regenerate_path
  save
end

#slug=(new_slug) ⇒ Object

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.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gluttonberg/content/page_localization_slug.rb', line 9

def slug=(new_slug)
  unless new_slug.blank?
    write_attribute(:slug, new_slug.to_s.sluglize)
    page_temp_slug = self.page.slug
    self.page.slug = self.slug
    write_attribute(:slug, self.page.slug)
    unless self.locale.default
      self.page.slug = page_temp_slug
    end
  end
end