FEATURE: Small improvements to the topic list embed (#12881)
* FEATURE: Small improvements to the topic list embed - Ability to wrap the list in a custom class so you can styles different lists using specific CSS - Adds a topic link to the thumbnail when using the complete template * FIX: Be more strict about allowed chars in class name
This commit is contained in:
parent
15eabb1d97
commit
e2154b3d59
|
@ -34,6 +34,10 @@ class EmbedController < ApplicationController
|
|||
raise Discourse::InvalidParameters.new(:embed_id) unless @embed_id =~ /^de\-[a-zA-Z0-9]+$/
|
||||
end
|
||||
|
||||
if @embed_class = params[:embed_class]
|
||||
raise Discourse::InvalidParameters.new(:embed_class) unless @embed_class =~ /^[a-zA-Z0-9\-_]+$/
|
||||
end
|
||||
|
||||
if params.has_key?(:template) && params[:template] == "complete"
|
||||
@template = "complete"
|
||||
else
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
</button>
|
||||
<%- end %>
|
||||
<%- end %>
|
||||
<div class='topics-list' data-embed-state='loaded' <%- if @embed_id %>data-embed-id="<%= @embed_id %>"<%- end %>>
|
||||
<div class='topics-list <%= @embed_class %>' data-embed-state='loaded' <%- if @embed_id %>data-embed-id="<%= @embed_id %>"<%- end %>>
|
||||
<%- @list.topics.each do |t| %>
|
||||
<div class='topic-list-item'>
|
||||
<%- if @template == "complete" %>
|
||||
|
@ -49,7 +49,9 @@
|
|||
<div class='topic-column featured-image-column'>
|
||||
<%- if t.image_url.present? %>
|
||||
<div class='topic-featured-image'>
|
||||
<a target="_parent" href="<%= t.url %>" class="title raw-link raw-topic-link" data-topic-id="<%= t.id %>">
|
||||
<img src="<%= t.image_url %>">
|
||||
</a>
|
||||
</div>
|
||||
<%- end %>
|
||||
</div>
|
||||
|
|
|
@ -100,7 +100,7 @@ describe EmbedController do
|
|||
expect(response.body).to match("data-referer=\"https://example.com/evil-trout\"")
|
||||
end
|
||||
|
||||
it "returns a list of topics" do
|
||||
it "returns a list of top topics" do
|
||||
bad_topic = Fabricate(:topic)
|
||||
good_topic = Fabricate(:topic, like_count: 1000, posts_count: 100)
|
||||
TopTopic.refresh!
|
||||
|
@ -116,6 +116,16 @@ describe EmbedController do
|
|||
expect(response.body).to match("data-referer=\"https://example.com/evil-trout\"")
|
||||
end
|
||||
|
||||
it "wraps the list in a custom class" do
|
||||
topic = Fabricate(:topic)
|
||||
get '/embed/topics?discourse_embed_id=de-1234&embed_class=my-special-class', headers: {
|
||||
'REFERER' => 'https://example.com/evil-trout'
|
||||
}
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.headers['X-Frame-Options']).to be_nil
|
||||
expect(response.body).to match("class='topics-list my-special-class'")
|
||||
end
|
||||
|
||||
it "returns no referer if not supplied" do
|
||||
get '/embed/topics?discourse_embed_id=de-1234'
|
||||
expect(response.status).to eq(200)
|
||||
|
|
Loading…
Reference in New Issue