Move work from template to controller (#16092)
* Move work from template to controller * Render only the final result with the template
This commit is contained in:
parent
46d40b2f54
commit
dd8aeee58e
3 changed files with 14 additions and 7 deletions
|
|
@ -5,6 +5,17 @@ class LiquidEmbedsController < ApplicationController
|
|||
|
||||
def show
|
||||
set_surrogate_key_header params.to_s
|
||||
|
||||
begin
|
||||
@rendered_node = Liquid::Template
|
||||
.parse("{% #{params[:embeddable]} #{params[:args]} %}")
|
||||
.root
|
||||
.nodelist
|
||||
.first
|
||||
.render({})
|
||||
rescue StandardError
|
||||
raise ActionController::RoutingError, "Not Found"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -2,11 +2,7 @@
|
|||
<% cache "liquid_tag_styles_#{ForemInstance.deployed_at}", expires_in: 8.hours do #TODO: Render specific ltag class instead of everything %>
|
||||
<style><%= Rails.application.assets["ltags/LiquidTags.css"].to_s.html_safe %></style>
|
||||
<% end %>
|
||||
<% begin %>
|
||||
<% @liquid_node = Liquid::Template.parse("{% #{params[:embeddable]} #{params[:args]} %}").root.nodelist.first %>
|
||||
<%= @liquid_node.render({}) %>
|
||||
<% rescue %>
|
||||
<% raise ActionController::RoutingError, "Not Found" %>
|
||||
<% end %>
|
||||
|
||||
<%= @rendered_node %>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.1.1/iframeResizer.contentWindow.min.js" integrity="sha384-G6tHzK74z1pvDJPpiekQQg/Ad3+gDzJkLvIheIjfKjYVFG7Wpsot40rOJkXT92B2" crossorigin="anonymous" defer="defer"></script>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ RSpec.describe "LiquidEmbeds", type: :request, vcr: { cassette_name: "twitter_cl
|
|||
it "renders 404 if improper tweet" do
|
||||
expect do
|
||||
get liquid_embed_path("tweet", args: "improper")
|
||||
end.to raise_error(ActionView::Template::Error)
|
||||
end.to raise_error(ActionController::RoutingError)
|
||||
end
|
||||
|
||||
it "contains base target parent" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue