fix oembed issues in backbone land
This commit is contained in:
parent
203607945b
commit
177f608276
6 changed files with 39 additions and 7 deletions
|
|
@ -5,6 +5,12 @@ class OEmbedCache < ActiveRecord::Base
|
||||||
|
|
||||||
has_many :posts
|
has_many :posts
|
||||||
|
|
||||||
|
# NOTE API V1 to be extracted
|
||||||
|
acts_as_api
|
||||||
|
api_accessible :backbone do |t|
|
||||||
|
t.add :data
|
||||||
|
end
|
||||||
|
|
||||||
def self.find_or_create_by_url(url)
|
def self.find_or_create_by_url(url)
|
||||||
cache = OEmbedCache.find_or_initialize_by_url(url)
|
cache = OEmbedCache.find_or_initialize_by_url(url)
|
||||||
return cache if cache.persisted?
|
return cache if cache.persisted?
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,10 @@ class Reshare < Post
|
||||||
self.root.author.diaspora_handle
|
self.root.author.diaspora_handle
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def o_embed_cache
|
||||||
|
self.root ? root.o_embed_cache : super
|
||||||
|
end
|
||||||
|
|
||||||
def raw_message
|
def raw_message
|
||||||
self.root ? root.raw_message : super
|
self.root ? root.raw_message : super
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,7 @@
|
||||||
|
|
||||||
<%= text %>
|
<%= text %>
|
||||||
|
|
||||||
<% if(o_embed_cache) { %>
|
<%= o_embed_html %>
|
||||||
<%= root.o_embed_cache.posts.data.html %>
|
|
||||||
<% } %>
|
|
||||||
<!-- end duplication -->
|
<!-- end duplication -->
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,4 @@
|
||||||
|
|
||||||
<%= text %>
|
<%= text %>
|
||||||
|
|
||||||
<% if(o_embed_cache) { %>
|
<%= o_embed_html %>
|
||||||
<%= o_embed_cache.posts.data.html %>
|
|
||||||
<% } %>
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ app.views.Content = app.views.StreamObject.extend({
|
||||||
presenter : function(){
|
presenter : function(){
|
||||||
var model = this.model
|
var model = this.model
|
||||||
return _.extend(this.defaultPresenter(), {
|
return _.extend(this.defaultPresenter(), {
|
||||||
text : metafyText(model.get("text"))
|
text : metafyText(model.get("text")),
|
||||||
|
o_embed_html : embedHTML(model)
|
||||||
})
|
})
|
||||||
|
|
||||||
function metafyText(text) {
|
function metafyText(text) {
|
||||||
|
|
@ -48,6 +49,11 @@ app.views.Content = app.views.StreamObject.extend({
|
||||||
return "<a href='" + protocol + url + "' target=_blank>" + url + "</a>"
|
return "<a href='" + protocol + url + "' target=_blank>" + url + "</a>"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function embedHTML(model){
|
||||||
|
if(!model.get("o_embed_cache")) { return ""; }
|
||||||
|
return model.get("o_embed_cache").data.html
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,26 @@ describe("app.views.Post", function(){
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
context("embed_html", function(){
|
||||||
|
it("provides oembed html from the model response", function(){
|
||||||
|
this.statusMessage.set({"o_embed_cache" : {
|
||||||
|
"data" : {
|
||||||
|
"html" : "some html"
|
||||||
|
}
|
||||||
|
}})
|
||||||
|
|
||||||
|
var view = new app.views.Content({model : this.statusMessage});
|
||||||
|
expect(view.presenter().o_embed_html).toContain("some html")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("does not provide oembed html from the model response if none is present", function(){
|
||||||
|
this.statusMessage.set({"o_embed_cache" : null})
|
||||||
|
|
||||||
|
var view = new app.views.Content({model : this.statusMessage});
|
||||||
|
expect(view.presenter().o_embed_html).toBe("");
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
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(){
|
||||||
logout()
|
logout()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue