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.



5
6
7
# File 'lib/awestruct/extensions/data_dir.rb', line 5

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

Instance Method Details

#execute(site) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/awestruct/extensions/data_dir.rb', line 13

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

#watch(watched_dirs) ⇒ Object



9
10
11
# File 'lib/awestruct/extensions/data_dir.rb', line 9

def watch(watched_dirs)
    watched_dirs << @data_dir
end