Utilize ERB template in Instagram liquid tag (#2749) [ci skip]
This commit is contained in:
parent
5581fd6ff7
commit
84eb7ceb75
4 changed files with 31 additions and 16 deletions
|
|
@ -1,24 +1,18 @@
|
|||
class InstagramTag < LiquidTagBase
|
||||
PARTIAL = "liquids/instagram".freeze
|
||||
|
||||
def initialize(tag_name, id, tokens)
|
||||
super
|
||||
@id = parse_id(id)
|
||||
end
|
||||
|
||||
def render(_context)
|
||||
html = <<-HTML
|
||||
<div class="instagram-position">
|
||||
<iframe
|
||||
id="instagram-liquid-tag"
|
||||
src="https://www.instagram.com/p/#{@id}/embed/captioned"
|
||||
allowtransparency="true"
|
||||
frameborder="0"
|
||||
data-instgrm-payload-id="instagram-media-payload-0"
|
||||
scrolling="no">
|
||||
</iframe>
|
||||
<script async defer src="https://platform.instagram.com/en_US/embeds.js"></script>
|
||||
</div>
|
||||
HTML
|
||||
finalize_html(html)
|
||||
ActionController::Base.new.render_to_string(
|
||||
partial: PARTIAL,
|
||||
locals: {
|
||||
id: @id
|
||||
},
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
11
app/views/liquids/_instagram.html.erb
Normal file
11
app/views/liquids/_instagram.html.erb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<div class="instagram-position">
|
||||
<iframe
|
||||
id="instagram-liquid-tag"
|
||||
src="https://www.instagram.com/p/<%= id %>/embed/captioned"
|
||||
allowtransparency="true"
|
||||
frameborder="0"
|
||||
data-instgrm-payload-id="instagram-media-payload-0"
|
||||
scrolling="no">
|
||||
</iframe>
|
||||
<script async defer src="https://platform.instagram.com/en_US/embeds.js"></script>
|
||||
</div>
|
||||
|
|
@ -12,8 +12,9 @@ RSpec.describe InstagramTag, type: :liquid_template do
|
|||
|
||||
it "checks that the tag is properly parsed" do
|
||||
valid_id = "BXgGcAUjM39"
|
||||
html = "<div class=\"instagram-position\"> <iframe id=\"instagram-liquid-tag\" src=\"https://www.instagram.com/p/#{valid_id}/embed/captioned\" allowtransparency=\"true\" frameborder=\"0\" data-instgrm-payload-id=\"instagram-media-payload-0\" scrolling=\"no\"> </iframe> <script async defer src=\"https://platform.instagram.com/en_US/embeds.js\"></script> </div>" # rubocop:disable Metrics/LineLength
|
||||
expect(generate_instagram_tag(valid_id).render).to eq(html.chomp("\n"))
|
||||
liquid = generate_instagram_tag(valid_id)
|
||||
rendered_instagram = liquid.render
|
||||
Approvals.verify(rendered_instagram, name: "instagram_liquid_tag", format: :html)
|
||||
end
|
||||
|
||||
it "rejects invalid ids" do
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<body>
|
||||
<div class="instagram-position">
|
||||
<iframe id="instagram-liquid-tag" src="https://www.instagram.com/p/BXgGcAUjM39/embed/captioned" allowtransparency="true" frameborder="0" data-instgrm-payload-id="instagram-media-payload-0" scrolling="no">
|
||||
</iframe>
|
||||
<script async="" defer="defer" src="https://platform.instagram.com/en_US/embeds.js"></script></div>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue