Class: Neruda::Config
- Inherits:
-
Object
- Object
- Neruda::Config
- Extended by:
- LispConfig
- Defined in:
- lib/neruda/config.rb
Overview
Wrapper for configuration
This class is a singleton interface, which share the static website being build settings among different steps or tasks.
It expects the website author to holds their custom settings in a YAML file named ~config.yml~ available at the root of their project.
For example, with the given config file:
#+begin_src
title: My website author: Alice Doe #+end_src
Settings will be available like this:
#+begin_src Neruda::Config.settings
> “Alice Doe”
#+end_src
Class Method Summary collapse
-
.load_test(config) ⇒ Hash
Load the given settings as if they comes from the ~config.yml~ file.
-
.save(new_config) ⇒ Hash
Save the settings given as a parameter to the ~config.yml~ file.
-
.settings ⇒ Hash
Access the current website settings.
-
.sources ⇒ Array
Return the qualified projects sources list.
Methods included from LispConfig
org_last_version, write_dir_locals, write_org_lisp_config
Class Method Details
.load_test(config) ⇒ Hash
Load the given settings as if they comes from the ~config.yml~ file.
This method is handy for testing purpose. Later call to settings will use these new settings.
77 78 79 80 |
# File 'lib/neruda/config.rb', line 77 def load_test(config) @sources = nil # Reset sources @config = default_settings.merge config end |
.save(new_config) ⇒ Hash
Save the settings given as a parameter to the ~config.yml~ file.
Not only this method overwrite the old settings, but it replace the current shared settings with the ones given in parameter. Later call to settings will, obviously, use these new settings.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/neruda/config.rb', line 55 def save(new_config) # Do not save obvious default config values. We'll always try to # save author and lang as they default on system variables, # which may be different from a system to another. Thus it may # be confusing if one use neruda on two different computer and # these params always change. new_config.delete_if do |k, v| ['domain', 'public_folder', 'templates', 'theme'].include?(k) \ && v == default_settings[k] end IO.write 'config.yml', new_config.to_yaml load_settings # Reload config, taking default settings into account end |
.settings ⇒ Hash
Access the current website settings
If the settings have not been loaded yet, this method is responsible for calling the one, which actually loads them.
40 41 42 43 |
# File 'lib/neruda/config.rb', line 40 def settings return load_settings unless @config @config end |
.sources ⇒ Array
Return the qualified projects sources list.
85 86 87 88 89 90 91 |
# File 'lib/neruda/config.rb', line 85 def sources return @sources if @sources default_sources = [{ 'path' => 'src', 'target' => '.' }] @sources = (settings['sources'] || default_sources).map do |s| build_source(s) end.compact end |