Module: Deris::PartialHasher

Included in:
Directory, Project
Defined in:
lib/partial_hasher.rb

Instance Method Summary collapse

Instance Method Details

#partials_hashObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/partial_hasher.rb', line 5

def partials_hash
  unless respond_to?(:directory)
    raise 'need to response to  "directory" to create a hash of partials' 
  end
  
  partials = {}
  partial_file_mask = ::File.join(directory, '*.haml')
  partial_files = ::Dir.glob(partial_file_mask)
  
  partial_files.each do |file|
    file_sym = ::File.basename(file, '.haml').to_sym
    partials[file_sym] = ::File.new(file).read      
  end

  # apply the convention where a partial with the same name as the file
  # being output is set as the content partial unless it already exists
  if !partials[:content] and partials[@file_name.to_sym]
    partials[:content] = partials[@file_name.to_sym]
  end
        
  partials      
end