From dea8eed50b3e28789bb40034d754603ce6a7f4cc Mon Sep 17 00:00:00 2001 From: Wade West Date: Tue, 7 Feb 2012 10:25:19 -0600 Subject: [PATCH 1/3] Bundled email address encoding into Ruby and Javascript functions. --- app/helpers/application_helper.rb | 8 ++++++++ app/views/feedback_messages/new.html.erb | 4 +--- app/views/info/about.html.erb | 4 +--- public/javascripts/application.js | 13 +++++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4b7cd3f..203bad4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -57,4 +57,12 @@ def field(f, attribute, options = {}) type = options.delete(:type) || :text_field content_tag(:div, (f.label(attribute, label_name) + f.send(type, attribute, options)), :class => "field") end + + def encrypt_email(email_address) + email_address.chars.map{|c|c.ord} + end + + def encrypt_mailto_link(email_address) + "".html_safe + end end diff --git a/app/views/feedback_messages/new.html.erb b/app/views/feedback_messages/new.html.erb index ba9a300..c857af8 100644 --- a/app/views/feedback_messages/new.html.erb +++ b/app/views/feedback_messages/new.html.erb @@ -6,9 +6,7 @@ <%= form_for @feedback_message do |f| %> <%= f.error_messages %>
-

You can also contact @railscasts on Twitter, or send an email to .

+

You can also contact @railscasts on Twitter, or send an email to <%= encrypt_mailto_linK("feedback@addoncasts.com")%>.

<%= label_tag :email %> diff --git a/app/views/info/about.html.erb b/app/views/info/about.html.erb index 38e0b66..78d4ff8 100644 --- a/app/views/info/about.html.erb +++ b/app/views/info/about.html.erb @@ -16,9 +16,7 @@

Download Textmate Theme

Contact

-

If you have any comments, suggestions, questions, etc. I'd love to hear them! Please use the <%= link_to "Feedback Page", feedback_path %> or send an email to .

+

If you have any comments, suggestions, questions, etc. I'd love to hear them! Please use the <%= link_to "Feedback Page", feedback_path %> or send an email to <%= encrypt_mailto_link("feedback@railscasts.com") %>.

Moderators

Thank you to all moderators who help keep the site clean and up to date:

diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 5e6bb89..1f5948a 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -1,3 +1,16 @@ +function decrypted_email(riddle) { + var email_address = ''; + for ( var i = 0; i < riddle.length; i++ ) { + email_address += String.fromCharCode(riddle[i]) + } + return email_address +} + +function decrypted_mailto_link(riddle) { + var email_address = decrypted_email(riddle) + document.write(""+email_address+"") +} + $(function() { if ($("#episode").length > 0) { sublimevideo.ready(function() { From 7ea27efe3806d626be39454e67ddad0e2b87933d Mon Sep 17 00:00:00 2001 From: Wade West Date: Tue, 7 Feb 2012 10:26:36 -0600 Subject: [PATCH 2/3] Update to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 7d6158b..ac8193e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ config/*.sphinx.conf config/initializers/development_mail.rb db/sphinx public/assets +.DS_Store +._* From 38d9c4d0f06e953def42a13da795bc8f00a599ad Mon Sep 17 00:00:00 2001 From: Wade West Date: Tue, 7 Feb 2012 10:40:43 -0600 Subject: [PATCH 3/3] Added test for ApplicationHelper#encrypt_email --- spec/helpers/application_helper_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 spec/helpers/application_helper_spec.rb diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb new file mode 100644 index 0000000..10c2734 --- /dev/null +++ b/spec/helpers/application_helper_spec.rb @@ -0,0 +1,7 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe ApplicationHelper do + it "encrypts an email address" do + helper.encrypt_email('foo@bar.com').should eq([102, 111, 111, 64, 98, 97, 114, 46, 99, 111, 109]) + end +end