Class: Hyde::Config

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

Overview

Constant Summary collapse

DEFAULTS =
{
  :site_path => '.',
  :layouts_path => '_layouts',
  :extensions_path => '_extensions',
  :partials_path => '_layouts',
  :output_path => '_output',
  :tilt_options => {
    :haml => {
      :escape_html => true
    },
    :sass => {
      :load_paths => ['css', '.'],
      :style => :compact,
      :line_numbers => true
    },
    :scss => {
      :load_paths => ['css', '..'],
      :style => :compact,
      :line_numbers => true
    },
  },
  :tilt_build_options => {
    :scss => {
      :style => :compressed,
      :line_numbers => false
    },
    :sass => {
      :style => :compressed,
      :line_numbers => false
    }
  }
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



61
62
63
64
65
66
67
# File 'lib/hyde/config.rb', line 61

def initialize(options={})
  # Try to emulate proper .merge behavior in Ruby 1.8
  #DEFAULTS.each { |k, v| options[k] ||= v }
  @table = Hashie::Mash.new
  @table.deep_merge! DEFAULTS
  @table.deep_merge! options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object

Passthru



70
71
72
# File 'lib/hyde/config.rb', line 70

def method_missing(meth, *args, &blk)
  @table.send meth, *args
end

Class Method Details

.load(config_file) ⇒ Object



57
58
59
# File 'lib/hyde/config.rb', line 57

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

Instance Method Details

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

Method: tilt_options (Hyde::Config) Returns tilt options for a given engine.

## Usage

tilt_options(engine_name)

## Example

tilt_options('haml')  # { :escape_html => ... }


100
101
102
103
# File 'lib/hyde/config.rb', line 100

def tilt_options(what, key=:tilt_options)
  @table[key] ||= Hash.new
  @table[key][what.to_s] ||= Hash.new
end

#tilt_options_for(file, options = {}) ⇒ Object

Method: tilt_options_for (Hyde::Config) Returns tilt options for a given file.

## Usage

tilt_options_for(filename, options={})

## Example

tilt_options_for('index.haml')  # { :escape_html => ... }


83
84
85
86
87
88
89
# File 'lib/hyde/config.rb', line 83

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))  if options[:build]

  to_hash opts
end