Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/derrickreimer/bypass

Mutate URLs and hyperlinks in HTML and plain text documents with ease
https://github.com/derrickreimer/bypass

Last synced: about 2 months ago
JSON representation

Mutate URLs and hyperlinks in HTML and plain text documents with ease

Awesome Lists containing this project

README

        

# Bypass

[![Build Status](https://travis-ci.org/djreimer/bypass.png?branch=master)](https://travis-ci.org/djreimer/bypass)
[![Code Climate](https://codeclimate.com/github/djreimer/bypass.png)](https://codeclimate.com/github/djreimer/bypass)

Bypass is a Ruby gem that scans plain text or HTML documents for URLs and
hyperlinks and allows you to mutate or replace them with ease. This library
was originally designed for appending tracking data and shortening link
URLs in HTML and plain text emails.

Extracted from [Drip](http://www.getdrip.com/).

## Installation

Add this line to your application's Gemfile:

gem 'bypass'

And then execute:

$ bundle

Or install it yourself as:

$ gem install bypass

## Usage

There are URL filters available for both plain text and HTML documents.

### Plain Text

To replace all URLs in a plain text document:

```ruby
text = "Visit our website: http://www.getdrip.com"
filter = Bypass::TextFilter.new(text)

filter.replace do |url|
url.append_to_query_values(:id => 123)
url
end

filter.content
#=> "Visit our website: http://www.getdrip.com?id=123"
```

### HTML

To replace all `href` attributes in `a` tags in an HTML document:

```ruby
text = "Visit our website: Drip"
filter = Bypass::HTMLFilter.new(text)

filter.replace do |url|
url.append_to_query_values(:id => 123)
url
end

filter.content
#=> "Visit our website: Drip"
```

To convert all non-hyperlinked URLs to hyperlinks:

```ruby
text = "Lets auto link this: http://www.google.com"
filter = Bypass::HTMLFilter.new(text)
filter.auto_link

filter.content
#=> "Lets auto link this: http://www.google.com"
```

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request