Create endpoint for liquid tag embed (#3813)
This commit is contained in:
parent
47c2885810
commit
3443fdf2bd
5 changed files with 226 additions and 0 deletions
7
app/controllers/liquid_embeds_controller.rb
Normal file
7
app/controllers/liquid_embeds_controller.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class LiquidEmbedsController < ApplicationController
|
||||
before_action :set_cache_control_headers, only: %i[show]
|
||||
layout false
|
||||
def show
|
||||
set_surrogate_key_header params.to_s
|
||||
end
|
||||
end
|
||||
9
app/views/liquid_embeds/show.html.erb
Normal file
9
app/views/liquid_embeds/show.html.erb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<% cache "liquid_tag_styles_#{ApplicationConfig['DEPLOYMENT_SIGNATURE']}", expires_in: 8.hours do #TODO: Render specific ltag class instead of everything %>
|
||||
<style><%= Rails.application.assets["ltags/LiquidTags.scss"].to_s.html_safe %></style>
|
||||
<% end %>
|
||||
<% begin %>
|
||||
<% @liquid_node = Liquid::Template.parse("{% #{params[:embeddable]} #{params[:args]} %}").root.nodelist.first %>
|
||||
<%= @liquid_node.render("argument") %>
|
||||
<% rescue %>
|
||||
<% raise ActionController::RoutingError, "Not Found" %>
|
||||
<% end %>
|
||||
|
|
@ -318,6 +318,8 @@ Rails.application.routes.draw do
|
|||
get "/rails/mailers/*path" => "rails/mailers#preview"
|
||||
end
|
||||
|
||||
get "/embed/:embeddable" => "liquid_embeds#show"
|
||||
|
||||
get "/new" => "articles#new"
|
||||
get "/new/:template" => "articles#new"
|
||||
|
||||
|
|
|
|||
20
spec/requests/liquid_embeds_spec.rb
Normal file
20
spec/requests/liquid_embeds_spec.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
require "rails_helper"
|
||||
|
||||
vcr_option = {
|
||||
cassette_name: "twitter_gem",
|
||||
allow_playback_repeats: "true"
|
||||
}
|
||||
|
||||
RSpec.describe "LiquidEmbeds", type: :request, vcr: vcr_option do
|
||||
describe "get /embeds" do
|
||||
it "renders proper tweet" do
|
||||
get "/embed/tweet?args=1018911886862057472"
|
||||
expect(response.body).to include("ltag__twitter-tweet")
|
||||
end
|
||||
it "renders 404 if improper tweet" do
|
||||
expect do
|
||||
get "/embed/tweet?args=improper"
|
||||
end.to raise_error(ActionView::Template::Error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,188 @@
|
|||
---
|
||||
http_interactions:
|
||||
- request:
|
||||
method: get
|
||||
uri: https://api.twitter.com/1.1/statuses/show/1018911886862057472.json?tweet_mode=extended
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: ''
|
||||
headers:
|
||||
User-Agent:
|
||||
- TwitterRubyGem/6.2.0
|
||||
Connection:
|
||||
- close
|
||||
response:
|
||||
status:
|
||||
code: 401
|
||||
message: Unauthorized
|
||||
headers:
|
||||
Connection:
|
||||
- close
|
||||
Content-Length:
|
||||
- '62'
|
||||
Content-Type:
|
||||
- application/json; charset=utf-8
|
||||
Date:
|
||||
- Fri, 23 Aug 2019 20:06:12 GMT
|
||||
Server:
|
||||
- tsa_b
|
||||
Strict-Transport-Security:
|
||||
- max-age=631138519
|
||||
X-Connection-Hash:
|
||||
- 666a51edec1438cd31154ecddd54b880
|
||||
X-Response-Time:
|
||||
- '6'
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: '{"errors":[{"code":89,"message":"Invalid or expired token."}]}'
|
||||
http_version:
|
||||
recorded_at: Fri, 23 Aug 2019 20:06:12 GMT
|
||||
- request:
|
||||
method: get
|
||||
uri: https://api.twitter.com/1.1/statuses/show/1018911886862057472.json?tweet_mode=extended
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: ''
|
||||
headers:
|
||||
User-Agent:
|
||||
- TwitterRubyGem/6.2.0
|
||||
Connection:
|
||||
- close
|
||||
response:
|
||||
status:
|
||||
code: 401
|
||||
message: Unauthorized
|
||||
headers:
|
||||
Connection:
|
||||
- close
|
||||
Content-Length:
|
||||
- '62'
|
||||
Content-Type:
|
||||
- application/json; charset=utf-8
|
||||
Date:
|
||||
- Fri, 23 Aug 2019 20:06:13 GMT
|
||||
Server:
|
||||
- tsa_b
|
||||
Strict-Transport-Security:
|
||||
- max-age=631138519
|
||||
X-Connection-Hash:
|
||||
- 91bec65cb6604873963e0a48ee18db53
|
||||
X-Response-Time:
|
||||
- '5'
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: '{"errors":[{"code":89,"message":"Invalid or expired token."}]}'
|
||||
http_version:
|
||||
recorded_at: Fri, 23 Aug 2019 20:06:13 GMT
|
||||
- request:
|
||||
method: get
|
||||
uri: https://api.twitter.com/1.1/statuses/show/1018911886862057472.json?tweet_mode=extended
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: ''
|
||||
headers:
|
||||
User-Agent:
|
||||
- TwitterRubyGem/6.2.0
|
||||
Connection:
|
||||
- close
|
||||
response:
|
||||
status:
|
||||
code: 401
|
||||
message: Unauthorized
|
||||
headers:
|
||||
Connection:
|
||||
- close
|
||||
Content-Length:
|
||||
- '62'
|
||||
Content-Type:
|
||||
- application/json; charset=utf-8
|
||||
Date:
|
||||
- Fri, 23 Aug 2019 20:06:13 GMT
|
||||
Server:
|
||||
- tsa_b
|
||||
Strict-Transport-Security:
|
||||
- max-age=631138519
|
||||
X-Connection-Hash:
|
||||
- e3813b53c3d63444d30cfb448d3c13f7
|
||||
X-Response-Time:
|
||||
- '5'
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: '{"errors":[{"code":89,"message":"Invalid or expired token."}]}'
|
||||
http_version:
|
||||
recorded_at: Fri, 23 Aug 2019 20:06:13 GMT
|
||||
- request:
|
||||
method: get
|
||||
uri: https://api.twitter.com/1.1/statuses/show/1018911886862057472.json?tweet_mode=extended
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: ''
|
||||
headers:
|
||||
User-Agent:
|
||||
- TwitterRubyGem/6.2.0
|
||||
Connection:
|
||||
- close
|
||||
response:
|
||||
status:
|
||||
code: 401
|
||||
message: Unauthorized
|
||||
headers:
|
||||
Connection:
|
||||
- close
|
||||
Content-Length:
|
||||
- '62'
|
||||
Content-Type:
|
||||
- application/json; charset=utf-8
|
||||
Date:
|
||||
- Fri, 23 Aug 2019 20:06:13 GMT
|
||||
Server:
|
||||
- tsa_b
|
||||
Strict-Transport-Security:
|
||||
- max-age=631138519
|
||||
X-Connection-Hash:
|
||||
- 98b85e3a31de3c7c5b1f102e1d1d5406
|
||||
X-Response-Time:
|
||||
- '5'
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: '{"errors":[{"code":89,"message":"Invalid or expired token."}]}'
|
||||
http_version:
|
||||
recorded_at: Fri, 23 Aug 2019 20:06:14 GMT
|
||||
- request:
|
||||
method: get
|
||||
uri: https://api.twitter.com/1.1/statuses/show/1018911886862057472.json?tweet_mode=extended
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: ''
|
||||
headers:
|
||||
User-Agent:
|
||||
- TwitterRubyGem/6.2.0
|
||||
Connection:
|
||||
- close
|
||||
response:
|
||||
status:
|
||||
code: 401
|
||||
message: Unauthorized
|
||||
headers:
|
||||
Connection:
|
||||
- close
|
||||
Content-Length:
|
||||
- '62'
|
||||
Content-Type:
|
||||
- application/json; charset=utf-8
|
||||
Date:
|
||||
- Fri, 23 Aug 2019 20:06:14 GMT
|
||||
Server:
|
||||
- tsa_b
|
||||
Strict-Transport-Security:
|
||||
- max-age=631138519
|
||||
X-Connection-Hash:
|
||||
- 682620a7423aab82a4cba8ec60ed8eff
|
||||
X-Response-Time:
|
||||
- '5'
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: '{"errors":[{"code":89,"message":"Invalid or expired token."}]}'
|
||||
http_version:
|
||||
recorded_at: Fri, 23 Aug 2019 20:06:14 GMT
|
||||
recorded_with: VCR 5.0.0
|
||||
Loading…
Add table
Reference in a new issue