Skip to content

Commit 0f565a0

Browse files
committed
Move the Gist tag into its own file
1 parent b45216c commit 0f565a0

File tree

2 files changed

+47
-39
lines changed

2 files changed

+47
-39
lines changed

lib/jekyll-gist.rb

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,7 @@
1-
require "jekyll/gist/version"
1+
require "jekyll-gist/version"
2+
require "jekyll-gist/gist_tag"
23

34
module Jekyll
4-
class Gist < Liquid::Tag
5-
6-
def render(context)
7-
if tag_contents = determine_arguments(@markup.strip)
8-
gist_id, filename = tag_contents[0], tag_contents[1]
9-
gist_script_tag(gist_id, filename)
10-
else
11-
raise ArgumentError.new <<-eos
12-
Syntax error in tag 'gist' while parsing the following markup:
13-
14-
#{@markup}
15-
16-
Valid syntax:
17-
for all gists: {% gist user/1234567 %}
18-
eos
19-
end
20-
end
21-
22-
private
23-
24-
def determine_arguments(input)
25-
matched = if input.include?("/")
26-
input.match(/\A([a-zA-Z0-9\/\-_]+) ?(\S*)\Z/)
27-
else
28-
input.match(/\A(\d+) ?(\S*)\Z/)
29-
end
30-
[matched[1].strip, matched[2].strip] if matched && matched.length >= 3
31-
end
32-
33-
def gist_script_tag(gist_id, filename = nil)
34-
if filename.empty?
35-
"<script src=\"https://gist.github.com/#{gist_id}.js\"> </script>"
36-
else
37-
"<script src=\"https://gist.github.com/#{gist_id}.js?file=#{filename}\"> </script>"
38-
end
39-
end
5+
module Gist
406
end
417
end
42-
43-
Liquid::Template.register_tag('gist', Jekyll::GistTag)

lib/jekyll-gist/gist_tag.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module Jekyll
2+
module Gist
3+
class GistTag < Liquid::Tag
4+
5+
def render(context)
6+
if tag_contents = determine_arguments(@markup.strip)
7+
gist_id, filename = tag_contents[0], tag_contents[1]
8+
gist_script_tag(gist_id, filename)
9+
else
10+
raise ArgumentError.new <<-eos
11+
Syntax error in tag 'gist' while parsing the following markup:
12+
13+
#{@markup}
14+
15+
Valid syntax:
16+
for all gists: {% gist user/1234567 %}
17+
eos
18+
end
19+
end
20+
21+
private
22+
23+
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
29+
[matched[1].strip, matched[2].strip] if matched && matched.length >= 3
30+
end
31+
32+
def gist_script_tag(gist_id, filename = nil)
33+
if filename.empty?
34+
"<script src=\"https://gist.github.com/#{gist_id}.js\"> </script>"
35+
else
36+
"<script src=\"https://gist.github.com/#{gist_id}.js?file=#{filename}\"> </script>"
37+
end
38+
end
39+
40+
end
41+
end
42+
end
43+
44+
Liquid::Template.register_tag('gist', Jekyll::Gist::GistTag)

0 commit comments

Comments
 (0)