Slugger v0.3.0 Slugger View Source

Calcualtes a ‘slug’ for a given string. Such a slug can be used for reading URLs or Search Engine Optimization.

Link to this section Summary

Functions

Return a string in form of a slug for a given string

Return a string in form of a lowercase slug for a given string

Truncate a slug at a given maximum length

Link to this section Functions

Link to this function slugify(text, separator \\ 45) View Source
slugify(text :: any, separator :: char) :: String.t

Return a string in form of a slug for a given string.

Examples

iex> Slugger.slugify(" Hi # there ")
"Hi-there"

iex> Slugger.slugify("Über den Wölkchen draußen im Tore")
"Ueber-den-Woelkchen-draussen-im-Tore"

iex> Slugger.slugify("Wikipedia Style", ?_)
"Wikipedia_Style"

iex> Slugger.slugify("_Trimming_and___Removing_inside___")
"Trimming-and-Removing-inside"
Link to this function slugify_downcase(text, separator \\ 45) View Source
slugify_downcase(text :: any, separator :: char) :: String.t

Return a string in form of a lowercase slug for a given string.

Examples

iex> Slugger.slugify_downcase(" Hi # there ")
"hi-there"

iex> Slugger.slugify_downcase("Über den Wölkchen draußen im Tore")
"ueber-den-woelkchen-draussen-im-tore"

iex> Slugger.slugify_downcase("Wikipedia Style", ?_)
"wikipedia_style"

iex> Slugger.slugify_downcase("_trimming_and___removing_inside___")
"trimming-and-removing-inside"
Link to this function truncate_slug(slug, max_length, options \\ []) View Source

Truncate a slug at a given maximum length.

Tries to cut off before the last separator instead of breaking inside of a word, unless you set the hard option to true.

Examples

iex> Slugger.truncate_slug(“hello-world”, 7) “hello”

iex> Slugger.truncate_slug(“hello-world”, 7, [hard: true]) “hello-w”