Converts string to friendly url
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
features
lib
.gitignore
.travis.yml
Gemfile
README.markdown
Rakefile
string-urlize.gemspec

README.markdown

String Urlize Build Status Dependency Status

Extends ruby String class with urlize method which converts string to friendly url. It removes all characters that couldn't be used in url and replaces spaces/underscores with dashes. In addition it transliterate string using I18n library.

Installation

gem install string-urlize

In Rails 3, add this to your Gemfile and run the bundle command.

gem "string-urlize"

Usage

'my cool string'.urlize # => my-cool-string
:foo_symbol.to_s.urlize # => foo-symbol

Examples:

stringurl
Lorem ipsum dolor sit ametlorem-ipsum-dolor-sit-amet
CamelCasecamel-case
a lot of spacesa-lot-of-spaces
special !@#$%^&*()<>,./?\ \| symbolsspecial-symbols
underscored_stringunderscored-string
string with-dashesstring-with-dashes
ÈÉÊËeeee
òóôõöøoooooo

Transliteration

Transliteration powered by I18n library and enabled by default. So you could provide locale to the urlize method:

'Jürgen'.urlize                 # => "jurgen"
'Jürgen'.urlize(:locale => :de) # => "juergen"

or disable transliteration at all:

'Jürgen'.urlize(:transliterate => false) # => 'jürgen' in ruby 1.9 and 'jrden' in ruby 1.8.7