Skip to content

Commit 9198f4e

Browse files
committed
Merge pull request #1 from leongersing/allow-gist-only-sha
2 parents 8edfd34 + 1e32926 commit 9198f4e

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

lib/jekyll-gist/gist_tag.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@ def render(context)
1313
#{@markup}
1414
1515
Valid syntax:
16-
for all gists: {% gist user/1234567 %}
16+
{% gist user/1234567 %}
17+
{% gist user/1234567 foo.js %}
18+
{% gist 28949e1d5ee2273f9fd3 %}
19+
{% gist 28949e1d5ee2273f9fd3 best.md %}
1720
eos
1821
end
1922
end
2023

2124
private
2225

2326
def determine_arguments(input)
24-
matched = if input.include?("/")
25-
input.match(/\A([a-zA-Z0-9\/\-_]+) ?(\S*)\Z/)
26-
else
27-
input.match(/\A(\d+) ?(\S*)\Z/)
28-
end
27+
matched = input.match(/\A([\S]+|.*(?=\/).+)\s?(\S*)\Z/)
2928
[matched[1].strip, matched[2].strip] if matched && matched.length >= 3
3029
end
3130

@@ -41,4 +40,4 @@ def gist_script_tag(gist_id, filename = nil)
4140
end
4241
end
4342

44-
Liquid::Template.register_tag('gist', Jekyll::Gist::GistTag)
43+
Liquid::Template.register_tag('gist', Jekyll::Gist::GistTag)

spec/gist_tag_spec.rb

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,26 @@
88
doc.output = Jekyll::Renderer.new(doc.site, doc).run
99
end
1010

11-
context "simple gist" do
12-
let(:gist) { 358471 }
1311

14-
it "produces the correct script tag" do
15-
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
12+
context "valid gist" do
13+
context "with user prefix" do
14+
let(:gist) { "mattr-/24081a1d93d2898ecf0f" }
15+
16+
it "produces the correct script tag" do
17+
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
18+
end
1619
end
17-
end
1820

19-
context "private gist" do
21+
context "without user prefix" do
22+
let(:gist) { "28949e1d5ee2273f9fd3" }
2023

21-
context "when valid" do
22-
let(:gist) { "mattr-/24081a1d93d2898ecf0f" }
24+
it "produces the correct script tag" do
25+
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
26+
end
27+
end
28+
29+
context "classic Gist id style" do
30+
let(:gist) { "1234321" }
2331

2432
it "produces the correct script tag" do
2533
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
@@ -35,9 +43,13 @@
3543
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js\?file=#{filename}">\s<\/script>/)
3644
end
3745
end
46+
end
47+
48+
49+
context "invalid gist" do
3850

39-
context "when invalid" do
40-
let(:gist) { "mattr-24081a1d93d2898ecf0f" }
51+
context "no gist id present" do
52+
let(:gist) { "" }
4153

4254
it "raises an error" do
4355
expect(->{ output }).to raise_error
@@ -46,12 +58,4 @@
4658

4759
end
4860

49-
context "no gist id present" do
50-
let(:gist) { "" }
51-
52-
it "raises an error" do
53-
expect(->{ output }).to raise_error
54-
end
55-
end
56-
5761
end

0 commit comments

Comments
 (0)