Class: Proton::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/proton/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/proton/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/proton/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/proton/config.rb', line 57

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

Instance Method Details

#requirementObject



74
75
76
77
78
# File 'lib/proton/config.rb', line 74

def requirement
  # Backward compatibility; this config option used to be called
  # `hyde_requirement` before the project was renamed to Proton.
  self[:requirement] || self[:hyde_requirement]
end

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

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

## Usage

tilt_options(engine_name)

## Example

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


106
107
108
109
# File 'lib/proton/config.rb', line 106

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 (Proton::Config) Returns tilt options for a given file.

## Usage

tilt_options_for(filename, options={})

## Example

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


89
90
91
92
93
94
95
# File 'lib/proton/config.rb', line 89

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