Skip to content

Refactored email encoding into server side and client side functions. #54

Open
wants to merge 3 commits into from
View
2 .gitignore
@@ -11,3 +11,5 @@ config/*.sphinx.conf
config/initializers/development_mail.rb
db/sphinx
public/assets
+.DS_Store
+._*
View
8 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)
+ "<script>decrypted_mailto_link([#{encrypt_email(email_address).join(',')}])</script>".html_safe
+ end
end
View
4 app/views/feedback_messages/new.html.erb
@@ -6,9 +6,7 @@
<%= form_for @feedback_message do |f| %>
<%= f.error_messages %>
<div class="info">
- <p>You can also contact <a href="http://twitter.com/railscasts">@railscasts</a> on Twitter, or send an email to <script type="text/javascript">document.write(
- "<n uers=\"znvygb:srrqonpx\100envyfpnfgf\056pbz\">srrqonpx\100envyfpnfgf\056pbz<\057n>".replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}));
- </script>.</p>
+ <p>You can also contact <a href="http://twitter.com/railscasts">@railscasts</a> on Twitter, or send an email to <%= encrypt_mailto_linK("feedback@addoncasts.com")%>.</p>
</div>
<div class="special_email_field">
<%= label_tag :email %>
View
4 app/views/info/about.html.erb
@@ -16,9 +16,7 @@
<p><a href="http://media.railscasts.com/resources/textmate_theme.zip">Download Textmate Theme</a></p>
<h2>Contact</h2>
- <p>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 <script type="text/javascript">document.write(
-"<n uers=\"znvygb:srrqonpx\100envyfpnfgf\056pbz\">srrqonpx\100envyfpnfgf\056pbz<\057n>".replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}));
-</script>.</p>
+ <p>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") %>.</p>
<h2>Moderators</h2>
<p>Thank you to all moderators who help keep the site clean and up to date:</p>
View
13 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("<a href=\"mailto:"+email_address+"\">"+email_address+"</a>")
+}
+
$(function() {
if ($("#episode").length > 0) {
sublimevideo.ready(function() {
View
7 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
Something went wrong with that request. Please try again.