Class: Hyde::Config

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/hyde/config.rb

Constant Summary collapse

DEFAULTS =
{
  :site_path => '.',
  :layouts_path => nil,
  :extensions_path => nil,
  :partials_path => nil,
  :output_path => nil
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



15
16
17
18
19
# File 'lib/hyde/config.rb', line 15

def initialize(options={})
  # Try to emulate proper .merge behavior in Ruby 1.8
  options.each { |k, v| options[k] ||= DEFAULTS[k]  if DEFAULTS.keys.include?(k) }
  super options
end

Class Method Details

.load(config_file) ⇒ Object



11
12
13
# File 'lib/hyde/config.rb', line 11

def self.load(config_file)
  new(YAML::load_file(config_file)) rescue new
end

Instance Method Details

#tilt_options(what, key = :tilt_options) ⇒ Object

Returns tilt options for a given engine.

Examples:

tilt_options(‘haml’) # { :escape_html => … }



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hyde/config.rb', line 32

def tilt_options(what, key=:tilt_options)
  @table[key] ||= begin
    h = Hash.new { |h, k| h[k] = Hash.new }
    h['haml'] = { :escape_html => true }
    h['scss'] = { :load_path => ['css'] }
    h['sass'] = { :load_path => ['css'] }
    h
  end

  @table[key][what.to_s]
end

#tilt_options_for(file, options) ⇒ Object

Returns tilt options for a given file.

Examples:

tilt_options(‘index.haml’) # { :escape_html => … }



23
24
25
26
27
28
# File 'lib/hyde/config.rb', line 23

def tilt_options_for(file, options)
  ext = file.split('.').last.downcase
  opts = tilt_options(ext) || Hash.new
  opts = opts.merge(tilt_options(ext, :tilt_build_options) || Hash.new)  if options[:build]
  opts
end