File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818module Jekyll
1919
2020 class IncludeCodeTag < Liquid ::Tag
21- def initialize ( tag_name , file , tokens )
21+ def initialize ( tag_name , markup , tokens )
22+ @title = nil
23+ @file = nil
24+ if markup . strip =~ /(.*)?(\s +|^)(\/ *\S +)/i
25+ @title = $1 || nil
26+ @file = $3
27+ end
2228 super
23- @file = file . strip
2429 end
2530
2631 def render ( context )
@@ -39,8 +44,9 @@ def render(context)
3944 Dir . chdir ( code_path ) do
4045 code = file . read
4146 file_type = file . extname
47+ title = @title ? "#{ @title } (#{ file . basename } )" : file . basename
4248 url = "#{ context . registers [ :site ] . config [ 'url' ] } /#{ code_dir } /#{ @file } "
43- source = "<div><figure role=code><figcaption><span>#{ file . basename } </span> <a href='#{ url } '>download</a></figcaption>\n "
49+ source = "<div><figure role=code><figcaption><span>#{ title } </span> <a href='#{ url } '>download</a></figcaption>\n "
4450 source += "{% highlight #{ file_type } %}\n " + code + "\n {% endhighlight %}</figure></div>"
4551 partial = Liquid ::Template . parse ( source )
4652 context . stack do
You can’t perform that action at this time.
0 commit comments