Sha256: 70e224056f4ca6117ba0d211b5f1cf1636b52b9d57bf6168712cf2af496150e6

Contents?: true

Size: 772 Bytes

Versions: 4

Compression:

Stored size: 772 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 slug_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

4 entries across 4 versions & 1 rubygems

Version Path
panda_cms-0.6.3 app/lib/panda_cms/slug.rb
panda_cms-0.6.2 app/lib/panda_cms/slug.rb
panda_cms-0.6.1 app/lib/panda_cms/slug.rb
panda_cms-0.6.0 app/lib/panda_cms/slug.rb