Parent

Files

Class/Module Index [+]

Quicksearch

Jekyll::FrontmatterDefaults

This class handles custom defaults for YAML frontmatter settings. These are set in _config.yml and apply both to internal use (e.g. layout) and the data available to liquid.

It is exposed via the frontmatter_defaults method on the site class.

Public Class Methods

new(site) click to toggle source

Initializes a new instance.

# File lib/jekyll/frontmatter_defaults.rb, line 9
def initialize(site)
  @site = site
end

Public Instance Methods

all(path, type) click to toggle source

Collects a hash with all default values for a page or post

path - the relative path of the page or post type - a symbol indicating the type (:post, :page or :draft)

Returns a hash with all default values (an empty hash if there are none)

# File lib/jekyll/frontmatter_defaults.rb, line 58
def all(path, type)
  defaults = {}
  old_scope = nil
  matching_sets(path, type).each do |set|
    if has_precedence?(old_scope, set['scope'])
      defaults = Utils.deep_merge_hashes(defaults, set['values'])
      old_scope = set['scope']
    else
      defaults = Utils.deep_merge_hashes(set['values'], defaults)
    end
  end
  defaults
end
find(path, type, setting) click to toggle source

Finds a default value for a given setting, filtered by path and type

path - the path (relative to the source) of the page, post or :draft the default is used in type - a symbol indicating whether a :page, a :post or a :draft calls this method

Returns the default value or nil if none was found

# File lib/jekyll/frontmatter_defaults.rb, line 39
def find(path, type, setting)
  value = nil
  old_scope = nil

  matching_sets(path, type).each do |set|
    if set['values'].key?(setting) && has_precedence?(old_scope, set['scope'])
      value = set['values'][setting]
      old_scope = set['scope']
    end
  end
  value
end
update_deprecated_types(set) click to toggle source
# File lib/jekyll/frontmatter_defaults.rb, line 13
def update_deprecated_types(set)
  return set unless set.key?('scope') && set['scope'].key?('type')

  set['scope']['type'] = case set['scope']['type']
  when 'page'
    Deprecator.defaults_deprecate_type('page', 'pages')
    'pages'
  when 'post'
    Deprecator.defaults_deprecate_type('post', 'posts')
    'posts'
  when 'draft'
    Deprecator.defaults_deprecate_type('draft', 'drafts')
    'drafts'
  else
    set['scope']['type']
  end

  set
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.