Sha256: 7416f57eb9d1f6c6fe37e4d1b3de48f7d93294ef2d070372280c48f9a1d36ade

Contents?: true

Size: 785 Bytes

Versions: 27

Compression:

Stored size: 785 Bytes

Contents

module PandaCms
  class Slug
    #
    # Generates a slug from a provided string
    #
    # @param string [String] The provided string to turn into a slug
    # @return string Generated slug
    # @see text_field_update_controller.js should also implement this logic
    def self.generate(string)
      # Trim whitespace and downcase the string
      string = string.to_s.strip.downcase
      # Replace & with "and"
      string = string.gsub("&", "and")
      # Remove special characters
      string = string.gsub(/[\!\@\£\$\%\^\&\*\(\)\+\=\{\}\[\]\:\;\"\'\|\\\`\<\>\?\,\.\/]+/, "")
      # Replace any whitespace character with -
      string = string.gsub(/[^\w\s-]/, "-")
      # Replace multiple occurences of _ and - with -
      string.gsub(/[\s_-]+/, "-")
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
panda_cms-0.5.10 app/lib/panda_cms/slug.rb
panda_cms-0.5.9 app/lib/panda_cms/slug.rb
panda_cms-0.5.8 app/lib/panda_cms/slug.rb
panda_cms-0.5.7 app/lib/panda_cms/slug.rb
panda_cms-0.5.6 app/lib/panda_cms/slug.rb
panda_cms-0.5.5 app/lib/panda_cms/slug.rb
panda_cms-0.5.4 app/lib/panda_cms/slug.rb
panda_cms-0.5.3 app/lib/panda_cms/slug.rb
panda_cms-0.5.2 app/lib/panda_cms/slug.rb
panda_cms-0.5.1 app/lib/panda_cms/slug.rb
panda_cms-0.5.0 app/lib/panda_cms/slug.rb
panda_cms-0.3.15 app/lib/panda_cms/slug.rb
panda_cms-0.3.14 app/lib/panda_cms/slug.rb
panda_cms-0.3.13 app/lib/panda_cms/slug.rb
panda_cms-0.3.12 app/lib/panda_cms/slug.rb
panda_cms-0.3.11 app/lib/panda_cms/slug.rb
panda_cms-0.3.10 app/lib/panda_cms/slug.rb
panda_cms-0.3.9 app/lib/panda_cms/slug.rb
panda_cms-0.3.8 app/lib/panda_cms/slug.rb
panda_cms-0.3.7 app/lib/panda_cms/slug.rb