Commit dceee11f

mo <mo.khan@gmail.com>
2017-09-03 21:16:43
remove disqus
1 parent 2fe8923
app/assets/javascripts/views/my/profiles/show_view.js.coffee
@@ -13,7 +13,6 @@ class CakeSide.Views.My.Profiles.ShowView extends Marionette.ItemView
 
   modelEvents:
     'invalid': 'displayError'
-    'sync': 'syncedUp'
 
   events:
     "submit #profile-form": "save"
@@ -29,10 +28,6 @@ class CakeSide.Views.My.Profiles.ShowView extends Marionette.ItemView
       error: @couldNotSave
     )
 
-  syncedUp: (event) ->
-    console.log(arguments)
-    console.log('syncd')
-
   savedSuccessfully: (profile) =>
     @disableSaveButton()
     @ui.status.removeClass('hide')
app/assets/javascripts/views/disqus_view.js.coffee
@@ -1,32 +0,0 @@
-class CakeSide.Views.DisqusView extends Backbone.View
-  el: "#disqus_thread"
-  initialize: (options) ->
-    disqus = document.createElement('script')
-    disqus.type = 'text/javascript'
-    disqus.async = true
-    disqus.src = "//#{options.disqus_shortname}.disqus.com/embed.js"
-    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(disqus)
-
-  render: (options) ->
-    try
-      @$el.removeClass('hidden')
-      that = @
-      DISQUS.reset
-        reload: true,
-        config: ->
-          @page.identifier = options.identifier
-          @page.title = "CakeSide - #{options.title}"
-          @page.url = options.url
-          @callbacks.onNewComment = [that.saveComment]
-      @
-    catch error
-      console.log(error)
-    finally
-      @
-
-  hide: ->
-    @$el.addClass('hidden')
-
-  saveComment: (comment) ->
-    $.post Routes.comments_path(), { id: comment.id, url: document.URL, comment: comment }, (result) ->
-      console.log(result)
app/assets/javascripts/cakeside.js.coffee
@@ -21,7 +21,6 @@ window.CakeSide =
     CakeSide.Application = new Marionette.Application()
     CakeSide.Application.addRegions
       content_region: '#backbone-content'
-      comment_region: '#disqus_thread'
 
     CakeSide.Application.addInitializer (options) ->
       new CakeSide.Routers.CakesRouter
@@ -41,10 +40,6 @@ window.CakeSide =
     @categories = new CakeSide.Collections.CategoriesCollection()
     @tutorials = new CakeSide.Collections.TutorialsCollection()
 
-    #@disqus_view = new CakeSide.Views.DisqusView
-      #disqus_shortname: data.disqus_shortname
-    #CakeSide.Application.reqres.setHandler 'CommentView', =>
-      #@disqus_view
     CakeSide.Application.reqres.setHandler 'CakesRepository', =>
       @cakes
     CakeSide.Application.reqres.setHandler 'CategoriesRepository', =>
app/controllers/comments_controller.rb
@@ -1,17 +0,0 @@
-class CommentsController < ApplicationController
-  def create
-    creation = Creation.find(creation_id)
-    @comment = current_user.comment_on(creation, comment_params[:text], comment_params[:id])
-    render json: @comment
-  end
-
-  private
-
-  def creation_id
-    params[:url].match(/\/(\d+)/)[0].gsub("/", "")
-  end
-
-  def comment_params
-    params.require(:comment).permit(:id, :text)
-  end
-end
app/helpers/application_helper.rb
@@ -13,15 +13,6 @@ module ApplicationHelper
     title.blank? ? "CakeSide - for cake lovers!" : "#{title} - CakeSide"
   end
 
-  def disqus_auth(user = current_user)
-    data = { id: user.id, username: user.name, email: user.email, url: "https://#{request.host_with_port}/profiles/#{user.to_param}" }
-    data[:avatar] = user.avatar.url_for(:thumb) if user.has_avatar?
-    message = Base64.encode64(data.to_json).gsub("\n", "")
-    timestamp = Time.now.to_i
-    signature = OpenSSL::HMAC.hexdigest('sha1', ENV['DISQUS_SECRET_KEY'] || '', "#{message} #{timestamp}")
-    "#{message} #{signature} #{timestamp}"
-  end
-
   def controller?(name)
     params[:controller].include?(name.to_s)
   end
app/views/cakes/show.html.erb
@@ -5,5 +5,3 @@
 <div id="primary-photo">
   <%= render partial: 'show' %>
 </div>
-
-<%# render partial: "shared/disqus", locals: { id: "c-#{@creation.id}" } %>
app/views/my/kitchens/show.html.erb
@@ -2,16 +2,7 @@
 <%= content_for :javascript do -%>
   <%= javascript_tag do %>
     var ALL_TAGS = <%= raw @tags.pluck(:name) %>;
-    var disqus_shortname = '<%= ENV['DISQUS_SHORTNAME'] %>';
-    var disqus_identifier = 'u-<%= current_user.id %>';
-    var disqus_config = function(){
-      this.page.remote_auth_s3 = '<%= disqus_auth %>';
-      this.page.api_key = '<%= ENV['DISQUS_API_KEY'] %>';
-    };
-    CakeSide.initialize({
-      access_token: '<%= current_user.authentication_token %>',
-      disqus_shortname: disqus_shortname,
-    });
+    CakeSide.initialize({ access_token: '<%= current_user.authentication_token %>' });
   <% end %>
 <% end %>
 
@@ -21,5 +12,4 @@
   </div>
   <div id="backbone-content" class="col-9"></div>
 </div>
-<div id="disqus_thread" class="row"></div>
 <div id="modal" class="modal hide fade"></div>
app/views/shared/_disqus.html.erb
@@ -1,21 +0,0 @@
-<div id="disqus_thread"></div>
-<script type="text/javascript">
-var disqus_shortname = '<%= ENV['DISQUS_SHORTNAME'] %>';
-var disqus_identifier = '<%= id %>';
-<% if current_user %>
-  var disqus_config = function(){
-    this.page.remote_auth_s3 = '<%= disqus_auth %>';
-    this.page.api_key = '<%= ENV['DISQUS_API_KEY'] %>';
-    this.callbacks.onNewComment = [function(comment) {
-      $.post('<%= comments_path %>', { id: comment.id, url: document.URL, comment: comment }, function(result){ console.log(result); });
-    }];
-  };
-<% end %>
-(function() {
- var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
- dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
- (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
- })();
-</script>
-<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
-<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
config/routes.rb
@@ -4,8 +4,6 @@ Cake::Application.routes.draw do
   get "about_us" => "home#about_us"
   get "why_cakeside" => "home#why_cakeside"
 
-  post 'comments', to: 'comments#create'
-
   resources :tutorials, only: [:index, :show] do
     get 'page/:page', action: :index, on: :collection
   end
spec/controllers/cakes_controller_spec.rb
@@ -1,69 +0,0 @@
-require 'rails_helper'
-
-describe CakesController do
-  let(:user) { create(:user) }
-
-  describe "#index" do
-    let!(:cakes) { create(:category, slug: "cakes") }
-    let!(:cookies) { create(:category, slug: "cookies") }
-
-    it "returns all published cakes" do
-      cake = create(:published_cake, category: cakes)
-      cookie = create(:published_cake, category: cookies)
-      unpublished_cake = create(:cake, category: cakes)
-      get :index
-      expect(assigns(:cakes)).to match_array([cake, cookie])
-    end
-
-    it "returns all cakes in the category" do
-      cookie = create(:published_cake, name: "cookie", category: cookies)
-      get :index, category: cookie.category.slug
-      expect(assigns(:cakes)).to match_array([cookie])
-    end
-
-    it "returns all cakes matching the search query" do
-      cake = create(:published_cake, name: "cake", category: cakes)
-      get :index, q: cake.name[0..2]
-      expect(assigns(:cakes)).to match_array([cake])
-    end
-
-    it "returns all cakes tagged with the tag" do
-      cake = create(:published_cake, name: "cake", category: cakes)
-      cake.tag_list = "cakes"
-      cake.save!
-
-      get :index, tags: "cakes"
-      expect(assigns(:cakes)).to match_array([cake])
-    end
-
-    describe "sorting" do
-      let!(:old_cake) { create(:published_cake, name: 'old', created_at: 2.days.ago) }
-      let!(:new_cake) { create(:published_cake, name: 'new', created_at: 1.day.ago) }
-
-      it 'returns oldest cakes first' do
-        get :index, sort: "oldest"
-        expect(assigns(:cakes).to_a).to eql([ old_cake, new_cake ])
-      end
-
-      it 'returns newest cakes first' do
-        get :index, sort: "newest"
-        expect(assigns(:cakes).to_a).to eql([ new_cake, old_cake ])
-      end
-    end
-  end
-
-  describe "#show" do
-    let(:cake) { create(:cake, user: user) }
-    let(:photo) { create(:photo, imageable: cake) }
-
-    it "loads the cake" do
-      get :show, id: cake.id
-      expect(assigns(:creation)).to eql(cake)
-    end
-
-    it 'loads the selected image' do
-      get :show, id: cake.id, photo_id: photo.id
-      expect(assigns(:primary_image)).to eql(photo)
-    end
-  end
-end
spec/controllers/comments_controller_spec.rb
@@ -1,20 +0,0 @@
-require "rails_helper"
-
-describe CommentsController do
-  context "#create" do
-    let(:creation) { create(:creation) }
-    let(:user) { create(:user) }
-
-    before :each do
-      http_login(user)
-    end
-
-    it "creates a new comment" do
-      post :create, id: 1207743539, url: "http://localhost:3000/creations/#{creation.to_param}", comment: { id: 1207743539, text: 'very nice' }
-      comment = Comment.last
-      expect(comment.disqus_id).to eql(1207743539)
-      expect(comment.creation).to eql(creation)
-      expect(comment.text).to eql('very nice')
-    end
-  end
-end
spec/helpers/application_helper_spec.rb
@@ -1,22 +1,4 @@
 require "rails_helper"
 
 describe ApplicationHelper do
-  describe "#disqus_auth" do
-    let(:user) { create(:user) }
-    let(:secret) { 'secret' }
-
-    let(:expected) do
-      data = { id: user.id, username: user.name, email: user.email, url: "https://test.host/profiles/#{user.to_param}" }.to_json
-      message = Base64.encode64(data).gsub("\n", "")
-      timestamp = Time.now.to_i
-      signature = OpenSSL::HMAC.hexdigest('sha1', secret, "#{message} #{timestamp}")
-      "#{message} #{signature} #{timestamp}"
-    end
-
-    before { ENV['DISQUS_SECRET_KEY'] = secret }
-
-    it "should generate a single sign on token" do
-      expect(helper.disqus_auth(user)).to eql(expected)
-    end
-  end
 end
spec/routing/comments_routing_spec.rb
@@ -1,7 +0,0 @@
-require "rails_helper"
-
-describe "/comments" do
-  it "routes to the create action" do
-    expect({ :post => '/comments' }).to route_to(controller: 'comments', action: 'create')
-  end
-end