Giter Site home page Giter Site logo

sexy_slug's Introduction

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.

sexy_slug's People

Contributors

flori avatar jaynetics avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

flori

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.