Class: Jekyll::ThemeReader

Inherits:
Reader
  • Object
show all
Defined in:
lib/jekyll/theme_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ ThemeReader

Returns a new instance of ThemeReader.



6
7
8
9
10
# File 'lib/jekyll/theme_reader.rb', line 6

def initialize(site)
  @site = site
  @theme_data_files = Dir[File.join(@site.theme.root,
    site.config["data_dir"], "**", "*.{yaml,yml,json,csv}")]
end

Instance Method Details

#readObject

Read data files within theme-gem.

Returns nothing.



15
16
17
18
# File 'lib/jekyll/theme_reader.rb', line 15

def read
  super
  read_theme_data
end

#read_theme_configObject

Read the ‘_config.yml’ file if present within the theme gem and return a data hash otherwise return a hash of Jekyll Defaults.

Returns a hash



43
44
45
46
47
48
49
50
# File 'lib/jekyll/theme_reader.rb', line 43

def read_theme_config
  config = @site.in_theme_dir("_config.yml")
  if File.exist?(config)
    Configuration.new.read_config_file(config)
  else
    Configuration::DEFAULTS
  end
end

#read_theme_dataObject

Read data files within a theme gem and add them to internal data

Returns a hash appended with new data



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jekyll/theme_reader.rb', line 23

def read_theme_data
  if site.theme.data_path
    #

    # show contents of "<theme>/_data/" dir being read while degugging.

    # Additionally validate if a data file with the same name as the

    # theme (= theme config or theme config-override) is a Hash.

    inspect_theme_data
    theme_data = ThemeDataReader.new(site).read(site.config["data_dir"])
    @site.data = Utils.deep_merge_hashes(theme_data, @site.data)
    #

    # check if the merged hash is suitable for generating the site.

    # Also show contents of merged site.data hash while debugging.

    inspect_merged_hash
  end
end