From 8fa6c46de25165af1ac1f98c04ece4818be2419f Mon Sep 17 00:00:00 2001 From: Dennis Collinson Date: Sat, 7 Jan 2012 14:22:38 -0800 Subject: [PATCH] DG DC more hashtag fixes, throw in mention clearing cowboy style --- .../app/views/post_content_view.js | 6 +++--- .../javascripts/app/views/publisher_view.js | 19 ++++++++++++------- spec/javascripts/app/views/post_view_spec.js | 10 +++++++++- .../javascripts/app/views/stream_view_spec.js | 2 +- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/public/javascripts/app/views/post_content_view.js b/public/javascripts/app/views/post_content_view.js index ff594f784..358de275b 100644 --- a/public/javascripts/app/views/post_content_view.js +++ b/public/javascripts/app/views/post_content_view.js @@ -22,9 +22,9 @@ } function hashtagify(text){ - var utf8WordCharcters =/(#([\u0080-\uFFFF|\w|-]+|<3))/g - return text.replace(utf8WordCharcters, function(tagText) { - return "" + tagText + "" + var utf8WordCharcters =/(\s|^|>)#([\u0080-\uFFFF|\w|-]+|<3)/g + return text.replace(utf8WordCharcters, function(hashtag, preceeder, tagText) { + return preceeder + "#" + tagText + "" }) } diff --git a/public/javascripts/app/views/publisher_view.js b/public/javascripts/app/views/publisher_view.js index 13967168b..52a3ca865 100644 --- a/public/javascripts/app/views/publisher_view.js +++ b/public/javascripts/app/views/publisher_view.js @@ -1,5 +1,8 @@ -app.views.Publisher = Backbone.View.extend({ +//this file is the scary no-no-zone bad-touch of our backbone code. +//after re-writing/eliminating the existing Publisher let's re-write +//this with PANACHE! +app.views.Publisher = Backbone.View.extend({ el : "#publisher", events : { @@ -8,6 +11,7 @@ app.views.Publisher = Backbone.View.extend({ "submit form" : "createStatusMessage" }, + initialize : function(){ this.collection = this.collection || new app.collections.Stream; return this; @@ -37,12 +41,10 @@ app.views.Publisher = Backbone.View.extend({ }, clear : function() { - // remove form data - _.each(this.$('textarea'), function(element) { - $(element).removeClass("with_attachments") - .css("paddingBottom", "") - .val(""); - }); + this.$('textarea') + .removeClass("with_attachments") + .css("paddingBottom", "") + .val(""); // remove photos this.$("#photodropzone").find('li').remove(); @@ -50,6 +52,9 @@ app.views.Publisher = Backbone.View.extend({ // close publishing area (CSS) this.close(); + // clear mentions (TO BE REMOVED!!) + Publisher.autocompletion.mentionList.clear() + return this; }, diff --git a/spec/javascripts/app/views/post_view_spec.js b/spec/javascripts/app/views/post_view_spec.js index e7b676994..db065d54a 100644 --- a/spec/javascripts/app/views/post_view_spec.js +++ b/spec/javascripts/app/views/post_view_spec.js @@ -49,6 +49,15 @@ describe("app.views.Post", function(){ this.statusMessage.set({text: "I love #parties and #rockstars and #unicorns"}) var view = new app.views.Post({model : this.statusMessage}).render(); expect(view.$("a.tag").length).toBe(3) + expect(view.$("a:contains('#parties')")).toExist(); + expect(view.$("a:contains('#rockstars')")).toExist(); + expect(view.$("a:contains('#unicorns')")).toExist(); + }) + + it("requires hashtags to be preceeded with a space", function(){ + this.statusMessage.set({text: "I love the#parties"}) + var view = new app.views.Post({model : this.statusMessage}).render(); + expect(view.$(".tag").length).toBe(0) }) // NOTE THIS DIVERGES FROM GRUBER'S ORIGINAL DIALECT OF MARKDOWN. @@ -62,7 +71,6 @@ describe("app.views.Post", function(){ var view = new app.views.Post({model : this.statusMessage}).render(); expect(view.$("h1:contains(parties)")).not.toExist(); expect(view.$("a:contains('#parties')")).toExist(); - }) }) diff --git a/spec/javascripts/app/views/stream_view_spec.js b/spec/javascripts/app/views/stream_view_spec.js index 30cda0951..a7df063f5 100644 --- a/spec/javascripts/app/views/stream_view_spec.js +++ b/spec/javascripts/app/views/stream_view_spec.js @@ -34,7 +34,7 @@ describe("app.views.Stream", function(){ context("when rendering a Status Mesasage", function(){ it("shows the status message in the content area", function(){ - expect(this.statusElement.find(".post-content p").text()).toContain("you're gonna love this") //markdown'ed + expect(this.statusElement.find(".post-content p").text()).toContain("you're gonna love this") //markdown'ed }) }) })