Class: JekyllData::Reader

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

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ Reader

Returns a new instance of Reader.



7
8
9
10
11
12
# File 'lib/jekyll-data/reader.rb', line 7

def initialize(site)
  @site = site
  @theme = site.theme
  @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.



17
18
19
20
# File 'lib/jekyll-data/reader.rb', line 17

def read
  super
  read_theme_data
end

#read_theme_dataObject

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

Returns a hash appended with new data



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jekyll-data/reader.rb', line 25

def read_theme_data
  if @theme.data_path
    #
    # show contents of "<theme>/_data/" dir being read while degugging.
    inspect_theme_data
    theme_data = ThemeDataReader.new(site).read(site.config["data_dir"])
    @site.data = Jekyll::Utils.deep_merge_hashes(theme_data, @site.data)
    #
    # show contents of merged site.data hash while debugging with
    # additional --show-data switch.
    inspect_merged_hash if site.config["show-data"] && site.config["verbose"]
  end
end