...
|
...
|
@@ -18,9 +18,14 @@ require 'pathname'
|
18
|
18
|
module Jekyll
|
19
|
19
|
|
20
|
20
|
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
|
22
|
28
|
super
|
23
|
|
- @file = file.strip
|
24
|
29
|
end
|
25
|
30
|
|
26
|
31
|
def render(context)
|
...
|
...
|
@@ -39,8 +44,9 @@ module Jekyll
|
39
|
39
|
Dir.chdir(code_path) do
|
40
|
40
|
code = file.read
|
41
|
41
|
file_type = file.extname
|
|
42
|
+ title = @title ? "#{@title} (#{file.basename})" : file.basename
|
42
|
43
|
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"
|
|
44
|
+ source = "<div><figure role=code><figcaption><span>#{title}</span> <a href='#{url}'>download</a></figcaption>\n"
|
44
|
45
|
source += "{% highlight #{file_type} %}\n" + code + "\n{% endhighlight %}</figure></div>"
|
45
|
46
|
partial = Liquid::Template.parse(source)
|
46
|
47
|
context.stack do
|