Class: Mako::Configuration

Inherits:
Object
  • Object
show all
Includes:
FileOpenUtil
Defined in:
lib/mako/configuration.rb

Constant Summary collapse

DEFAULT_CONFIGURATION =
{ 'source_templates' => File.expand_path('../templates', __dir__),
'destination' => File.expand_path('site/', Dir.pwd),
'theme' => 'simple',
'sanitize_images' => true,
'config_file' => '' }.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FileOpenUtil

included, #load_resource

Constructor Details

#initialize(args) ⇒ Configuration

Returns a new instance of Configuration.



36
37
38
39
40
41
42
# File 'lib/mako/configuration.rb', line 36

def initialize(args)
  @source_templates = args.fetch('source_templates')
  @theme = args.fetch('theme')
  @destination = args.fetch('destination')
  @sanitize_images = args.fetch('sanitize_images')
  @config_file = args.fetch('config_file')
end

Instance Attribute Details

#config_fileObject (readonly)

Returns the value of attribute config_file.



33
34
35
# File 'lib/mako/configuration.rb', line 33

def config_file
  @config_file
end

#destinationObject (readonly)

Returns the value of attribute destination.



33
34
35
# File 'lib/mako/configuration.rb', line 33

def destination
  @destination
end

#sanitize_imagesObject (readonly)

Returns the value of attribute sanitize_images.



33
34
35
# File 'lib/mako/configuration.rb', line 33

def sanitize_images
  @sanitize_images
end

#source_templatesObject (readonly)

Returns the value of attribute source_templates.



33
34
35
# File 'lib/mako/configuration.rb', line 33

def source_templates
  @source_templates
end

#themeObject (readonly)

Returns the value of attribute theme.



33
34
35
# File 'lib/mako/configuration.rb', line 33

def theme
  @theme
end

Class Method Details

.load(file) ⇒ Mako::Configuration

Loads default config file and attempts to merge in any user settings. Creates a new instance of Mako::Configuration.

Parameters:

  • (String)

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mako/configuration.rb', line 20

def self.load(file)
  begin
    user_config_yaml = load_resource(file)
  rescue SystemCallError
    config = DEFAULT_CONFIGURATION
    return new(config)
  end
  user_config = YAML.safe_load(user_config_yaml) || {}
  user_config['config_file'] = file
  config = DEFAULT_CONFIGURATION.merge(user_config)
  new(config)
end