diff options
author | Brandon Mathis <brandon@imathis.com> | 2011-07-20 11:02:49 -0400 |
---|---|---|
committer | Brandon Mathis <brandon@imathis.com> | 2011-07-20 11:03:10 -0400 |
commit | c030550917da803e064aaaf00f556f6f11307c46 (patch) | |
tree | b062e8ceb112e051033aa03eeb4fdd78a191fd76 /plugins/include_code.rb | |
parent | ae51fe859e832c90866204c6cda93f85ebef6543 (diff) | |
download | my_new_personal_website-c030550917da803e064aaaf00f556f6f11307c46.tar.xz my_new_personal_website-c030550917da803e064aaaf00f556f6f11307c46.zip |
added optional title to include code tag
Diffstat (limited to 'plugins/include_code.rb')
-rw-r--r-- | plugins/include_code.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/plugins/include_code.rb b/plugins/include_code.rb index 72a74ac7..e00f1c81 100644 --- a/plugins/include_code.rb +++ b/plugins/include_code.rb @@ -18,9 +18,14 @@ require 'pathname' module Jekyll class IncludeCodeTag < Liquid::Tag - def initialize(tag_name, file, tokens) + def initialize(tag_name, markup, tokens) + @title = nil + @file = nil + if markup.strip =~ /(.*)?(\s+|^)(\/*\S+)/i + @title = $1 || nil + @file = $3 + end super - @file = file.strip end def render(context) @@ -39,8 +44,9 @@ module Jekyll Dir.chdir(code_path) do code = file.read file_type = file.extname + title = @title ? "#{@title} (#{file.basename})" : file.basename url = "#{context.registers[:site].config['url']}/#{code_dir}/#{@file}" - source = "<div><figure role=code><figcaption><span>#{file.basename}</span> <a href='#{url}'>download</a></figcaption>\n" + source = "<div><figure role=code><figcaption><span>#{title}</span> <a href='#{url}'>download</a></figcaption>\n" source += "{% highlight #{file_type} %}\n" + code + "\n{% endhighlight %}</figure></div>" partial = Liquid::Template.parse(source) context.stack do |