Class: Jekyll::Tags::IncludeTag

### Home Classes Methods

### In Files

- lib/jekyll/tags/include.rb

### Parent

Liquid::Tag

### Methods

- ::new
- #parse_params
- #render
- #validate_file
- #validate_syntax

### Files

- LICENSE

### Class/Module Index

Quicksearch

- Jekyll
- Jekyll::Command
- Jekyll::Commands
- Jekyll::Commands::Build
- Jekyll::Commands::Doctor
- Jekyll::Commands::New
- Jekyll::Commands::Serve
- Jekyll::Configuration
- Jekyll::Converter
- Jekyll::Converters
- Jekyll::Converters::Identity
- Jekyll::Converters::Markdown
- Jekyll::Converters::Markdown::KramdownParser
- Jekyll::Converters::Markdown::MarukuParser
- Jekyll::Converters::Markdown::RDiscountParser
- Jekyll::Converters::Markdown::RedcarpetParser
- Jekyll::Converters::Markdown::RedcarpetParser::CommonMethods
- Jekyll::Converters::Markdown::RedcarpetParser::WithPygments
- Jekyll::Converters::Markdown::RedcarpetParser::WithoutPygments
- Jekyll::Converters::Textile
- Jekyll::Convertible
- Jekyll::Deprecator
- Jekyll::Draft
- Jekyll::Excerpt
- Jekyll::FatalException
- Jekyll::Filters
- Jekyll::Generator
- Jekyll::Generators
- Jekyll::Generators::Pagination
- Jekyll::GistTag
- Jekyll::Layout
- Jekyll::Page
- Jekyll::Pager
- Jekyll::Plugin
- Jekyll::Post
- Jekyll::RelatedPosts
- Jekyll::Site
- Jekyll::Site::Cleaner
- Jekyll::StaticFile
- Jekyll::Stevenson
- Jekyll::Tags
- Jekyll::Tags::HighlightBlock
- Jekyll::Tags::IncludeTag
- Jekyll::Tags::PostComparer
- Jekyll::Tags::PostUrl
- Jekyll::URL
- Date
- Enumerable
- Hash
- Object

No matching classes.

# Jekyll::Tags::IncludeTag

### Constants

MATCHER

### Public Class Methods

new(tag_name, markup, tokens) click to toggle source

    # File lib/jekyll/tags/include.rb, line 7
    def initialize(tag_name, markup, tokens)
      super
      @file, @params = markup.strip.split(' ', 2);
    end

### Public Instance Methods

parse_params(context) click to toggle source

    # File lib/jekyll/tags/include.rb, line 12
    def parse_params(context)
      validate_syntax

      params = {}
      markup = @params

      while match = MATCHER.match(markup) do
        markup = markup[match.end(0)..-1]

        value = if match[2]
          match[2].gsub(/\\"/, '"')
        elsif match[3]
          match[3].gsub(/\\'/, "'")
        elsif match[4]
          context[match[4]]
        end

        params[match[1]] = value
      end
      params
    end

render(context) click to toggle source

    # File lib/jekyll/tags/include.rb, line 51
    def render(context)
      includes_dir = File.join(context.registers[:site].source, '_includes')

      if error = validate_file(includes_dir)
        return error
      end

      source = File.read(File.join(includes_dir, @file))
      partial = Liquid::Template.parse(source)

      context.stack do
        context['include'] = parse_params(context) if @params
        partial.render(context)
      end
    end

validate_file(includes_dir) click to toggle source

    # File lib/jekyll/tags/include.rb, line 67
    def validate_file(includes_dir)
      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

      file = File.join(includes_dir, @file)
      if !File.exists?(file)
        return "Included file #{@file} not found in _includes directory"
      elsif File.symlink?(file)
        return "The included file '_includes/#{@file}' should not be a symlink"
      end
    end

validate_syntax() click to toggle source

ensure the entire markup string from start to end is valid syntax, and params are separated by spaces

    # File lib/jekyll/tags/include.rb, line 35
    def validate_syntax
      full_matcher = Regexp.compile('\A\s*(?:' + MATCHER.to_s + '(?=\s|\z)\s*)*\z')
      unless @params =~ full_matcher
        raise SyntaxError.new Invalid syntax for include tag:        #{@params}Valid syntax:        {% include file.ext param='value' param2="value" %}
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.