Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tenderlove/rails_autolink
The auto_link function from Rails
https://github.com/tenderlove/rails_autolink
Last synced: about 2 months ago
JSON representation
The auto_link function from Rails
- Host: GitHub
- URL: https://github.com/tenderlove/rails_autolink
- Owner: tenderlove
- License: mit
- Created: 2011-05-02T22:37:12.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2023-10-18T21:33:02.000Z (11 months ago)
- Last Synced: 2024-05-19T11:45:46.191Z (4 months ago)
- Language: Ruby
- Homepage:
- Size: 79.1 KB
- Stars: 582
- Watchers: 21
- Forks: 92
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# rails_autolink
- http://github.com/tenderlove/rails_autolink
## Description
This is an extraction of the `auto_link` method from rails. The `auto_link`
method was removed from Rails in version Rails 3.1. This gem is meant to
bridge the gap for people migrating.## Features
By default auto_link returns sanitized html_safe strings. This behaviour can
be overridden by setting the `:sanitize` option to false (thus making it
insecure if you don't have the content under control).## Install
Add this line to your application's Gemfile:
```ruby
gem 'rails_autolink'
```And then execute:
```bash
$ bundle install
```## Synopsis
### Basic Usage
```ruby
require 'rails_autolink'auto_link("Go to http://www.rubyonrails.org and say hello to [email protected]")
# => "Go to http://www.rubyonrails.org and
# say hello to [email protected]"
```### Convert Only URLs to Links
```ruby
auto_link("Visit http://www.loudthinking.com/ or e-mail [email protected]", :link => :urls)
# => "Visit http://www.loudthinking.com/
# or e-mail [email protected]"
```### Convert Only Email Addresses to Links
```ruby
auto_link("Visit http://www.loudthinking.com/ or e-mail [email protected]", :link => :email_addresses)
# => "Visit http://www.loudthinking.com/ or e-mail [email protected]"
```### Generate Links Without Sanitizing HTML Tags
```ruby
## By default, HTML tags are sanitized to protect from malicious code
auto_link("Go to http://www.rubyonrails.org Malicious code!")
# => "Go to http://www.rubyonrails.org "## Use the :sanitize => false option to prevent sanitization
auto_link("Go to http://www.rubyonrails.org alert('Script!')", :sanitize => false)
# => "Go to http://www.rubyonrails.org alert('Script!')"
```### Customize Links and Shorten Text
```ruby
post_body = "Welcome to my new blog at http://www.myblog.com/. Please e-mail me at [email protected]."
auto_link(post_body, :html => { :target => '_blank' }) do |text|
truncate(text, :length => 15)
end
# => "Welcome to my new blog at http://www.m....
```## Requirements
- `rails` > `3.1`