Utilize ERB Template in GlitchTag (#2774) [ci skip]
This commit is contained in:
parent
825bea6e13
commit
d478cc372b
3 changed files with 23 additions and 23 deletions
|
|
@ -2,23 +2,22 @@ require "uri"
|
|||
|
||||
class GlitchTag < LiquidTagBase
|
||||
attr_accessor :uri
|
||||
PARTIAL = "liquids/glitch".freeze
|
||||
|
||||
def initialize(tag_name, id, tokens)
|
||||
super
|
||||
@uri = build_uri(id)
|
||||
@query = parse_options(id)
|
||||
@id = parse_id(id)
|
||||
end
|
||||
|
||||
def render(_context)
|
||||
html = <<-HTML
|
||||
<div class="glitch-embed-wrap" style="height: 450px; width: 100%;margin: 1em auto 1.3em">
|
||||
<iframe
|
||||
sandbox="allow-same-origin allow-scripts allow-forms allow-top-navigation-by-user-activation"
|
||||
src="#{@uri}"
|
||||
alt="#{@id} on glitch"
|
||||
style="height: 100%; width: 100%; border: 0;margin:0;padding:0"></iframe>
|
||||
</div>
|
||||
HTML
|
||||
finalize_html(html)
|
||||
ActionController::Base.new.render_to_string(
|
||||
partial: PARTIAL,
|
||||
locals: {
|
||||
id: @id,
|
||||
query: @query
|
||||
},
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
@ -78,12 +77,6 @@ class GlitchTag < LiquidTagBase
|
|||
|
||||
build_options(options)
|
||||
end
|
||||
|
||||
def build_uri(input)
|
||||
id = parse_id(input)
|
||||
query = parse_options(input)
|
||||
"https://glitch.com/embed/#!/embed/#{id}?#{query}"
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_tag("glitch", GlitchTag)
|
||||
|
|
|
|||
7
app/views/liquids/_glitch.html.erb
Normal file
7
app/views/liquids/_glitch.html.erb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<div class="glitch-embed-wrap" style="height: 450px; width: 100%;margin: 1em auto 1.3em">
|
||||
<iframe
|
||||
sandbox="allow-same-origin allow-scripts allow-forms allow-top-navigation-by-user-activation"
|
||||
src="https://glitch.com/embed/#!/embed/<%= id %>?<%= query %>"
|
||||
alt="<%= id %> on glitch"
|
||||
style="height: 100%; width: 100%; border: 0;margin:0;padding:0"></iframe>
|
||||
</div>
|
||||
|
|
@ -31,31 +31,31 @@ RSpec.describe GlitchTag, type: :liquid_template do
|
|||
|
||||
it "handles 'app' option" do
|
||||
template = generate_tag(id_with_app_option)
|
||||
expected = "src=\"" + base_uri + "some-id?previewSize=100&path=index.html"
|
||||
expected = "src=\"" + base_uri + "some-id?previewSize=100&path=index.html"
|
||||
expect(template.render(nil)).to include(expected)
|
||||
end
|
||||
|
||||
it "handles 'code' option" do
|
||||
template = generate_tag(id_with_code_option)
|
||||
expected = "src=\"" + base_uri + "some-id?previewSize=0&path=index.html"
|
||||
expected = "src=\"" + base_uri + "some-id?previewSize=0&path=index.html"
|
||||
expect(template.render(nil)).to include(expected)
|
||||
end
|
||||
|
||||
it "handles 'no-files' option" do
|
||||
template = generate_tag(id_with_no_files_option)
|
||||
expected = "src=\"" + base_uri + "some-id?sidebarCollapsed=true&path=index.html"
|
||||
expected = "src=\"" + base_uri + "some-id?sidebarCollapsed=true&path=index.html"
|
||||
expect(template.render(nil)).to include(expected)
|
||||
end
|
||||
|
||||
it "handles 'preview-first' option" do
|
||||
template = generate_tag(id_with_preview_first_option)
|
||||
expected = "src=\"" + base_uri + "some-id?previewFirst=true&path=index.html"
|
||||
expected = "src=\"" + base_uri + "some-id?previewFirst=true&path=index.html"
|
||||
expect(template.render(nil)).to include(expected)
|
||||
end
|
||||
|
||||
it "handles 'no-attribution' option" do
|
||||
template = generate_tag(id_with_no_attribution_option)
|
||||
expected = "src=\"" + base_uri + "some-id?attributionHidden=true&path=index.html"
|
||||
expected = "src=\"" + base_uri + "some-id?attributionHidden=true&path=index.html"
|
||||
expect(template.render(nil)).to include(expected)
|
||||
end
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ RSpec.describe GlitchTag, type: :liquid_template do
|
|||
it "handles complex case" do
|
||||
template = generate_tag(id_with_many_options)
|
||||
expected = "src=\"" + base_uri +
|
||||
"some-id?previewSize=100&attributionHidden=true&sidebarCollapsed=true&path=script.js"
|
||||
"some-id?previewSize=100&attributionHidden=true&sidebarCollapsed=true&path=script.js"
|
||||
expect(template.render(nil)).to include(expected)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue