class Jekyll::Tags::OptimizedIncludeTag

Do not inherit from this class. TODO: Merge into the ‘Jekyll::Tags::IncludeTag` in v5.0

Public Instance Methods

render(context) click to toggle source
# File lib/jekyll/tags/include.rb, line 195
def render(context)
  @site ||= context.registers[:site]

  file = render_variable(context) || @file
  validate_file_name(file)

  @site.inclusions[file] ||= locate_include_file(file)
  inclusion = @site.inclusions[file]

  add_include_to_dependency(inclusion, context) if @site.config["incremental"]

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

Private Instance Methods

add_include_to_dependency(inclusion, context) click to toggle source
# File lib/jekyll/tags/include.rb, line 236
def add_include_to_dependency(inclusion, context)
  page = context.registers[:page]
  return unless page&.key?("path")

  absolute_path = \
    if page["collection"]
      @site.in_source_dir(@site.config["collections_dir"], page["path"])
    else
      @site.in_source_dir(page["path"])
    end

  @site.regenerator.add_dependency(absolute_path, inclusion.path)
end
locate_include_file(file) click to toggle source
# File lib/jekyll/tags/include.rb, line 214
def locate_include_file(file)
  @site.includes_load_paths.each do |dir|
    path = PathManager.join(dir, file)
    return Inclusion.new(@site, dir, file) if valid_include_file?(path, dir)
  end
  raise IOError, could_not_locate_message(file, @site.includes_load_paths, @site.safe)
end
outside_scope?(path, dir) click to toggle source
# File lib/jekyll/tags/include.rb, line 226
def outside_scope?(path, dir)
  @site.safe && !realpath_prefixed_with?(path, dir)
end
realpath_prefixed_with?(path, dir) click to toggle source
# File lib/jekyll/tags/include.rb, line 230
def realpath_prefixed_with?(path, dir)
  File.realpath(path).start_with?(dir)
rescue StandardError
  false
end
valid_include_file?(path, dir) click to toggle source
# File lib/jekyll/tags/include.rb, line 222
def valid_include_file?(path, dir)
  File.file?(path) && !outside_scope?(path, dir)
end