Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/jekyll-gist/gist_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Jekyll
module Gist
class GistTag < Liquid::Tag
def render(context)
@special_characters = "#"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this an instance variable??

@encoding = context.registers[:site].config["encoding"] || "utf-8"
@settings = context.registers[:site].config["gist"]
if (tag_contents = determine_arguments(@markup.strip))
Expand All @@ -22,6 +23,7 @@ def render(context)
if context_contains_key?(context, filename)
filename = context[filename]
end
filename.delete!(@special_characters)
noscript_tag = gist_noscript_tag(gist_id, filename)
script_tag = gist_script_tag(gist_id, filename)
"#{noscript_tag}#{script_tag}"
Expand Down
12 changes: 10 additions & 2 deletions spec/gist_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,25 @@
end

context "with file specified" do
before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw/#{filename}").to_return(:body => http_output) }
before { stub_request(:get, %r!https://gist.githubusercontent.com/#{gist}/raw/.*!).to_return(:body => http_output) }
let(:gist) { "mattr-/24081a1d93d2898ecf0f" }
let(:filename) { "myfile.ext" }
let(:content) { "{% gist #{gist} #{filename} %}" }

it "produces the correct script tag" do
expect(output).to match(%r!<script src="https:\/\/gist.github.com\/#{gist}.js\?file=#{filename}">\s<\/script>!)
expect(output).to match(%r!<script src="https://gist.github.com/#{gist}.js\?file=#{filename}">\s<\/script>!)
end
it "produces the correct noscript tag" do
expect(output).to match(%r!<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n!)
end

context "with octothorpe in filename" do
let(:filename) { "my#file" }

it "removes special characters from the filename" do
expect(output).to match(%r!<script src="https://gist.github.com/#{gist}.js\?file=myfile">\s</script>!)
end
end
end

context "with variable gist id" do
Expand Down