Utilize ERB template in GistTag (#2785)
This commit is contained in:
parent
aa68fee630
commit
419ee34866
3 changed files with 13 additions and 8 deletions
|
|
@ -1,16 +1,18 @@
|
|||
class GistTag < LiquidTagBase
|
||||
PARTIAL = "liquids/gist".freeze
|
||||
|
||||
def initialize(tag_name, link, tokens)
|
||||
super
|
||||
@uri = build_uri(link)
|
||||
end
|
||||
|
||||
def render(_context)
|
||||
html = <<~HTML
|
||||
<div class="ltag_gist-liquid-tag">
|
||||
<script id="gist-ltag" src="#{@uri}"></script>
|
||||
</div>
|
||||
HTML
|
||||
finalize_html(html)
|
||||
ActionController::Base.new.render_to_string(
|
||||
partial: PARTIAL,
|
||||
locals: {
|
||||
uri: @uri
|
||||
},
|
||||
)
|
||||
end
|
||||
|
||||
def self.special_script
|
||||
|
|
|
|||
3
app/views/liquids/_gist.html.erb
Normal file
3
app/views/liquids/_gist.html.erb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<div class="ltag_gist-liquid-tag">
|
||||
<script id="gist-ltag" src="<%= uri %>"></script>
|
||||
</div>
|
||||
|
|
@ -40,14 +40,14 @@ RSpec.describe GistTag, type: :liquid_template do
|
|||
it "accepts proper gist url" do
|
||||
gist_links.each do |link|
|
||||
liquid = generate_new_liquid(link)
|
||||
expect(liquid.render.delete(" ")).to eq(generate_script(link))
|
||||
expect(liquid.render.tr("\n", " ").delete(" ")).to eq(generate_script(link))
|
||||
end
|
||||
end
|
||||
|
||||
it "handles 'file' option" do
|
||||
liquid = generate_new_liquid(link_with_file_option)
|
||||
link, option = link_with_file_option.split(" ", 2)
|
||||
expect(liquid.render.delete(" ")).to eq(generate_script(link, option))
|
||||
expect(liquid.render.tr("\n", " ").delete(" ")).to eq(generate_script(link, option))
|
||||
end
|
||||
|
||||
it "rejects invalid gist url" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue