Class: Refinery::Page::FriendlyIdPath

Inherits:
Object
  • Object
show all
Defined in:
app/models/refinery/page.rb

Class Method Summary collapse

Class Method Details

.normalize_friendly_id(slug_string) ⇒ Object



351
352
353
354
355
356
357
358
359
# File 'app/models/refinery/page.rb', line 351

def self.normalize_friendly_id(slug_string)
  # If we are scoping by parent, no slashes are allowed. Otherwise, slug is
  # potentially a custom slug that contains a custom route to the page.
  if !Pages.scope_slug_by_parent && slug_string.include?('/')
    self.normalize_friendly_id_path(slug_string)
  else
    self.protected_slug_string(slug_string)
  end
end

.normalize_friendly_id_path(slug_string) ⇒ Object



341
342
343
344
345
346
347
348
349
# File 'app/models/refinery/page.rb', line 341

def self.normalize_friendly_id_path(slug_string)
  # Remove leading and trailing slashes, but allow internal
  slug_string
    .sub(%r{^/*}, '')
    .sub(%r{/*$}, '')
    .split('/')
    .select(&:present?)
    .map { |slug| self.normalize_friendly_id(slug) }.join('/')
end

.protected_slug_string(slug_string) ⇒ Object



361
362
363
364
365
366
367
# File 'app/models/refinery/page.rb', line 361

def self.protected_slug_string(slug_string)
  sluggified = slug_string.to_slug.normalize!
  if Pages.marketable_urls && Refinery::Pages.friendly_id_reserved_words.include?(sluggified)
    sluggified << "-page"
  end
  sluggified
end