The Enkoder Plugin for Ruby on Rails

I am happy to announce that the Enkoder, a tool that hides your email address from email address harvesters, is now available as a Ruby on Rails plugin!

That’s right, you can now include the full functionality of the Enkoder (including on-the-fly enkoding) right in your own Rails applications.

What is the Enkoder?

The Enkoder helps protect email addresses by converting them into encrypted JavaScript code, hiding them from email-harvesting robots while revealing them to real people.

The Enkoder plugin provides an extension to the Rails TextHelper module that can be used to protect email addresses (or other information) by obfuscating them using JavaScript code.

Installation

You can download the Enkoder plugin as a zip archive. Then, just unzip the archive and drop the enkoder folder it creates into your project’s vendor/plugins folder.

Usage

There are two methods:

enkode( html )

This method accepts a block of html (or any text) and returns an enkoded JavaScript.

The second method is:

enkode_mail( email, link_text, title_text, subject )

This method takes an email address, the text to show to the viewer, optional title text (what’s seen when somebody hovers over the link), and optional subject for the email, and returns an enkoded email address link.

Examples:

To enkode a single email address, you could just do this:

<%= enkode_mail('user@domain.com','click here') %>

And the following link would be returned (enkoded as JavaScript):

<a href="mailto:"user@domain.com" title="">click here</a>

Of course we can also enkode many email addresses on the fly:

<% @users.each do |user| %>
  <p><%= enkode_mail(@user.email,@user.name) %></p>
<% end %>

To enkode a snippet of XHTML, we can do:

<%=
  enkode(
    "<p>This block will be hidden from spambots.</p>" 
  )
%>

We could have anything we wanted in that block, XHTML, links, email addresses, etc.

For more information, usage details, and additional examples, please visit the Hivelogic Enkoder page.

Special Thanks

I’d like to share my gratitude to The Guru, wherever he dwells, for his assistance with the latest Enkoder algorithm. Without his help, we’d still be in the stone-ages, using easily-decoded HTML entity conversions or performing voodoo rituals to try and ward-off spam.

More articles in the Archive →