ekampp / string-urlize

Converts string to friendly url

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Converts string to friendly url


Languages

Language:Ruby 59.0%Language:Gherkin 41.0%