Class: Jekyll::ThemeDataReader
- Inherits:
-
DataReader
- Object
- DataReader
- Jekyll::ThemeDataReader
- Defined in:
- lib/jekyll/readers/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.
4 5 6 7 8 |
# File 'lib/jekyll/readers/theme_data_reader.rb', line 4 def initialize(site) @site = site @content = {} @entry_filter = EntryFilter.new(site) end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
3 4 5 |
# File 'lib/jekyll/readers/theme_data_reader.rb', line 3 def content @content end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
3 4 5 |
# File 'lib/jekyll/readers/theme_data_reader.rb', line 3 def site @site end |
Instance Method Details
#read(dir) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/jekyll/readers/theme_data_reader.rb', line 10 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
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jekyll/readers/theme_data_reader.rb', line 17 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 |