module Rapper::Config
Rapper
configuration and definition methods.
Attributes
Protected Instance Methods
Get the config setting for the given key.
@param [String] key Configuration key.
@return [String,Hash] If the current environment’s config defines this
setting, returns that value. If not, returns the default setting. If the default setting is a hash, returns the default merged with the environment's setting.
# File lib/rapper/config.rb, line 44 def get_config( key ) if default_config[key].is_a?( Hash ) default_config[key].merge( env_config[key] || {} ) else env_config.key?( key ) ? env_config[key] : default_config[key] end end
Load the Rapper
configuration from a YAML file and all asset definition YAML files in the folder specified in the current environment’s definition_root
setting. The definition type is inferred from the file name. E.g. The type key for javascript.yml
will be “javascript”.
@param [String] config_path The path to the configuration YAML file.
# File lib/rapper/config.rb, line 18 def load_config( config_path ) @config = YAML.load_file( config_path ) if env_config.nil? raise Rapper::Errors::InvalidEnvironment, "The '#{@environment}' environment is not defined in #{config_path}" elsif env_config["definition_root"].nil? raise Rapper::Errors::NoDefinitionRoot, "No 'definition_root' has been defined for #{@environment}" end definition_paths = File.join( env_config["definition_root"], "*.yml" ) Dir[definition_paths].each do |definition| type = File.basename( definition, ".yml" ) @definitions[type] = Definition.new( definition ) end end
Update the asset definition files. (Typically done after regenerating versions.)
@param [<String>] types Asset types to update the definition files for.
Defaults to all types (i.e. every type with a definition file in `definition_root`).
# File lib/rapper/config.rb, line 58 def update_definitions( *types ) types = types.empty? ? asset_types : types log :info, "Updating definitions for #{types.join( ', ' )}" types.each do |type| @definitions[type].update end end
Private Instance Methods
@return [Array<String>] All defined asset types.
# File lib/rapper/config.rb, line 88 def asset_types @definitions.keys end
@return [Hash] Default rapper configuration.
# File lib/rapper/config.rb, line 70 def default_config { "bundle" => true, "compress" => true, "tag_style" => "html5", "version" => true, "yui_compressor" => { "line_break" => 2000 } } end
@return [Hash] The configuration for the currently set environment.
# File lib/rapper/config.rb, line 83 def env_config @config[@environment] end