Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: gh-pages
Fetching contributors…

Cannot retrieve contributors at this time

54 lines (45 sloc) 1.144 kb
# Stolen from Octopress -- but with different usage now.
#
# Example:
#
# {% capture readme %}
# {% relative README.md %}
# {% endcapture %}
# {{ readme | markdownify }
require 'pathname'
module Jekyll
class RenderPartialTag < Liquid::Tag
def initialize(tag_name, markup, tokens)
@file = nil
@raw = false
if markup =~ /^(\S+)\s?(\w+)?/
@file = $1.strip
@raw = $2 == 'raw'
end
super
end
def render(context)
file_dir = (context.registers[:site].source || 'source')
file_path = Pathname.new(file_dir).expand_path
file = file_path + @file
unless file.file?
return "File #{file} could not be found"
end
Dir.chdir(file_path) do
contents = file.read
if contents =~ /\A-{3}.+[^\A]-{3}\n(.+)/m
contents = $1.lstrip
end
if @raw
contents
else
partial = Liquid::Template.parse(contents)
context.stack do
partial.render(context)
end
end
end
end
end
end
Liquid::Template.register_tag('relative', Jekyll::RenderPartialTag)
Jump to Line
Something went wrong with that request. Please try again.