Sha256: cc79eef119c4f0653ebdcf2c7900e803493d4718aca23e10189f706ba1821bee

Contents?: true

Size: 852 Bytes

Versions: 22

Compression:

Stored size: 852 Bytes

Contents

module Jekyll
  
  class IncludeTag < Liquid::Tag
    def initialize(tag_name, file, tokens)
      super
      @file = file.strip
    end
    
    def render(context)
      if @file !~ /^[a-zA-Z0-9_\/\.-]+$/ || @file =~ /\.\// || @file =~ /\/\./
        return "Include file '#{@file}' contains invalid characters or sequences"
      end
      
      Dir.chdir(File.join(Jekyll.source, '_includes')) 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

22 entries across 22 versions & 11 rubygems

Version Path
calavera-jekyll-0.4.1 lib/jekyll/tags/include.rb
codeslinger-jekyll-0.3.0 lib/jekyll/tags/include.rb
codeslinger-jekyll-0.4.1 lib/jekyll/tags/include.rb
danski-jekyll-0.4.1 lib/jekyll/tags/include.rb
dysinger-jekyll-0.4.0 lib/jekyll/tags/include.rb
elq-jekyll-0.4.2 lib/jekyll/tags/include.rb
matflores-jekyll-0.4.1.1 lib/jekyll/tags/include.rb
matflores-jekyll-0.4.1 lib/jekyll/tags/include.rb
matflores-jekyll-0.4.2 lib/jekyll/tags/include.rb
matflores-jekyll-0.4.3 lib/jekyll/tags/include.rb
mattmatt-jekyll-0.4.0 lib/jekyll/tags/include.rb
mattmatt-jekyll-0.4.1 lib/jekyll/tags/include.rb
mattmatt-jekyll-0.4.3 lib/jekyll/tags/include.rb
mattmatt-jekyll-0.4.4 lib/jekyll/tags/include.rb
mattmatt-jekyll-0.4.5 lib/jekyll/tags/include.rb
mojombo-jekyll-0.4.0 lib/jekyll/tags/include.rb
mojombo-jekyll-0.4.1 lib/jekyll/tags/include.rb
qrush-jekyll-0.3.0.1 lib/jekyll/tags/include.rb
qrush-jekyll-0.4.0 lib/jekyll/tags/include.rb
qrush-jekyll-0.4.1 lib/jekyll/tags/include.rb