Class: Rapper::Engine

Inherits:
Object
  • Object
show all
Includes:
Compressors, Config, HelperSetup, HtmlTags, Logging, Utils, Versioning
Defined in:
lib/rapper.rb

Overview

The main Rapper class. Handles, well, everything.

Instance Attribute Summary

Attributes included from Config

#config, #definitions, #environment

Instance Method Summary collapse

Methods included from HelperSetup

#setup_helpers

Methods included from HtmlTags

#css_tag, #js_tag, #tag_method_for_type, #tag_paths

Methods included from Compressors

#compress

Constructor Details

#initialize(config_path, environment) ⇒ Engine

Load the configuration YAML file and set the current environment.

to an environment configured in the Rapper configuration file.

Parameters:

  • config_path (String)

    Path to the configuration YAML file.

  • environment (String, Symbol)

    The current environment. This must map



31
32
33
34
35
36
37
38
# 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

Instance Method Details

#package(*types) ⇒ Object

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

Parameters:

  • types (<String>)

    Asset types to refresh versions for.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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