Class: Skyrocket::AssetManager

Inherits:
Object
  • Object
show all
Defined in:
lib/skyrocket/asset_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ AssetManager

Returns a new instance of AssetManager.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/skyrocket/asset_manager.rb', line 7

def initialize(options)
  @asset_dirs = options[:asset_dirs].map{ |ad| File.expand_path(ad) }
  @lib_dirs = options[:lib_dirs].map{ |ld| File.expand_path(ld) }
  @output_dir = File.expand_path(options[:output_dir])
  @base_url = options[:base_url]
  @style = options[:style]
  @af = AssetFactory.new(@asset_dirs, @lib_dirs, @output_dir)
  @aw = AssetWriter.new
  @al = AssetLocator.new(@af)
  Processor.asset_factory = @af
  Processor.base_url = @base_url
end

Instance Attribute Details

#asset_dirsObject (readonly)

Returns the value of attribute asset_dirs.



5
6
7
# File 'lib/skyrocket/asset_manager.rb', line 5

def asset_dirs
  @asset_dirs
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



5
6
7
# File 'lib/skyrocket/asset_manager.rb', line 5

def base_url
  @base_url
end

#lib_dirsObject (readonly)

Returns the value of attribute lib_dirs.



5
6
7
# File 'lib/skyrocket/asset_manager.rb', line 5

def lib_dirs
  @lib_dirs
end

#output_dirObject (readonly)

Returns the value of attribute output_dir.



5
6
7
# File 'lib/skyrocket/asset_manager.rb', line 5

def output_dir
  @output_dir
end

#styleObject (readonly)

Returns the value of attribute style.



5
6
7
# File 'lib/skyrocket/asset_manager.rb', line 5

def style
  @style
end

Instance Method Details

#compile(&block) ⇒ Object



20
21
22
# File 'lib/skyrocket/asset_manager.rb', line 20

def compile(&block)
  update_public(&block)
end

#watch(&block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/skyrocket/asset_manager.rb', line 24

def watch(&block)
  gem 'listen', '>=0.4.2'
  require 'listen'

  begin
    update_public(&block)
  rescue Exception => e
    puts e.message
    puts e.backtrace
  end

  Listen.to(*(@asset_dirs)) do |modified, added, removed|
    begin
      (modified + added).each { |am| process_change(@af.build_asset(am), &block) }
      removed.each do |del|
        as = @af.build_asset(del)
        process_deleted(as.output_path, &block)
      end
    rescue Exception => e
      puts e.message
      puts e.backtrace
    end
  end
end