Class: Awestruct::Extensions::DataDir

Inherits:
Object
  • Object
show all
Defined in:
lib/awestruct/extensions/data_dir.rb

Instance Method Summary collapse

Constructor Details

#initialize(data_dir = "_data") ⇒ DataDir

Returns a new instance of DataDir.



7
8
9
# File 'lib/awestruct/extensions/data_dir.rb', line 7

def initialize(data_dir="_data")
  @data_dir = data_dir
end

Instance Method Details

#execute(site) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/awestruct/extensions/data_dir.rb', line 15

def execute(site)
  Dir.glob(File.join(site.dir, @data_dir, '*')).each do |entry|
    next unless File.directory? entry
    data_key = File.basename(entry)
    data_map = {}
    Dir.glob(File.join(entry, '*')).each do |chunk|
      File.basename(chunk) =~ /^([^\.]+)/
      key = $1.to_sym
      chunk_page = nil
      if chunk.end_with?('.yml')
        chunk_page = Awestruct.yaml_load_file(chunk)
      else
        chunk_page = site.engine.load_page(chunk)
      end
      data_map[key] = chunk_page
    end
    site.send("#{data_key}=", data_map)
  end
end

#watch(watched_dirs) ⇒ Object



11
12
13
# File 'lib/awestruct/extensions/data_dir.rb', line 11

def watch(watched_dirs)
    watched_dirs << @data_dir
end