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