class Jekyll::Theme

Attributes

name[R]

Public Class Methods

new(name) click to toggle source
# File lib/jekyll/theme.rb, line 10
def initialize(name)
  @name = name.downcase.strip
  Jekyll.logger.debug "Theme:", name
  Jekyll.logger.debug "Theme source:", root
end

Public Instance Methods

assets_path() click to toggle source
# File lib/jekyll/theme.rb, line 42
def assets_path
  @assets_path ||= path_for "assets"
end
basename() click to toggle source

The name of theme directory

# File lib/jekyll/theme.rb, line 26
def basename
  @basename ||= File.basename(root)
end
data_path() click to toggle source
# File lib/jekyll/theme.rb, line 46
def data_path
  @data_path ||= path_for "_data"
end
includes_path() click to toggle source
# File lib/jekyll/theme.rb, line 30
def includes_path
  @includes_path ||= path_for "_includes"
end
layouts_path() click to toggle source
# File lib/jekyll/theme.rb, line 34
def layouts_path
  @layouts_path ||= path_for "_layouts"
end
root() click to toggle source
# File lib/jekyll/theme.rb, line 16
def root
  # Must use File.realpath to resolve symlinks created by rbenv
  # Otherwise, Jekyll.sanitized path with prepend the unresolved root
  @root ||= File.realpath(gemspec.full_gem_path)
rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP
  raise "Path #{gemspec.full_gem_path} does not exist, is not accessible or includes " \
        "a symbolic link loop"
end
runtime_dependencies() click to toggle source
# File lib/jekyll/theme.rb, line 50
def runtime_dependencies
  gemspec.runtime_dependencies
end
sass_path() click to toggle source
# File lib/jekyll/theme.rb, line 38
def sass_path
  @sass_path ||= path_for "_sass"
end

Private Instance Methods

gemspec() click to toggle source
# File lib/jekyll/theme.rb, line 83
def gemspec
  @gemspec ||= Gem::Specification.find_by_name(name)
rescue Gem::LoadError
  raise Jekyll::Errors::MissingDependencyException,
        "The #{name} theme could not be found."
end
log_realpath_exception(err, folder) click to toggle source
# File lib/jekyll/theme.rb, line 72
def log_realpath_exception(err, folder)
  return if err.is_a?(Errno::ENOENT)

  case err
  when Errno::EACCES
    Jekyll.logger.error "Theme error:", "Directory '#{folder}' is not accessible."
  when Errno::ELOOP
    Jekyll.logger.error "Theme error:", "Directory '#{folder}' includes a symbolic link loop."
  end
end
path_for(folder) click to toggle source
# File lib/jekyll/theme.rb, line 56
def path_for(folder)
  path = realpath_for(folder)
  path if path && File.directory?(path)
end
realpath_for(folder) click to toggle source
# File lib/jekyll/theme.rb, line 61
def realpath_for(folder)
  # This resolves all symlinks for the theme subfolder and then ensures that the directory
  # remains inside the theme root. This prevents the use of symlinks for theme subfolders to
  # escape the theme root.
  # However, symlinks are allowed to point to other directories within the theme.
  Jekyll.sanitized_path(root, File.realpath(Jekyll.sanitized_path(root, folder.to_s)))
rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP => e
  log_realpath_exception(e, folder)
  nil
end