Class: JekyllData::ThemeDataReader
- Inherits:
-
Jekyll::DataReader
- Object
- Jekyll::DataReader
- JekyllData::ThemeDataReader
- Defined in:
- lib/jekyll-data/theme_data_reader.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
-
#initialize(site) ⇒ ThemeDataReader
constructor
A new instance of ThemeDataReader.
- #read(dir) ⇒ Object
- #read_data_to(dir, data) ⇒ Object
Constructor Details
#initialize(site) ⇒ ThemeDataReader
Returns a new instance of ThemeDataReader.
6 7 8 9 10 |
# File 'lib/jekyll-data/theme_data_reader.rb', line 6 def initialize(site) @site = site @content = {} @entry_filter = Jekyll::EntryFilter.new(site) end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
5 6 7 |
# File 'lib/jekyll-data/theme_data_reader.rb', line 5 def content @content end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
5 6 7 |
# File 'lib/jekyll-data/theme_data_reader.rb', line 5 def site @site end |
Instance Method Details
#read(dir) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/jekyll-data/theme_data_reader.rb', line 12 def read(dir) return unless site.theme && site.theme.data_path base = site.in_theme_dir(dir) read_data_to(base, @content) @content end |
#read_data_to(dir, data) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jekyll-data/theme_data_reader.rb', line 19 def read_data_to(dir, data) return unless File.directory?(dir) && !@entry_filter.symlink?(dir) entries = Dir.chdir(dir) do Dir["*.{yaml,yml,json,csv}"] + Dir["*"].select { |fn| File.directory?(fn) } end entries.each do |entry| path = @site.in_theme_dir(dir, entry) next if @entry_filter.symlink?(path) if File.directory?(path) read_data_to(path, data[sanitize_filename(entry)] = {}) else key = sanitize_filename(File.basename(entry, ".*")) data[key] = read_data_file(path) end end end |