Skip to content

Commit

Permalink
Utilize ERB template in GistTag (forem#2785)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocsee authored and maestromac committed May 13, 2019
1 parent aa68fee commit 419ee34
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
14 changes: 8 additions & 6 deletions app/liquid_tags/gist_tag.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/views/liquids/_gist.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="ltag_gist-liquid-tag">
<script id="gist-ltag" src="<%= uri %>"></script>
</div>
4 changes: 2 additions & 2 deletions spec/liquid_tags/gist_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def generate_script(link, option = "")
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
Expand Down

0 comments on commit 419ee34

Please sign in to comment.