Skip to content

Commit 502e8d2

Browse files
committed
Merge pull request #4 from pathawks/variable_params
Merge pull request 4
2 parents 9140b2c + f17cfd2 commit 502e8d2

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/jekyll-gist/gist_tag.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ class GistTag < Liquid::Tag
55
def render(context)
66
if tag_contents = determine_arguments(@markup.strip)
77
gist_id, filename = tag_contents[0], tag_contents[1]
8+
if context[gist_id]
9+
gist_id = context[gist_id]
10+
end
11+
if context[filename]
12+
filename = context[filename]
13+
end
814
gist_script_tag(gist_id, filename)
915
else
1016
raise ArgumentError.new <<-eos

spec/gist_tag_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,35 @@
4343
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js\?file=#{filename}">\s<\/script>/)
4444
end
4545
end
46+
47+
context "with variable gist id" do
48+
let(:gist) { "page.gist_id" }
49+
let(:output) do
50+
doc.data['gist_id'] = "1342013"
51+
doc.content = content
52+
doc.output = Jekyll::Renderer.new(doc.site, doc).run
53+
end
54+
55+
it "produces the correct script tag" do
56+
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{doc.data['gist_id']}.js">\s<\/script>/)
57+
end
58+
end
59+
60+
context "with variable gist id and filename" do
61+
let(:gist) { "page.gist_id" }
62+
let(:filename) { "page.gist_filename" }
63+
let(:content) { "{% gist #{gist} #{filename} %}" }
64+
let(:output) do
65+
doc.data['gist_id'] = "1342013"
66+
doc.data['gist_filename'] = "atom.xml"
67+
doc.content = content
68+
doc.output = Jekyll::Renderer.new(doc.site, doc).run
69+
end
70+
71+
it "produces the correct script tag" do
72+
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{doc.data['gist_id']}.js\?file=#{doc.data['gist_filename']}">\s<\/script>/)
73+
end
74+
end
4675
end
4776

4877

0 commit comments

Comments
 (0)