Sha256: 938b092783f3534aa44e8bcb1ce9775ffaef9e5eb33e3fa2908eee69304abfd1

Contents?: true

Size: 660 Bytes

Versions: 19

Compression:

Stored size: 660 Bytes

Contents

# frozen_string_literal: true

module PagesCore
  module HumanizableParam
    include ActiveSupport::Inflector
    extend ActiveSupport::Concern

    def humanized_param(slug)
      safe_slug = safe_humanized_param(slug)
      return id.to_s if safe_slug.blank?

      "#{id}-#{safe_slug}"
    end

    private

    def safe_humanized_param(str)
      transliterate(str.to_s).downcase
                             .gsub(/[\[{]/, "(")
                             .gsub(/}\]/, ")")
                             .gsub(/[^[[:alnum:]]()-]+/, "-")
                             .gsub(/-{2,}/, "-")
                             .gsub(/(^-|-$)/, "")
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
pages_core-3.15.5 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.15.4 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.15.3 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.15.2 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.15.1 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.14.0 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.13.0 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.12.7 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.12.6 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.12.5 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.12.4 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.12.3 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.12.2 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.12.1 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.12.0 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.11.3 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.11.2 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.11.1 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.11.0 app/models/concerns/pages_core/humanizable_param.rb