hash tags are linked on the front end, adding markdown.js file
This commit is contained in:
parent
fd6e3bae62
commit
0fb1bf5d4b
4 changed files with 1512 additions and 3 deletions
|
|
@ -16,7 +16,9 @@ class Post < ActiveRecord::Base
|
||||||
api_accessible :backbone do |t|
|
api_accessible :backbone do |t|
|
||||||
t.add :id
|
t.add :id
|
||||||
t.add :guid
|
t.add :guid
|
||||||
t.add :text
|
t.add lambda { |post|
|
||||||
|
post.raw_message
|
||||||
|
}, :as => :text
|
||||||
t.add :public
|
t.add :public
|
||||||
t.add :created_at
|
t.add :created_at
|
||||||
t.add :comments_count
|
t.add :comments_count
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,21 @@
|
||||||
var postContentView = app.views.StreamObject.extend({
|
var postContentView = app.views.StreamObject.extend({
|
||||||
presenter : function(){
|
presenter : function(){
|
||||||
return _.extend(this.defaultPresenter(), {
|
return _.extend(this.defaultPresenter(), {
|
||||||
text : markdown.toHTML(this.model.get("text") || "")
|
text : metafyText(this.model.get("text"))
|
||||||
})
|
})
|
||||||
},
|
|
||||||
|
function metafyText(text) {
|
||||||
|
//we want it to return at least a <p> from markdown
|
||||||
|
text = text || ""
|
||||||
|
return hashtagify(markdown.toHTML(text) || text)
|
||||||
|
}
|
||||||
|
|
||||||
|
function hashtagify(text){
|
||||||
|
return text.replace(/(#([\u0080-\uFFFF|\w|-]+|<3))/g, function(tagText) {
|
||||||
|
return "<a href='/tags/" + tagText.substring(1) + "' class='tag'>" + tagText + "</a>"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
1467
public/javascripts/vendor/markdown.js
vendored
Normal file
1467
public/javascripts/vendor/markdown.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -38,6 +38,34 @@ describe("app.views.Post", function(){
|
||||||
expect(window.markdown.toHTML).toHaveBeenCalledWith("I have three Belly Buttons")
|
expect(window.markdown.toHTML).toHaveBeenCalledWith("I have three Belly Buttons")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
context("changes hashtags to links", function(){
|
||||||
|
it("links to a hashtag to the tag page", function(){
|
||||||
|
this.statusMessage.set({text: "I love #parties"})
|
||||||
|
var view = new app.views.Post({model : this.statusMessage}).render();
|
||||||
|
expect(view.$("a:contains('#parties')").attr('href')).toBe('/tags/parties')
|
||||||
|
})
|
||||||
|
|
||||||
|
it("changes all hashtags", 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)
|
||||||
|
})
|
||||||
|
|
||||||
|
// NOTE THIS DIVERGES FROM GRUBER'S ORIGINAL DIALECT OF MARKDOWN.
|
||||||
|
// We had to edit markdown.js line 291 - good people would have made a new dialect.
|
||||||
|
//
|
||||||
|
// original : var m = block.match( /^(#{1,6})\s*(.*?)\s*#*\s*(?:\n|$)/ );
|
||||||
|
// \s* changed to \s+
|
||||||
|
//
|
||||||
|
it("doesn't create a header tag if the first word is a hashtag", function(){
|
||||||
|
this.statusMessage.set({text: "#parties, I love"})
|
||||||
|
var view = new app.views.Post({model : this.statusMessage}).render();
|
||||||
|
expect(view.$("h1:contains(parties)")).not.toExist();
|
||||||
|
expect(view.$("a:contains('#parties')")).toExist();
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
context("user not signed in", function(){
|
context("user not signed in", function(){
|
||||||
it("does not provide a Feedback view", function(){
|
it("does not provide a Feedback view", function(){
|
||||||
window.current_user = app.user(null);
|
window.current_user = app.user(null);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue