Class: Bridgetown::DefaultsReader

Inherits:
Object
  • Object
show all
Defined in:
bridgetown-core/lib/bridgetown-core/readers/defaults_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ DefaultsReader

Returns a new instance of DefaultsReader.



7
8
9
10
# File 'bridgetown-core/lib/bridgetown-core/readers/defaults_reader.rb', line 7

def initialize(site)
  @site = site
  @path_defaults = HashWithDotAccess::Hash.new
end

Instance Attribute Details

#path_defaultsObject (readonly)

Returns the value of attribute path_defaults.



5
6
7
# File 'bridgetown-core/lib/bridgetown-core/readers/defaults_reader.rb', line 5

def path_defaults
  @path_defaults
end

#siteObject (readonly)

Returns the value of attribute site.



5
6
7
# File 'bridgetown-core/lib/bridgetown-core/readers/defaults_reader.rb', line 5

def site
  @site
end

Instance Method Details

#readObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'bridgetown-core/lib/bridgetown-core/readers/defaults_reader.rb', line 12

def read
  return unless File.directory?(site.source)

  entries = Dir.chdir(site.source) do
    Dir["**/_defaults.{yaml,yml,json}"]
  end

  entries.each do |entry|
    path = @site.in_source_dir(entry)
    @path_defaults[File.dirname(path) + File::SEPARATOR] = YAMLParser.load_file(path)
  end

  @path_defaults
end