Sha256: b0eb36c67380a20f88d01706ae37d6005068a6818475f30df79ae38160b050e0

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

module Jekyll
  module Tags
    class IncludeTag < Liquid::Tag
      def initialize(tag_name, file, tokens)
        super
        @file = file.strip
      end

      def render(context)
        includes_dir = File.join(context.registers[:site].source, '_includes')

        if File.symlink?(includes_dir)
          return "Includes directory '#{includes_dir}' cannot be a symlink"
        end

        if @file !~ /^[a-zA-Z0-9_\/\.-]+$/ || @file =~ /\.\// || @file =~ /\/\./
          return "Include file '#{@file}' contains invalid characters or sequences"
        end

        Dir.chdir(includes_dir) do
          choices = Dir['**/*'].reject { |x| File.symlink?(x) }
          if choices.include?(@file)
            source = File.read(@file)
            partial = Liquid::Template.parse(source)
            context.stack do
              partial.render(context)
            end
          else
            "Included file '#{@file}' not found in _includes directory"
          end
        end
      end
    end
  end
end

Liquid::Template.register_tag('include', Jekyll::Tags::IncludeTag)

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
jekyll-1.0.4 lib/jekyll/tags/include.rb
jekyll-1.0.3 lib/jekyll/tags/include.rb
jekyll-1.0.2 lib/jekyll/tags/include.rb
jekyll-1.0.1 lib/jekyll/tags/include.rb
jekyll-1.0.0 lib/jekyll/tags/include.rb
jekyll-1.0.0.rc1 lib/jekyll/tags/include.rb
jekyll-1.0.0.beta4 lib/jekyll/tags/include.rb
jekyll-1.0.0.beta3 lib/jekyll/tags/include.rb
jekyll-1.0.0.beta2 lib/jekyll/tags/include.rb
jekyll-1.0.0.beta1 lib/jekyll/tags/include.rb