Project

sexy_slug

0.0
No release in over 3 years
Low commit activity in last 3 years
Build sexy slugs for your URL paths. A lightweight, opinionated alternative to StringEx/ActAsUrl.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 0.1
~> 12.0
~> 3.0

Runtime

 Project Readme

Gem Version Build Status Coverage

SexySlug

This is a Ruby gem that builds slugs from Strings.

It is similar to StringEx' String#to_url, but more lightweight.

These are the main things that SexySlug does differently:

  • depends on activesupport
  • leaves core classes untouched
  • makes a few more transformations (see specs)
  • does not transliterate non-latin scripts (why?)
  • provides no ActiveRecord mixin
  • is less customizable
  • is about five times faster (see benchmark)

Installation

gem install sexy_slug or add it to your Gemfile.

Usage

SexySlug.from('Hi there!') # => 'hi-there'
SexySlug.from('Mambo #5') # => 'mambo-number-five'
I18n.with_locale(:de) { SexySlug.from('Mambo #5') } # => 'mambo-nummer-fuenf'

Customization

Simply change the contents of the SexySlug::PROCESSORS Array.

SexySlug::PROCESSORS.delete(SexySlug::UsuallyTransliterableChar)
SexySlug::PROCESSORS.unshift(MyCustomProcessor)

Why no universal transliterations?

Sluggification is always a fuzzy business, but transliteration in particular is almost guaranteed to produce incorrect results.

In many languages, codepoints don't map one-to-one to pronunciations, so their correct transliteration is context-dependent. Some relevant issues are e.g. allophones, crasis, digraphs, sandhi, and shared scripts.

Despite some restraint, sexy_slug isn't completely "i18n-proof", e.g.:

  • it might mistranslate money amounts, as the dollar sign is also used for non-dollar currencies
  • it always transliterates umlauts, which isn't appropriate for languages such as Turkish

See customization on how to avoid this if needed.

Similar/related projects

Contributing

Feel free to send suggestions, point out issues, or submit pull requests.