class Rapper::Engine

The main Rapper class. Handles, well, everything.

Public Class Methods

new( config_path, environment ) click to toggle source

Load the configuration YAML file and set the current environment.

@param [String] config_path Path to the configuration YAML file.

@param [String,Symbol] environment The current environment. This must map to an environment configured in the Rapper configuration file.

# File lib/rapper.rb, line 31
def initialize( config_path, environment )
  @environment = environment
  @config = {}
  @definitions = {}
  load_config( config_path )
  setup_helpers
  log :verbose, "Loaded rappper with #{environment} environment from #{config_path}"
end

Public Instance Methods

package( *types ) click to toggle source

Package assets according to the loaded config and definitions. Defaults to packaging all asset types. Skips files that don’t need re-packaging.

@param [<String>] types Asset types to refresh versions for.

# File lib/rapper.rb, line 44
def package( *types )
  types = types.empty? ? asset_types : types
  log :info, "Packaging #{types.join( ', ' )}"
  
  types.each do |type|
    definition = @definitions[type]
    source = File.expand_path( definition.root )
    suffix = definition.suffix
    
    definition.assets.each do |name, spec|
      next unless needs_packaging?( type, name )
      
      source_files = definition.component_paths( name )
      destination_file = definition.asset_path( name )
      
      log :verbose, "Joining #{source_files.size} files to #{destination_file}"
      join_files( source_files, destination_file )
      
      if get_config( "compress" )
        log :verbose, "Compressing #{name}"
        compress( destination_file )
      end
    end
  end
  
  refresh_versions( *types )
  update_definitions( *types )
end