aboutsummaryrefslogtreecommitdiff
path: root/themes/classic/_plugins/include_file.rb
blob: 3862228b95087a8a0f5cc6595e4ef3b2779b35f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'pathname'

module Jekyll

  class IncludePartialTag < Liquid::Tag
    def initialize(tag_name, file, tokens)
      super
      @file = file.strip
    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
        partial = Liquid::Template.parse(file.read)
        context.stack do
          partial.render(context)
        end
      end
    end
  end
end

Liquid::Template.register_tag('include_partial', Jekyll::IncludePartialTag)