Sha256: e8fab04676144fb6c9de50231294aa79e44751459e51b40726e9b0f99d642d13

Contents?: true

Size: 499 Bytes

Versions: 10

Compression:

Stored size: 499 Bytes

Contents

# frozen_string_literal: true

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

    def humanized_param(slug)
      return id.to_s unless slug&.present?

      "#{id}-" + transliterate(slug)
                 .downcase
                 .gsub(/[\[{]/, "(")
                 .gsub(/}\]/, ")")
                 .gsub(/[^[[:alnum:]]()-]+/, "-")
                 .gsub(/-{2,}/, "-")
                 .gsub(/(^-|-$)/, "")
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pages_core-3.10.2 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.10.1 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.9.2 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.9.1 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.9.0 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.8.3 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.8.2 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.8.1 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.8.0 app/models/concerns/pages_core/humanizable_param.rb
pages_core-3.7.0 app/models/concerns/pages_core/humanizable_param.rb