From 6eed63807d63042cd6070e952c32bf1a3057152a Mon Sep 17 00:00:00 2001 From: Fabian Rodriguez Date: Sun, 1 Dec 2013 16:38:26 -0200 Subject: [PATCH 01/16] remove next and previous functionality from router --- app/assets/javascripts/app/router.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js index 169c1e32c..e75de9944 100644 --- a/app/assets/javascripts/app/router.js +++ b/app/assets/javascripts/app/router.js @@ -2,8 +2,6 @@ app.Router = Backbone.Router.extend({ routes: { //new hotness "posts/:id": "singlePost", - "posts/:id/next": "siblingPost", - "posts/:id/previous": "siblingPost", "p/:id": "singlePost", //oldness @@ -28,17 +26,6 @@ app.Router = Backbone.Router.extend({ this.renderPage(function(){ return new app.pages.SinglePostViewer({ id: id })}); }, - siblingPost : function(){ //next or previous - var post = new app.models.Post(); - post.bind("change", setPreloadAttributesAndNavigate) - post.fetch({url : window.location}) - - function setPreloadAttributesAndNavigate(){ - window.gon.preloads.post = post.attributes - app.router.navigate(post.url(), {trigger:true, replace: true}) - } - }, - renderPage : function(pageConstructor){ app.page && app.page.unbind && app.page.unbind() //old page might mutate global events $(document).keypress, so unbind before creating app.page = pageConstructor() //create new page after the world is clean (like that will ever happen) From 92db8cb92939d21a0707467e68a8b810801185da Mon Sep 17 00:00:00 2001 From: Fabian Rodriguez Date: Sun, 1 Dec 2013 16:49:18 -0200 Subject: [PATCH 02/16] remove #next and #previous from posts_controller --- app/controllers/posts_controller.rb | 20 +-------- spec/controllers/posts_controller_spec.rb | 54 ----------------------- 2 files changed, 1 insertion(+), 73 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 1d7dad7df..affb08f15 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -7,7 +7,7 @@ class PostsController < ApplicationController before_filter :authenticate_user!, :except => [:show, :iframe, :oembed, :interactions] before_filter :set_format_if_malformed_from_status_net, :only => :show - before_filter :find_post, :only => [:show, :next, :previous, :interactions] + before_filter :find_post, :only => [:show, :interactions] before_filter -> { @css_framework = :bootstrap } @@ -48,24 +48,6 @@ class PostsController < ApplicationController end end - def next - next_post = Post.visible_from_author(@post.author, current_user).newer(@post) - - respond_to do |format| - format.html{ redirect_to post_path(next_post) } - format.json{ render :json => PostPresenter.new(next_post, current_user)} - end - end - - def previous - previous_post = Post.visible_from_author(@post.author, current_user).older(@post) - - respond_to do |format| - format.html{ redirect_to post_path(previous_post) } - format.json{ render :json => PostPresenter.new(previous_post, current_user)} - end - end - def interactions respond_with(PostInteractionPresenter.new(@post, current_user)) end diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 691d37c8d..20b2d8a1c 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -167,58 +167,4 @@ describe PostsController do StatusMessage.exists?(message.id).should be_true end end - - describe "#next" do - before do - sign_in alice - Post.stub(:find_by_guid_or_id_with_user).and_return(mock_model(Post, :author => 4)) - Post.stub_chain(:visible_from_author, :newer).and_return(next_post) - end - - let(:next_post){ mock_model(StatusMessage, :id => 34)} - - context "GET .json" do - let(:mock_presenter) { mock(:as_json => {:title => "the unbearable lightness of being"}) } - - it "should return a show presenter the next post" do - PostPresenter.should_receive(:new).with(next_post, alice).and_return(mock_presenter) - get :next, :id => 14, :format => :json - response.body.should == {:title => "the unbearable lightness of being"}.to_json - end - end - - context "GET .html" do - it "should redirect to the next post" do - get :next, :id => 14 - response.should redirect_to(post_path(next_post)) - end - end - end - - describe "previous" do - before do - sign_in alice - Post.stub(:find_by_guid_or_id_with_user).and_return(mock_model(Post, :author => 4)) - Post.stub_chain(:visible_from_author, :older).and_return(previous_post) - end - - let(:previous_post){ mock_model(StatusMessage, :id => 11)} - - context "GET .json" do - let(:mock_presenter) { mock(:as_json => {:title => "existential crises"})} - - it "should return a show presenter the next post" do - PostPresenter.should_receive(:new).with(previous_post, alice).and_return(mock_presenter) - get :previous, :id => 14, :format => :json - response.body.should == {:title => "existential crises"}.to_json - end - end - - context "GET .html" do - it "should redirect to the next post" do - get :previous, :id => 14 - response.should redirect_to(post_path(previous_post)) - end - end - end end From d7b8cb2997a764d7be57dbd89dfa8fcefe79f20d Mon Sep 17 00:00:00 2001 From: Fabian Rodriguez Date: Sun, 1 Dec 2013 16:54:05 -0200 Subject: [PATCH 03/16] remove #next_post_path and #previous_post_path from postpresenter --- app/presenters/post_presenter.rb | 10 ---------- spec/presenters/post_presenter_spec.rb | 23 ++++++----------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 42fe3157c..74a9953d3 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -35,8 +35,6 @@ class PostPresenter :frame_name => @post.frame_name || template_name, :root => root, :title => title, - :next_post => next_post_path, - :previous_post => previous_post_path, :address => @post.address, :interactions => { @@ -49,14 +47,6 @@ class PostPresenter } end - def next_post_path - Rails.application.routes.url_helpers.next_post_path(@post) - end - - def previous_post_path - Rails.application.routes.url_helpers.previous_post_path(@post) - end - def title @post.text.present? ? post_page_title(@post) : I18n.translate('posts.presenter.title', :name => @post.author_name) end diff --git a/spec/presenters/post_presenter_spec.rb b/spec/presenters/post_presenter_spec.rb index 707e7fc5d..0d4cbe6b7 100644 --- a/spec/presenters/post_presenter_spec.rb +++ b/spec/presenters/post_presenter_spec.rb @@ -42,18 +42,18 @@ describe PostPresenter do @unauthenticated_presenter.user_reshare.should be_nil end end - + describe '#root' do it 'does not raise if the absolute_root does not exists' do first_reshare = FactoryGirl.create :reshare first_reshare.root = nil reshare = FactoryGirl.create :reshare, :root => first_reshare - + expect { PostPresenter.new(reshare).root }.to_not raise_error end - + it 'does not raise if the root does not exists' do reshare = FactoryGirl.create:reshare reshare.root = nil @@ -62,20 +62,8 @@ describe PostPresenter do }.to_not raise_error end end - - describe '#next_post_path' do - it 'returns a string of the users next post' do - @presenter.next_post_path.should == "#{Rails.application.routes.url_helpers.post_path(@sm)}/next" - end - end - describe '#previous_post_path' do - it 'returns a string of the users next post' do - @presenter.previous_post_path.should == "#{Rails.application.routes.url_helpers.post_path(@sm)}/previous" - end - end - - describe '#title' do + describe '#title' do context 'with posts with text' do context 'with a Markdown header of less than 200 characters on first line'do it 'returns atx style header' do @@ -90,6 +78,7 @@ describe PostPresenter do @presenter.title.should == "My title \n======" end end + context 'without a Markdown header of less than 200 characters on first line 'do it 'truncates post to the 20 first characters' do @sm = stub(:text => "Very, very, very long post") @@ -98,9 +87,9 @@ describe PostPresenter do end end end + context 'with posts without text' do it ' displays a messaage with the post class' do - @sm = stub(:text => "", :author => bob.person, :author_name => bob.person.name) @presenter.post = @sm @presenter.title.should == "A post from #{@sm.author.name}" From 0702db137aaccb851aee3ba0f0940b012ecbdb67 Mon Sep 17 00:00:00 2001 From: Fabian Rodriguez Date: Sun, 1 Dec 2013 17:32:13 -0200 Subject: [PATCH 04/16] remove PostViewerNav --- app/assets/javascripts/app/views/post-viewer/nav.js | 3 --- app/assets/templates/post-viewer/nav_tpl.jst.hbs | 11 ----------- 2 files changed, 14 deletions(-) delete mode 100644 app/assets/javascripts/app/views/post-viewer/nav.js delete mode 100644 app/assets/templates/post-viewer/nav_tpl.jst.hbs diff --git a/app/assets/javascripts/app/views/post-viewer/nav.js b/app/assets/javascripts/app/views/post-viewer/nav.js deleted file mode 100644 index 575a42493..000000000 --- a/app/assets/javascripts/app/views/post-viewer/nav.js +++ /dev/null @@ -1,3 +0,0 @@ -app.views.PostViewerNav = app.views.Base.extend({ - templateName: "post-viewer/nav" -}); \ No newline at end of file diff --git a/app/assets/templates/post-viewer/nav_tpl.jst.hbs b/app/assets/templates/post-viewer/nav_tpl.jst.hbs deleted file mode 100644 index 56771c791..000000000 --- a/app/assets/templates/post-viewer/nav_tpl.jst.hbs +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - From 179cc9e8dd38ae04144365c19d8df65c77beeab6 Mon Sep 17 00:00:00 2001 From: Fabian Rodriguez Date: Sun, 1 Dec 2013 17:33:45 -0200 Subject: [PATCH 05/16] remove PostViewerAuthor --- .../app/views/post-viewer/author.js | 15 ----------- .../templates/post-viewer/author_tpl.jst.hbs | 25 ------------------- 2 files changed, 40 deletions(-) delete mode 100644 app/assets/javascripts/app/views/post-viewer/author.js delete mode 100644 app/assets/templates/post-viewer/author_tpl.jst.hbs diff --git a/app/assets/javascripts/app/views/post-viewer/author.js b/app/assets/javascripts/app/views/post-viewer/author.js deleted file mode 100644 index af8e0aee2..000000000 --- a/app/assets/javascripts/app/views/post-viewer/author.js +++ /dev/null @@ -1,15 +0,0 @@ -app.views.PostViewerAuthor = app.views.Base.extend({ - - id : "post-author", - className : "media", - - tooltipSelector : ".profile-image-container", - - templateName: "post-viewer/author", - - initialize : function() { - /* add a class so we know how to color the text for the author name */ - this.$el.addClass(this.model.get("frame_name")) - } - -}); \ No newline at end of file diff --git a/app/assets/templates/post-viewer/author_tpl.jst.hbs b/app/assets/templates/post-viewer/author_tpl.jst.hbs deleted file mode 100644 index 3828014cc..000000000 --- a/app/assets/templates/post-viewer/author_tpl.jst.hbs +++ /dev/null @@ -1,25 +0,0 @@ -
- {{#linkToPerson author}} -
- {{/linkToPerson}} -
- -
- {{#linkToPerson author}} - {{name}} - {{/linkToPerson}} - - {{#if root}} - - {{#linkToPerson root.author}} - {{name}} - {{/linkToPerson}} - {{/if}} - -
-
-
From bf3ee8d7bb5937f70bc009c2ad62dd32fec63f6b Mon Sep 17 00:00:00 2001 From: Fabian Rodriguez Date: Sun, 1 Dec 2013 17:46:25 -0200 Subject: [PATCH 06/16] remove PostViewer --- .../javascripts/app/pages/post-viewer.js | 107 ------------------ app/assets/templates/post-viewer_tpl.jst.hbs | 4 - .../javascripts/app/pages/post-viewer_spec.js | 14 --- 3 files changed, 125 deletions(-) delete mode 100644 app/assets/javascripts/app/pages/post-viewer.js delete mode 100644 app/assets/templates/post-viewer_tpl.jst.hbs delete mode 100644 spec/javascripts/app/pages/post-viewer_spec.js diff --git a/app/assets/javascripts/app/pages/post-viewer.js b/app/assets/javascripts/app/pages/post-viewer.js deleted file mode 100644 index 237fdd3f1..000000000 --- a/app/assets/javascripts/app/pages/post-viewer.js +++ /dev/null @@ -1,107 +0,0 @@ -app.pages.PostViewer = app.views.Base.extend({ - templateName: "post-viewer", - - subviews : { - "#post-content" : "postView", - "#post-nav" : "navView", - "#post-interactions" : "interactionsView", - "#author-info" : "authorView" - }, - - initialize : function(options) { - this.model = new app.models.Post({ id : options.id }); - this.model.preloadOrFetch().done(_.bind(this.initViews, this)); - this.model.interactions.fetch() //async, yo, might want to throttle this later. - - this.bindEvents() - }, - - initViews : function() { - /* init view */ - this.authorView = new app.views.PostViewerAuthor({ model : this.model }); - this.interactionsView = new app.views.PostViewerInteractions({ model : this.model }); - this.navView = new app.views.PostViewerNav({ model : this.model }); - this.postView = app.views.Post.showFactory(this.model) - - this.render(); - }, - - bindEvents : function(){ - this.prepIdleHooks(); - this.bindNavHooks(); - - $(document).bind("keypress", _.bind(this.commentAnywhere, this)) - $(document).bind("keypress", _.bind(this.invokePane, this)) - $(document).bind("keyup", _.bind(this.closePane, this)) - }, - - unbind : function(){ - $(document).unbind("idle.idleTimer") - $(document).unbind("active.idleTimer") - $(document).unbind('keydown') - $(document).unbind('keypress') - $(document).unbind('keyup') - }, - - prepIdleHooks : function () { - $.idleTimer(3000); - - $(document).bind("idle.idleTimer", function(){ - $("body").addClass('idle'); - }); - - $(document).bind("active.idleTimer", function(){ - $("body").removeClass('idle'); - }); - }, - - bindNavHooks : function() { - var model = this.model; - $(document).keydown(function(evt){ - // prevent nav from happening if the user is using the arrow keys to navigate through their comment text - if($(evt.target).is("textarea")) { return } - - switch(evt.keyCode) { - case KEYCODES.LEFT: - app.router.navigate(model.get("next_post"), true); break; - case KEYCODES.RIGHT: - app.router.navigate(model.get("previous_post"), true); break; - default: - break; - } - }) - }, - - postRenderTemplate : function() { - if(this.model.get("title")){ - // formats title to html... - var html_title = app.helpers.textFormatter(this.model.get("title"), this.model); - //... and converts html to plain text - document.title = $('
').html(html_title).text(); - } - }, - - commentAnywhere : function(evt) { - /* ignore enter, space bar, arrow keys */ - if(_.include([KEYCODES.RETURN, KEYCODES.SPACE, KEYCODES.LEFT, - KEYCODES.UP, KEYCODES.RIGHT, KEYCODES.DOWN], evt.keyCode) || - this.modifierPressed(evt) ) { return } - - this.interactionsView.invokePane(); - $('#new-post-comment textarea').focus(); - }, - - invokePane : function(evt) { - if(evt.keyCode != KEYCODES.SPACE) { return } - this.interactionsView.invokePane(); - }, - - closePane : function(evt) { - if(evt.keyCode != KEYCODES.ESC) { return } - this.interactionsView.hidePane(); - }, - - modifierPressed: function(evt) { - return (evt.altKey || evt.ctrlKey || evt.shiftKey); - } -}); diff --git a/app/assets/templates/post-viewer_tpl.jst.hbs b/app/assets/templates/post-viewer_tpl.jst.hbs deleted file mode 100644 index dada78ec9..000000000 --- a/app/assets/templates/post-viewer_tpl.jst.hbs +++ /dev/null @@ -1,4 +0,0 @@ -
-
-
-
diff --git a/spec/javascripts/app/pages/post-viewer_spec.js b/spec/javascripts/app/pages/post-viewer_spec.js deleted file mode 100644 index eeda1184a..000000000 --- a/spec/javascripts/app/pages/post-viewer_spec.js +++ /dev/null @@ -1,14 +0,0 @@ -describe("app.Pages.PostViewer", function(){ - describe("postRenderTemplate", function(){ - beforeEach(function(){ - app.setPreload('post', factory.post({frame_name : "note"}).attributes); - this.page = new app.pages.PostViewer({id : 2}); - }) - it('translates post title from Markdown to plain text and pushes it in document.title', function () { - this.page.model.set({title : "### My [Markdown](url) *title*" }); - this.page.postRenderTemplate(); - expect(document.title).toEqual("My Markdown title"); - }) - }) -}); - From 9be780468d0621d71a5e3002f00df62361dbf397 Mon Sep 17 00:00:00 2001 From: Fabian Rodriguez Date: Sun, 1 Dec 2013 17:54:41 -0200 Subject: [PATCH 07/16] remove PostViewerInteractions --- .../app/views/post-viewer/interactions.js | 56 ------------------- .../post-viewer/interactions_tpl.jst.hbs | 11 ---- 2 files changed, 67 deletions(-) delete mode 100644 app/assets/javascripts/app/views/post-viewer/interactions.js delete mode 100644 app/assets/templates/post-viewer/interactions_tpl.jst.hbs diff --git a/app/assets/javascripts/app/views/post-viewer/interactions.js b/app/assets/javascripts/app/views/post-viewer/interactions.js deleted file mode 100644 index b9206ee2a..000000000 --- a/app/assets/javascripts/app/views/post-viewer/interactions.js +++ /dev/null @@ -1,56 +0,0 @@ -app.views.PostViewerInteractions = app.views.Base.extend({ - - className : "", - - subviews : { - "#post-feedback" : "feedbackView", - "#post-reactions" : "reactionsView", - "#new-post-comment" : "newCommentView" - }, - - templateName: "post-viewer/interactions", - - initialize : function() { - this.initViews(); - - this.feedbackView && this.feedbackView.bind("invokePane", this.invokePane, this) - this.feedbackView && this.feedbackView.bind("hidePane", this.hidePane, this) - }, - - initViews : function() { - this.reactionsView = new app.views.PostViewerReactions({ model : this.model.interactions }) - - /* subviews that require user */ - this.feedbackView = new app.views.PostViewerFeedback({ model : this.model }) - if(app.currentUser.authenticated()) { - this.newCommentView = new app.views.PostViewerNewComment({ model : this.model }) - } - }, - - togglePane : function(evt) { - if(evt) { evt.preventDefault() } - $("#post-interactions").toggleClass("active") - this.$("#post-info").slideToggle(300) - this.removeTooltips() - }, - - invokePane : function() { - if(!this.$("#post-info").is(":visible")) { - this.$("#post-info-sneaky").addClass("passive") - this.togglePane() - } - }, - - hidePane : function() { - if(this.$("#post-info").is(":visible")) { - - /* it takes about 400ms for the pane to hide. we need to keep - * the sneaky hidden until the slide is complete */ - setTimeout(function(){ - this.$("#post-info-sneaky").removeClass("passive") - }, 400) - - this.togglePane() - } - } -}); \ No newline at end of file diff --git a/app/assets/templates/post-viewer/interactions_tpl.jst.hbs b/app/assets/templates/post-viewer/interactions_tpl.jst.hbs deleted file mode 100644 index 1b59fa325..000000000 --- a/app/assets/templates/post-viewer/interactions_tpl.jst.hbs +++ /dev/null @@ -1,11 +0,0 @@ -
- - - From cfc247db752672a84a7ad44973af66359e9e4c21 Mon Sep 17 00:00:00 2001 From: Fabian Rodriguez Date: Sun, 1 Dec 2013 17:55:56 -0200 Subject: [PATCH 08/16] remove PostViewerFeedback --- .../app/views/post-viewer/feedback.js | 34 ------------ .../post-viewer/feedback_tpl.jst.hbs | 18 ------ .../app/views/feedback_actions_view_spec.js | 55 ------------------- 3 files changed, 107 deletions(-) delete mode 100644 app/assets/javascripts/app/views/post-viewer/feedback.js delete mode 100644 app/assets/templates/post-viewer/feedback_tpl.jst.hbs delete mode 100644 spec/javascripts/app/views/feedback_actions_view_spec.js diff --git a/app/assets/javascripts/app/views/post-viewer/feedback.js b/app/assets/javascripts/app/views/post-viewer/feedback.js deleted file mode 100644 index 18437bd4e..000000000 --- a/app/assets/javascripts/app/views/post-viewer/feedback.js +++ /dev/null @@ -1,34 +0,0 @@ -//= require ../feedback_view - -app.views.PostViewerFeedback = app.views.Feedback.extend({ - id : "user-controls", - className : "", - - templateName: "post-viewer/feedback", - - subviews : { - ".feedback-actions" : "feedbackActions" - }, - - events :_.extend({}, app.views.Feedback.prototype.events, { - "click *[rel='invoke-interaction-pane']" : "invokePane", - "click *[rel='hide-interaction-pane']" : "hidePane" - }), - - initViews : function(){ - this.feedbackActions = new app.views.FeedbackActions({model : this.model}) - }, - - postRenderTemplate : function() { - this.sneakyVisiblity() - }, - - sneakyVisiblity : function() { - if(!$("#post-info").is(":visible")) { - this.$("#post-info-sneaky").removeClass('passive') - } - }, - - invokePane : function(evt){ this.trigger("invokePane") }, - hidePane : function(evt){ this.trigger("hidePane") }, -}); diff --git a/app/assets/templates/post-viewer/feedback_tpl.jst.hbs b/app/assets/templates/post-viewer/feedback_tpl.jst.hbs deleted file mode 100644 index 1eacdf1dc..000000000 --- a/app/assets/templates/post-viewer/feedback_tpl.jst.hbs +++ /dev/null @@ -1,18 +0,0 @@ -