use content_view for comments (markdown, tagging)
This commit is contained in:
parent
985657cbc3
commit
d5a4f9eb98
5 changed files with 60 additions and 65 deletions
|
|
@ -18,9 +18,7 @@
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<p class="collapsible">
|
|
||||||
<%= text %>
|
<%= text %>
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="comment_info">
|
<div class="comment_info">
|
||||||
<time class="timeago" datetime="<%= created_at %>"/>
|
<time class="timeago" datetime="<%= created_at %>"/>
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ javascripts:
|
||||||
- public/javascripts/app/models/*
|
- public/javascripts/app/models/*
|
||||||
- public/javascripts/app/collections/*
|
- public/javascripts/app/collections/*
|
||||||
- public/javascripts/app/views/stream_object_view.js
|
- public/javascripts/app/views/stream_object_view.js
|
||||||
|
- public/javascripts/app/views/content_view.js
|
||||||
- public/javascripts/app/views/*
|
- public/javascripts/app/views/*
|
||||||
|
|
||||||
- public/javascripts/rails.validations.js
|
- public/javascripts/rails.validations.js
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
app.views.Comment = app.views.StreamObject.extend({
|
app.views.Comment = app.views.Content.extend({
|
||||||
|
|
||||||
template_name: "#comment-template",
|
template_name: "#comment-template",
|
||||||
|
|
||||||
|
|
|
||||||
57
public/javascripts/app/views/content_view.js
Normal file
57
public/javascripts/app/views/content_view.js
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
app.views.Content = app.views.StreamObject.extend({
|
||||||
|
presenter : function(){
|
||||||
|
var model = this.model
|
||||||
|
return _.extend(this.defaultPresenter(), {
|
||||||
|
text : metafyText(model.get("text"))
|
||||||
|
})
|
||||||
|
|
||||||
|
function metafyText(text) {
|
||||||
|
//we want it to return at least a <p> from markdown
|
||||||
|
text = text || ""
|
||||||
|
return mentionify(
|
||||||
|
hashtagify(
|
||||||
|
markdownify(text)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function markdownify(text){
|
||||||
|
//markdown returns falsy when it performs no substitutions, apparently...
|
||||||
|
return markdown.toHTML(text) || text
|
||||||
|
}
|
||||||
|
|
||||||
|
function hashtagify(text){
|
||||||
|
var utf8WordCharcters =/(\s|^|>)#([\u0080-\uFFFF|\w|-]+|<3)/g
|
||||||
|
return text.replace(utf8WordCharcters, function(hashtag, preceeder, tagText) {
|
||||||
|
return preceeder + "<a href='/tags/" + tagText + "' class='tag'>#" + tagText + "</a>"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function mentionify(text) {
|
||||||
|
var mentionRegex = /@\{([^;]+); ([^\}]+)\}/g
|
||||||
|
return text.replace(mentionRegex, function(mentionText, fullName, diasporaId) {
|
||||||
|
var personId = _.find(model.get("mentioned_people"), function(person){
|
||||||
|
return person.diaspora_id == diasporaId
|
||||||
|
}).id
|
||||||
|
|
||||||
|
|
||||||
|
return "<a href='/people/" + personId + "' class='mention'>" + fullName + "</a>"
|
||||||
|
})
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
app.views.StatusMessage = app.views.Content.extend({
|
||||||
|
template_name : "#status-message-template"
|
||||||
|
});
|
||||||
|
|
||||||
|
app.views.Reshare = app.views.Content.extend({
|
||||||
|
template_name : "#reshare-template"
|
||||||
|
});
|
||||||
|
|
||||||
|
app.views.ActivityStreams__Photo = app.views.Content.extend({
|
||||||
|
template_name : "#activity-streams-photo-template"
|
||||||
|
});
|
||||||
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
(function(){
|
|
||||||
var postContentView = app.views.StreamObject.extend({
|
|
||||||
presenter : function(){
|
|
||||||
var model = this.model
|
|
||||||
return _.extend(this.defaultPresenter(), {
|
|
||||||
text : metafyText(model.get("text"))
|
|
||||||
})
|
|
||||||
|
|
||||||
function metafyText(text) {
|
|
||||||
//we want it to return at least a <p> from markdown
|
|
||||||
text = text || ""
|
|
||||||
return mentionify(
|
|
||||||
hashtagify(
|
|
||||||
markdownify(text)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function markdownify(text){
|
|
||||||
//markdown returns falsy when it performs no substitutions, apparently...
|
|
||||||
return markdown.toHTML(text) || text
|
|
||||||
}
|
|
||||||
|
|
||||||
function hashtagify(text){
|
|
||||||
var utf8WordCharcters =/(\s|^|>)#([\u0080-\uFFFF|\w|-]+|<3)/g
|
|
||||||
return text.replace(utf8WordCharcters, function(hashtag, preceeder, tagText) {
|
|
||||||
return preceeder + "<a href='/tags/" + tagText + "' class='tag'>#" + tagText + "</a>"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function mentionify(text) {
|
|
||||||
var mentionRegex = /@\{([^;]+); ([^\}]+)\}/g
|
|
||||||
return text.replace(mentionRegex, function(mentionText, fullName, diasporaId) {
|
|
||||||
var personId = _.find(model.get("mentioned_people"), function(person){
|
|
||||||
return person.diaspora_id == diasporaId
|
|
||||||
}).id
|
|
||||||
|
|
||||||
|
|
||||||
return "<a href='/people/" + personId + "' class='mention'>" + fullName + "</a>"
|
|
||||||
})
|
|
||||||
return text
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
app.views.StatusMessage = postContentView.extend({
|
|
||||||
template_name : "#status-message-template"
|
|
||||||
});
|
|
||||||
|
|
||||||
app.views.Reshare = postContentView.extend({
|
|
||||||
template_name : "#reshare-template"
|
|
||||||
});
|
|
||||||
|
|
||||||
app.views.ActivityStreams__Photo = postContentView.extend({
|
|
||||||
template_name : "#activity-streams-photo-template"
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in a new issue