Class: Usmu::Configuration
- Inherits:
-
Object
- Object
- Usmu::Configuration
- Includes:
- Helpers::Indexer
- Defined in:
- lib/usmu/configuration.rb
Overview
This class is used to represent a configuration file. This file should be a YAML file and called usmu.yml
by default.
Instance Attribute Summary collapse
-
#config ⇒ void
readonly
private
Returns the value of attribute config.
-
#config_dir ⇒ String
readonly
The folder that the configuration was loaded from.
-
#config_file ⇒ String
readonly
The name of the file used to load the configuration.
-
#destination_path ⇒ String
readonly
The full path to the destination folder.
-
#includes_metadata ⇒ MetadataService
readonly
A metadata service for retrieving metadata about includes.
-
#layouts_files ⇒ Array<String>
readonly
A list of renderable files in the layouts folder.
-
#layouts_path ⇒ String
readonly
The full path to the layouts folder.
-
#log ⇒ void
readonly
private
Returns the value of attribute log.
-
#source_files ⇒ Array<String>
readonly
A list of renderable files in the source folder.
-
#source_metadata ⇒ MetadataService
readonly
A metadata service for retrieving metadata about pages in #source_path.
-
#source_path ⇒ String
readonly
The full path to the source folder.
Class Method Summary collapse
-
.from_file(filename) ⇒ Usmu::Configuration
Load a configuration from a YAML file on disk.
-
.from_hash(hash, config_path = nil) ⇒ Usmu::Configuration
Load a configuration from a hash.
Instance Method Summary collapse
-
#exclude ⇒ Array
Returns an array of exclusions.
-
#excluded?(filename) ⇒ Boolean
private
Helper to determine if a filename is excluded according to the exclude configuration parameter.
- #generator ⇒ Usmu::SiteGenerator
-
#get_files(directory) ⇒ Array<Usmu::Layout>, Array<Usmu::StaticFile>
private
Helper function to search a directory recursively and return a list of files that are renderable.
-
#get_path(path) ⇒ String
private
Helper function to transform a relative path in the configuration file to a relative path from the current working directory.
-
#includes_files ⇒ Array<String>
A list of renderable files in the layouts folder.
-
#includes_path ⇒ String
The full path to the layouts folder.
-
#initialize(hash, config_path) ⇒ Configuration
constructor
private
This class has a private constructor.
- #layouts_metadata ⇒ void
Methods included from Helpers::Indexer
Constructor Details
#initialize(hash, config_path) ⇒ Configuration (private)
This class has a private constructor.
117 118 119 120 121 122 123 124 |
# File 'lib/usmu/configuration.rb', line 117 def initialize(hash, config_path) @log = Logging.logger[self] @config = hash @config_file = config_path @config_dir = if config_path File.dirname(config_path) end end |
Instance Attribute Details
#config ⇒ void (readonly, private)
Returns the value of attribute config.
111 112 113 |
# File 'lib/usmu/configuration.rb', line 111 def config @config end |
#config_dir ⇒ String (readonly)
Returns the folder that the configuration was loaded from.
20 21 22 |
# File 'lib/usmu/configuration.rb', line 20 def config_dir @config_dir end |
#config_file ⇒ String (readonly)
Returns the name of the file used to load the configuration.
17 18 19 |
# File 'lib/usmu/configuration.rb', line 17 def config_file @config_file end |
#destination_path ⇒ String (readonly)
Returns the full path to the destination folder.
58 59 60 |
# File 'lib/usmu/configuration.rb', line 58 def destination_path get_path self['destination'] || 'site' end |
#includes_metadata ⇒ MetadataService (readonly)
Returns a metadata service for retrieving metadata about includes.
92 93 94 |
# File 'lib/usmu/configuration.rb', line 92 def @includes_metadata ||= MetadataService.new(includes_path) end |
#layouts_files ⇒ Array<String> (readonly)
Returns a list of renderable files in the layouts folder.
70 71 72 |
# File 'lib/usmu/configuration.rb', line 70 def layouts_files get_files layouts_path end |
#layouts_path ⇒ String (readonly)
Returns the full path to the layouts folder.
64 65 66 |
# File 'lib/usmu/configuration.rb', line 64 def layouts_path get_path self['layouts'] || 'layouts' end |
#log ⇒ void (readonly, private)
Returns the value of attribute log.
110 111 112 |
# File 'lib/usmu/configuration.rb', line 110 def log @log end |
#source_files ⇒ Array<String> (readonly)
Returns a list of renderable files in the source folder.
46 47 48 |
# File 'lib/usmu/configuration.rb', line 46 def source_files get_files source_path end |
#source_metadata ⇒ MetadataService (readonly)
Returns a metadata service for retrieving metadata about pages in #source_path.
52 53 54 |
# File 'lib/usmu/configuration.rb', line 52 def @source_metadata ||= MetadataService.new(source_path) end |
#source_path ⇒ String (readonly)
Returns the full path to the source folder.
40 41 42 |
# File 'lib/usmu/configuration.rb', line 40 def source_path get_path self['source'] || 'src' end |
Class Method Details
.from_file(filename) ⇒ Usmu::Configuration
Load a configuration from a YAML file on disk.
25 26 27 28 29 |
# File 'lib/usmu/configuration.rb', line 25 def self.from_file(filename) raise ArgumentError, "File not found: #{filename}" if filename.nil? || (not File.exist? filename) @log.debug("Loading configuration from #{filename}") new(YAML.load_file(filename), filename) end |
.from_hash(hash, config_path = nil) ⇒ Usmu::Configuration
Load a configuration from a hash.
34 35 36 |
# File 'lib/usmu/configuration.rb', line 34 def self.from_hash(hash, config_path = nil) new(hash, config_path) end |
Instance Method Details
#exclude ⇒ Array
Returns an array of exclusions
99 100 101 |
# File 'lib/usmu/configuration.rb', line 99 def exclude self['exclude'] || [] end |
#excluded?(filename) ⇒ Boolean (private)
Helper to determine if a filename is excluded according to the exclude configuration parameter.
141 142 143 144 145 146 147 |
# File 'lib/usmu/configuration.rb', line 141 def excluded?(filename) exclude.each do |f| f += '**/*' if f.end_with? '/' return true if File.fnmatch(f, filename, File::FNM_EXTGLOB | File::FNM_PATHNAME) end false end |
#generator ⇒ Usmu::SiteGenerator
104 105 106 |
# File 'lib/usmu/configuration.rb', line 104 def generator SiteGenerator.new(self) end |
#get_files(directory) ⇒ Array<Usmu::Layout>, Array<Usmu::StaticFile> (private)
Helper function to search a directory recursively and return a list of files that are renderable.
153 154 155 156 157 158 159 |
# File 'lib/usmu/configuration.rb', line 153 def get_files(directory) Dir["#{directory}/**/{*,.??*}"]. select {|f| not File.directory? f }. select {|f| !f.match(/[\.\/]meta\.yml$/) }. map {|f| f[directory.length + 1, f.length] }. select {|f| not excluded? f } end |
#get_path(path) ⇒ String (private)
Helper function to transform a relative path in the configuration file to a relative path from the current working directory.
130 131 132 133 134 135 136 |
# File 'lib/usmu/configuration.rb', line 130 def get_path(path) if @config_dir.nil? path else File.join(@config_dir, path) end end |
#includes_files ⇒ Array<String>
Returns a list of renderable files in the layouts folder.
86 87 88 |
# File 'lib/usmu/configuration.rb', line 86 def includes_files get_files includes_path end |
#includes_path ⇒ String
Returns the full path to the layouts folder.
80 81 82 |
# File 'lib/usmu/configuration.rb', line 80 def includes_path get_path self['includes'] || 'includes' end |
#layouts_metadata ⇒ void
74 75 76 |
# File 'lib/usmu/configuration.rb', line 74 def @layouts_metadata ||= MetadataService.new(layouts_path) end |