Class: Refinery::Page::FriendlyIdPath
- Inherits:
-
Object
- Object
- Refinery::Page::FriendlyIdPath
- Defined in:
- 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
355 356 357 358 359 360 361 362 363 |
# File 'app/models/refinery/page.rb', line 355 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
345 346 347 348 349 350 351 352 353 |
# File 'app/models/refinery/page.rb', line 345 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
365 366 367 368 369 370 371 |
# File 'app/models/refinery/page.rb', line 365 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 |