Sha256: e0078821219c1a53e210a4af0ad4054396ed2beecd175552eebe8e08b59b837c

Contents?: true

Size: 1013 Bytes

Versions: 16

Compression:

Stored size: 1013 Bytes

Contents

module Jekyll

  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

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

Version data entries

16 entries across 16 versions & 5 rubygems

Version Path
jekyll-0.12.1 lib/jekyll/tags/include.rb
jekyll-reloaded-0.12.2 lib/jekyll/tags/include.rb
jekyll-0.12.0 lib/jekyll/tags/include.rb
spinto-jekyll-0.11.2.5 lib/jekyll/tags/include.rb
jekyll-reloaded-0.12.1 lib/jekyll/tags/include.rb
jekyll-reloaded-0.12 lib/jekyll/tags/include.rb
spinto-jekyll-0.11.2.3 lib/jekyll/tags/include.rb
spinto-jekyll-0.11.2.2 lib/jekyll/tags/include.rb
spinto-jekyll-0.11.2.1 lib/jekyll/tags/include.rb
jekyll-0.11.2 lib/jekyll/tags/include.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/jekyll-0.11.0/lib/jekyll/tags/include.rb
jekyll-0.11.0 lib/jekyll/tags/include.rb
fagiani-jekyll-0.10.1 lib/jekyll/tags/include.rb
jekyll-0.10.0 lib/jekyll/tags/include.rb
jekyll-0.9.0 lib/jekyll/tags/include.rb
jekyll-0.8.0 lib/jekyll/tags/include.rb