Class: Rabbit::ThemeConfiguration
- Inherits:
-
Object
- Object
- Rabbit::ThemeConfiguration
- Includes:
- GetText, PathManipulatable
- Defined in:
- lib/rabbit/theme-configuration.rb
Constant Summary collapse
- GEM_NAME_PREFIX =
"rabbit-theme"
Constants included from GetText
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#id ⇒ Object
Returns the value of attribute id.
-
#licenses ⇒ Object
Returns the value of attribute licenses.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#tags ⇒ Object
Returns the value of attribute tags.
- #version ⇒ Object
Instance Method Summary collapse
- #gem_name ⇒ Object
-
#initialize(logger = nil) ⇒ ThemeConfiguration
constructor
A new instance of ThemeConfiguration.
- #load ⇒ Object
- #merge!(conf) ⇒ Object
- #path ⇒ Object
- #save(base_dir) ⇒ Object
- #to_hash ⇒ Object
- #to_yaml ⇒ Object
Methods included from GetText
Constructor Details
#initialize(logger = nil) ⇒ ThemeConfiguration
Returns a new instance of ThemeConfiguration.
33 34 35 36 37 38 39 40 |
# File 'lib/rabbit/theme-configuration.rb', line 33 def initialize(logger=nil) @logger = logger || Logger.default @id = nil @tags = [] @version = nil @licenses = [] @author = nil end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
32 33 34 |
# File 'lib/rabbit/theme-configuration.rb', line 32 def @author end |
#id ⇒ Object
Returns the value of attribute id.
30 31 32 |
# File 'lib/rabbit/theme-configuration.rb', line 30 def id @id end |
#licenses ⇒ Object
Returns the value of attribute licenses.
30 31 32 |
# File 'lib/rabbit/theme-configuration.rb', line 30 def licenses @licenses end |
#logger ⇒ Object
Returns the value of attribute logger.
29 30 31 |
# File 'lib/rabbit/theme-configuration.rb', line 29 def logger @logger end |
#tags ⇒ Object
Returns the value of attribute tags.
30 31 32 |
# File 'lib/rabbit/theme-configuration.rb', line 30 def @tags end |
#version ⇒ Object
86 87 88 |
# File 'lib/rabbit/theme-configuration.rb', line 86 def version @version || default_version end |
Instance Method Details
#gem_name ⇒ Object
90 91 92 |
# File 'lib/rabbit/theme-configuration.rb', line 90 def gem_name "#{GEM_NAME_PREFIX}-#{@id}" end |
#load ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/rabbit/theme-configuration.rb', line 42 def load return unless File.exist?(path) conf = YAMLLoader.load(File.read(path)) merge!(conf) rescue format = _("Failed to read slide configuration: %s: %s") @logger.error(format % [path, $!.]) end |
#merge!(conf) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/rabbit/theme-configuration.rb', line 61 def merge!(conf) @id = conf["id"] @tags = conf["tags"] @version = conf["version"] @licenses = conf["licenses"] @author = AuthorConfiguration.new(@logger) @author.merge!(conf["author"] || {}) end |
#path ⇒ Object
94 95 96 |
# File 'lib/rabbit/theme-configuration.rb', line 94 def path "config.yaml" end |
#save(base_dir) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/rabbit/theme-configuration.rb', line 51 def save(base_dir) config_path = File.join(base_dir, path) create_file(config_path) do |conf_file| conf_file.print(to_yaml) end rescue format = _("Failed to write slide configuration: %s: %s") @logger.error(format % [config_path, $!.]) end |
#to_hash ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rabbit/theme-configuration.rb', line 71 def to_hash config = { "id" => @id, "tags" => @tags, "version" => version, "licenses" => @licenses, } config["author"] = @author.to_hash if @author config end |
#to_yaml ⇒ Object
82 83 84 |
# File 'lib/rabbit/theme-configuration.rb', line 82 def to_yaml to_hash.to_yaml end |