Class: JekyllData::ThemeConfiguration

Inherits:
Jekyll::Configuration
  • Object
show all
Defined in:
lib/jekyll-data/theme_configuration.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ ThemeConfiguration

Returns a new instance of ThemeConfiguration.



32
33
34
# File 'lib/jekyll-data/theme_configuration.rb', line 32

def initialize(site)
  @site = site
end

Class Method Details

.reconfigure(site) ⇒ Object

Public: Establish a new site.config hash by reading an optional config

file within the theme-gem and appending the resulting hash to
existing site.config filling in keys not already defined.

site: current Jekyll::Site instance.

Returns a config Hash to be used by an ‘after_reset’ hook.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jekyll-data/theme_configuration.rb', line 13

def reconfigure(site)
  default_hash = Jekyll::Configuration::DEFAULTS
  theme_config = ThemeConfiguration.new(site).read_theme_config

  # Merge with existing site.config and strip any remaining defaults
  config = Jekyll::Utils.deep_merge_hashes(
    theme_config, site.config
  ).reject { |key, value| value == default_hash[key] }

  # Merge DEFAULTS < _config.yml in theme-gem < config file(s) from source
  # and redefine site.config
  site.config = Jekyll::Configuration.from(
    Jekyll::Utils.deep_merge_hashes(theme_config, config)
  )
end

Instance Method Details

#read_theme_configObject

Public: Read the ‘_config.yml’ file within the theme-gem.

Additionally validates that the extracted config data and the
the 'value' of '<site.theme.name> key', when present, is a Hash.

Returns a Configuration Hash



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/jekyll-data/theme_configuration.rb', line 41

def read_theme_config
  file = @site.in_theme_dir("_config.yml")
  theme_name = @site.theme.name

  config = safe_load_file(file)

  check_config_is_hash!(config, file)
  validate_config_hash config[theme_name] unless config[theme_name].nil?

  config
end