Class: Mako::Configuration
- Inherits:
-
Object
- Object
- Mako::Configuration
- Includes:
- FileOpenUtil
- Defined in:
- lib/mako/configuration.rb
Constant Summary collapse
- DEFAULT_CONFIGURATION =
{ 'source_templates' => File.('../templates', __dir__), 'destination' => File.('site/', Dir.pwd), 'theme' => 'simple', 'sanitize_images' => true, 'config_file' => '' }.freeze
Instance Attribute Summary collapse
-
#config_file ⇒ Object
readonly
Returns the value of attribute config_file.
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#sanitize_images ⇒ Object
readonly
Returns the value of attribute sanitize_images.
-
#source_templates ⇒ Object
readonly
Returns the value of attribute source_templates.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
Class Method Summary collapse
-
.load(file) ⇒ Mako::Configuration
Loads default config file and attempts to merge in any user settings.
Instance Method Summary collapse
-
#initialize(args) ⇒ Configuration
constructor
A new instance of Configuration.
Methods included from FileOpenUtil
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_file ⇒ Object (readonly)
Returns the value of attribute config_file.
33 34 35 |
# File 'lib/mako/configuration.rb', line 33 def config_file @config_file end |
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
33 34 35 |
# File 'lib/mako/configuration.rb', line 33 def destination @destination end |
#sanitize_images ⇒ Object (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_templates ⇒ Object (readonly)
Returns the value of attribute source_templates.
33 34 35 |
# File 'lib/mako/configuration.rb', line 33 def source_templates @source_templates end |
#theme ⇒ Object (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.
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 |