Module: Jekyll::Documents::LayoutRegistrar

Defined in:
lib/jekyll/documents/layout_registrar.rb

Overview

Registers gem-packaged _layouts and _includes with the site so Jekyll can discover them without the gem being declared as a theme.

Jekyll only auto-discovers _layouts and _includes from theme gems (set via the theme: config key). Plugin gems loaded via group :jekyll_plugins do not get their template directories added to Jekyll's lookup paths.

This hook copies any gem-packaged layouts and includes into the site's source directories when the user has not provided their own. Files already present in the site take precedence (user overrides are never clobbered).

Constant Summary collapse

GEM_ROOT =
File.expand_path("../../..", __dir__)
TEMPLATE_DIRS =
%w[_layouts _includes].freeze

Class Method Summary collapse

Class Method Details

.register(site) ⇒ void

This method returns an undefined value.

Copies gem-packaged template files into the site source.

Parameters:

  • site (Jekyll::Site)

    the Jekyll site instance



25
26
27
28
29
30
31
32
# File 'lib/jekyll/documents/layout_registrar.rb', line 25

def register(site)
  TEMPLATE_DIRS.each do |dir|
    gem_dir = File.join(GEM_ROOT, dir)
    next unless Dir.exist?(gem_dir)

    copy_templates(gem_dir, File.join(site.source, dir))
  end
end