Commit 81af15ea

mo khan <mo@mokhan.ca>
2013-07-05 21:36:04
install disqus, remove old comments from creations#show page
1 parent e43f1ae
Changed files (4)
app/helpers/application_helper.rb
@@ -18,7 +18,7 @@ module ApplicationHelper
   end
 
   def disqus_auth(user = current_user)
-    data = { id: user.id, username: user.username, email: user.email }.to_json
+    data = { id: user.id, username: user.email, email: user.email }.to_json
     message = Base64.encode64(data).gsub("\n", "")
     timestamp = Time.now.to_i
     signature = OpenSSL::HMAC.hexdigest('sha1', ENV['DISQUS_SECRET_KEY'], "#{message} #{timestamp}")
app/views/creations/show.html.erb
@@ -77,62 +77,4 @@ $(function() {
   </div>
 <% end %>
 
-<div class="row">
-  <a href="#" id="comments"></a>
-  <div class="span12">
-    <h3>Comments <small><%= pluralize @comments.length, "comment" %></small></h3>
-    <% unless user_signed_in? %>
-      <p><%= link_to "SIGN IN", new_user_session_path, :class => "btn btn-primary mix-link", "data-event" => "click-on-sign-in-to-comment" %> to comment </p>
-  <% else %>
-      <p><a id="add-comment-button" class="btn btn-large btn-primary mix-link" data-event="click-on-add-comment" data-toggle="modal" href="#add-comment-dialog"><i class="icon-comment"> </i>COMMENT</a></p>
-  <% end -%>
-    <% @comments.each do |comment| %>
-      <div class="row">
-      <div class="span6">
-        <div class="row">
-          <div class="span6">
-            <h4><strong><a href="<%= url_for profile_path(comment.user) %>"><%= comment.user.name %> </a>said...</strong></h4>
-          </div>
-        </div>
-        <div class="row">
-          <div class="span2">
-            <a href="<%= url_for profile_path(comment.user) %>" class="thumbnail"><%= avatar_for(comment.user, {:size => 260 }) %></a>
-          </div>
-          <div class="span6">
-            <p> <%= comment.body %> </p>
-          </div>
-        </div>
-        <div class="row">
-          <div class="span6">
-            <p></p>
-            <p>
-            <i class="icon-user"></i> By <%= link_to comment.user.name, profile_path(comment.user) %>
-          | <i class="icon-calendar"></i> <%= comment.created_at.to_s :foomat %> 
-          </p>
-          </div>
-        </div>
-      </div>
-    </div>
-    <hr>
-  <% end -%>
-  </div>
-</div>
-<div id="add-comment-dialog" class="modal hide fade">
-  <%= form_tag(creation_comments_path(@creation), :method => "post", :html => { :class => "form-horizontal"}) do |f| %>
-    <div class="modal-header">
-    <button type="button" class="close" data-dismiss="modal">x</button>
-    <h3>Add Comment</h3>
-  </div>
-  <div class="modal-body">
-    <%= fields_for Comment.new do |f| %>
-      <%= f.text_area :body, :class => "span5" %>
-  <% end %>
-  </div>
-  <div class="modal-footer">
-    <input type="submit" class="btn btn-primary" value="Add Comment" />
-    <a href="#" class="btn" data-dismiss="modal">Close</a>
-  </div>
-<% end %>
-</div>
-
-<%= render :partial => "disqus", :locals => { :id => "c-#{@creation.id}" } %>
+<%= render :partial => "shared/disqus", :locals => { :id => "c-#{@creation.id}" } %>
app/views/shared/_disqus.html.erb
@@ -1,6 +1,5 @@
 <div id="disqus_thread"></div>
 <script type="text/javascript">
-var disqus_shortname = 'cakeside';
 var disqus_shortname = '<%= ENV['DISQUS_SHORTNAME'] %>';
 var disqus_identifier = '<%= id %>';
 (function() {
@@ -9,6 +8,7 @@ var disqus_identifier = '<%= id %>';
   (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
 })();
 </script>
+<% if current_user %>
 <script type="text/javascript" charset="utf-8">
 (function(){
   var disqus_config = function(){
@@ -17,5 +17,6 @@ var disqus_identifier = '<%= id %>';
   };
 })();
 </script>
+<% end %>
 <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
 <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
spec/helpers/application_helper_spec.rb
@@ -2,7 +2,7 @@ require "spec_helper"
 
 describe ApplicationHelper do
   describe :disqus_auth do
-    let(:user) { OpenStruct.new(id: 1, username: 'blah', email: 'test@fairgoods.com') }
+    let(:user) { OpenStruct.new(id: 1, username: 'blah', email: 'test@cakeside.com') }
 
     before :each do
       data = { id: user.id, username: user.username, email: user.email }.to_json