Class: Refinery::Page::FriendlyIdPath

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

Class Method Summary collapse

Class Method Details

.normalize_friendly_id(slug_string) ⇒ Object



357
358
359
360
361
362
363
364
365
# File 'pages/app/models/refinery/page.rb', line 357

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



347
348
349
350
351
352
353
354
355
# File 'pages/app/models/refinery/page.rb', line 347

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



367
368
369
370
371
372
373
# File 'pages/app/models/refinery/page.rb', line 367

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