DG DC more hashtag fixes, throw in mention clearing cowboy style

This commit is contained in:
Dennis Collinson 2012-01-07 14:22:38 -08:00
parent daba42c857
commit 8fa6c46de2
4 changed files with 25 additions and 12 deletions

View file

@ -22,9 +22,9 @@
}
function hashtagify(text){
var utf8WordCharcters =/(#([\u0080-\uFFFF|\w|-]+|<3))/g
return text.replace(utf8WordCharcters, function(tagText) {
return "<a href='/tags/" + tagText.substring(1) + "' class='tag'>" + tagText + "</a>"
var utf8WordCharcters =/(\s|^|>)#([\u0080-\uFFFF|\w|-]+|&lt;3)/g
return text.replace(utf8WordCharcters, function(hashtag, preceeder, tagText) {
return preceeder + "<a href='/tags/" + tagText + "' class='tag'>#" + tagText + "</a>"
})
}

View file

@ -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;
},

View file

@ -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();
})
})

View file

@ -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&#39;re gonna love this") //markdown'ed
expect(this.statusElement.find(".post-content p").text()).toContain("you're gonna love this") //markdown'ed
})
})
})