Class: Refinery::Page::FriendlyIdPath
- Inherits:
-
Object
- Object
- Refinery::Page::FriendlyIdPath
- Defined in:
- pages/app/models/refinery/page.rb
Class Method Summary collapse
- .normalize_friendly_id(slug_string) ⇒ Object
- .normalize_friendly_id_path(slug_string) ⇒ Object
- .protected_slug_string(slug_string) ⇒ Object
Class Method Details
.normalize_friendly_id(slug_string) ⇒ Object
343 344 345 346 347 348 349 350 351 |
# File 'pages/app/models/refinery/page.rb', line 343 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
333 334 335 336 337 338 339 340 341 |
# File 'pages/app/models/refinery/page.rb', line 333 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
353 354 355 356 357 358 359 |
# File 'pages/app/models/refinery/page.rb', line 353 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 |