Change StackBlitz to utilize ActionController (#2664)

This commit is contained in:
Mac Siri 2019-05-03 14:50:12 -04:00 committed by GitHub
parent b5111a2767
commit d1549220ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 13 deletions

View file

@ -1,4 +1,6 @@
class StackblitzTag < LiquidTagBase
PARTIAL = "liquids/stackblitz".freeze
def initialize(tag_name, id, tokens)
super
@id = parse_id(id)
@ -8,18 +10,15 @@ class StackblitzTag < LiquidTagBase
end
def render(_context)
html = <<-HTML
<iframe
src="https://stackblitz.com/edit/#{@id}?embed=1#{@view}#{@file}"
width="100%"
height="#{@height}"
scrolling="no"
frameborder="no"
allowfullscreen
allowtransparency="true">
</iframe>
HTML
finalize_html(html)
ActionController::Base.new.render_to_string(
partial: PARTIAL,
locals: {
id: @id,
view: @view,
file: @file,
height: @height
},
)
end
private
@ -42,7 +41,7 @@ class StackblitzTag < LiquidTagBase
validated_views = input_split.map { |o| validator.call(o) }.reject(&:nil?)
raise StandardError, "Invalid Options" unless validated_views.length.between?(0, 1)
validated_views.length.zero? ? "" : "&#{validated_views.join('')}"
validated_views.length.zero? ? "" : validated_views.join("").to_s
end
def valid_view?(option)

View file

@ -0,0 +1,9 @@
<iframe
src="https://stackblitz.com/edit/<%= id %>?embed=1&<%= view %>&<%= file %>"
width="100%"
height="<%= height %>"
scrolling="no"
frameborder="no"
allowfullscreen
allowtransparency="true">
</iframe>