You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add slugger to your list of dependencies in mix.exs:
defdepsdo[{:slugger,"~> 0.3"},]end
Configuration
The following options can be set in your config.exs and will be used at next compile!
# Char used as separator between words.config:slugger,separator_char: ?-# Path to the file containing replacements.config:slugger,replacement_file: "lib/replacements.exs"
Library
Using the library is straightforward, check out a few examples:
iex(1)>Slugger.slugify" A b C ""A-b-C"iex(2)>Slugger.slugify_downcase" A b C ""a-b-c"iex(3)>Slugger.slugify"A cool title of a blog post""A-cool-title-of-a-blog-post"iex(4)>Slugger.slugify_downcase("Kluski Śląskie @ Jalapeño Bilingüe")"kluski-slaskie-at-jalapeno-bilinguee"iex(5)>Slugger.slugify"Wikipedia Style",?_"Wikipedia_Style"iex(6)>Slugger.truncate_slug"A-to-long-slug-that-should-be-truncated",16"A-to-long-slug"
Protocol
Next to the library, a protocol is provided to ease creating slugs for own data structures.
By default, the protocol will try to run Slugger.slugify(Kernel.to_string(your_data)), so if your_data implements String.Chars, the returned string will be slugified.
If you want to provide your own way to create a slug, check out the following example: