Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Middleman email obfuscate helper
# ====================================
# Obfuscate email
# Adapted from:
# Usage:
# = mailto('', 'Get in touch', 'btn btn--nav')
# ====================================
MAIL_TO = 'mailto:'
AT = '@'
DOT = '.'
def mailto email="", string="contact me", classes
comp = email.split("@")
# process string, if it is an email address
if string.include?("@") then
string.gsub!("@", AT + "‌").gsub!(".", DOT)
return "<a class=\"#{classes}\" href='javascript:void(0)' rel='nofollow' onclick='str1=\"#{comp[0]}\";str2=\"#{comp[1]}\";this.href=\"#{MAIL_TO}\" + str1 + \"@\" + str2'>#{string}</a>"
Copy link

Ross-Hunter commented May 9, 2017

Seems legit, but worked for me (for future generations who come here looking for this functionality).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment