Project

bypass

0.01
No commit activity in last 3 years
No release in over 3 years
Mutate URLs and hyperlinks in HTML and plain text documents
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Bypass

Build Status Code Climate

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.

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:

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:

text = "Visit our website: <a href='http://www.getdrip.com'>Drip</a>"
filter = Bypass::HTMLFilter.new(text)

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

filter.content
#=> "Visit our website: <a href='http://www.getdrip.com?id=123'>Drip</a>"

To convert all non-hyperlinked URLs to hyperlinks:

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

filter.content
#=> "Lets auto link this: <a href='http://www.google.com'>http://www.google.com</a>"

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