File tree Expand file tree Collapse file tree 1 file changed +38
-2
lines changed Expand file tree Collapse file tree 1 file changed +38
-2
lines changed Original file line number Diff line number Diff line change 11require "jekyll/gist/version"
22
33module Jekyll
4- module Gist
5- # Your code goes here...
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
640 end
741end
42+
43+ Liquid ::Template . register_tag ( 'gist' , Jekyll ::GistTag )
You can’t perform that action at this time.
0 commit comments