Sha256: d1ec6c6ac1154fcf134ac3bbc5557bafb9f0533cb84134e9cadca4e9d893d12f

Contents?: true

Size: 856 Bytes

Versions: 67

Compression:

Stored size: 856 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(context.registers[:site].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

67 entries across 67 versions & 26 rubygems

Version Path
Chrononaut-hyde-0.1.0 lib/jekyll/tags/include.rb
Chrononaut-hyde-0.1.1 lib/jekyll/tags/include.rb
PerfectlyNormal-jekyll-0.5.1 lib/jekyll/tags/include.rb
PerfectlyNormal-jekyll-0.5.3 lib/jekyll/tags/include.rb
cduruk-jekyll-0.5.2 lib/jekyll/tags/include.rb
codeslinger-jekyll-0.5.0 lib/jekyll/tags/include.rb
codeslinger-jekyll-0.5.1 lib/jekyll/tags/include.rb
codeslinger-jekyll-0.5.2 lib/jekyll/tags/include.rb
codeslinger-jekyll-0.5.3 lib/jekyll/tags/include.rb
codeslinger-jekyll-0.5.4 lib/jekyll/tags/include.rb
cypher-jekyll-0.5.2 lib/jekyll/tags/include.rb
cypher-jekyll-0.5.3 lib/jekyll/tags/include.rb
henrik-jekyll-0.5.0 lib/jekyll/tags/include.rb
henrik-jekyll-0.5.1 lib/jekyll/tags/include.rb
henrik-jekyll-0.5.2 lib/jekyll/tags/include.rb
jroes-jekyll-0.5.1 lib/jekyll/tags/include.rb
jroes-jekyll-0.5.2 lib/jekyll/tags/include.rb
jroes-jekyll-0.5.3 lib/jekyll/tags/include.rb
jroes-jekyll-0.5.4 lib/jekyll/tags/include.rb
matflores-jekyll-0.5.0 lib/jekyll/tags/include.rb