class Jekyll::Tags::JekyllPug_IncludeTag

Public Class Methods

new(tag_name, markup, tokens) click to toggle source
Calls superclass method
# File lib/jekyll-pug/include-tag.rb, line 6
def initialize(tag_name, markup, tokens)
  super
  matched = markup.strip.match(VARIABLE_SYNTAX)
  if matched
    @file = matched["variable"].strip
    @params = matched["params"].strip
  else
    @file, @params = markup.strip.split(%r!\s+!, 2)
  end
  # If file does not have an extension...
  if @file !~ /\.\w+$/
    # ...add a .pug
    # "navigation" -> "navigation.pug"
    @file = @file + ".pug"
    @isPug = true
  else
    @isPug = false
  end
  validate_params if @params
  @tag_name = tag_name
end

Public Instance Methods

locate_include_file(context, file, safe) click to toggle source
# File lib/jekyll-pug/include-tag.rb, line 38
def locate_include_file(context, file, safe)
  includes_dirs = tag_includes_dirs(context)
  includes_dirs.each do |dir|
    path = File.join(dir.to_s, file.to_s)
    return path if valid_include_file?(path, dir.to_s, safe)
  end
  raise IOError, "Could not locate the included file '#{file}' in any of "\
    "#{includes_dirs}. Ensure it exists in one of those directories and, "\
    "if it is a symlink, does not point outside your site source."
end
render(context) click to toggle source
# File lib/jekyll-pug/include-tag.rb, line 49
def render(context)
  site = context.registers[:site]
  file = render_variable(context) || @file
  validate_file_name(file)

  path = locate_include_file(context, file, site.safe)
  return unless path


  add_include_to_dependency(site, path, context)

  partial = load_cached_partial(path, context)
  context.stack do
    context["include"] = parse_params(context) if @params
    begin
      partial.render!(context)
    rescue Liquid::Error => e
      e.template_name = path
      e.markup_context = "included " if e.markup_context.nil?
      raise e
    end
  end
end
render_variable(context) click to toggle source

Render the variable if required

# File lib/jekyll-pug/include-tag.rb, line 28
def render_variable(context)
  if @file.match(VARIABLE_SYNTAX)
    partial = context.registers[:site]
      .liquid_renderer
      .file("(variable)")
      .parse(@file)
    partial.render!(context)
  end
end