Class: RapperLite::Engine

Inherits:
Object
  • Object
show all
Includes:
Build, Compressors, Config, Utils, Versioning
Defined in:
lib/rapper_lite.rb,
lib/rapper_lite/watch_support.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Versioning

#needs_packaging?

Methods included from Config

#compress?, #destination, #destination_path, #file_paths, #root, #yui_config

Methods included from Compressors

#compress

Methods included from Build

#build_package

Constructor Details

#initialize(config_path) ⇒ Engine

Returns a new instance of Engine.



23
24
25
# File 'lib/rapper_lite.rb', line 23

def initialize( config_path )
  self.load_config( config_path )
end

Class Method Details

.find_config_pathObject



27
28
29
30
31
32
33
34
35
# File 'lib/rapper_lite.rb', line 27

def self.find_config_path
  ["./", "config/"].each do |folder|
    ["rapper.yml", "assets.yml"].each do |file|
      path = File.expand_path( file, folder )
      return path if File.exists?( path )
    end
  end
  raise "No config file found."
end

Instance Method Details

#all_component_pathsObject

All absolute file paths for the component files



40
41
42
43
44
45
46
47
48
# File 'lib/rapper_lite/watch_support.rb', line 40

def all_component_paths
  [:css, :js].map do |type|
    (@definitions[type].keys - self.config_keys).map do |name|
      self.file_paths( type, name )
    end
  end.flatten.uniq.map do |path|
    File.expand_path( path )
  end
end

#common_rootObject

LCD for JS and CSS roots



28
29
30
31
32
33
34
35
36
37
# File 'lib/rapper_lite/watch_support.rb', line 28

def common_root
  js_path = File.expand_path( self.root( :js ) ).split( "/" )
  css_path = File.expand_path( self.root( :css ) ).split( "/" )
  path = []
  while js_component = js_path.shift && css_component = css_path.shift
    break if js_component != css_component
    path << js_component
  end
  path.join( "/" )
end

#noisy_packageObject



21
22
23
24
25
# File 'lib/rapper_lite/watch_support.rb', line 21

def noisy_package
  print( "Compiling static assets..." ) && STDOUT.flush
  self.package
  puts " Done!"
end

#packageObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rapper_lite.rb', line 37

def package
  [:js, :css].each do |type|
    definition = @definitions[type]
    source = File.expand_path( self.root( type ) )
    
    definition.each do |name, spec|
      next if self.config_key?( name ) # Skip config settings
      next unless self.needs_packaging?( type, name )
      self.build_package( type, name )
    end
  end
  
  self.refresh_versions
  self.save_config
end

#watchObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rapper_lite/watch_support.rb', line 4

def watch
  rapper = self
  rapper.noisy_package
  FSSM.monitor( rapper.common_root, '**/*.{css,js,coffee,sass}' ) do
    begin
      component_files = rapper.all_component_paths
      update do |base, relative|
        if component_files.include?( File.join( base, relative) )
          rapper.noisy_package
        end
      end
    rescue FSSM::CallbackError
      # no-op
    end
  end
end