Class: Sprockets::Secretary

Inherits:
Object
  • Object
show all
Defined in:
lib/sprockets/secretary.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :root         => ".",
  :load_path    => [],
  :source_files => [],
  :expand_paths => true
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Secretary

Returns a new instance of Secretary.



12
13
14
# File 'lib/sprockets/secretary.rb', line 12

def initialize(options = {})
  reset!(options)
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



10
11
12
# File 'lib/sprockets/secretary.rb', line 10

def environment
  @environment
end

#preprocessorObject (readonly)

Returns the value of attribute preprocessor.



10
11
12
# File 'lib/sprockets/secretary.rb', line 10

def preprocessor
  @preprocessor
end

Instance Method Details

#add_load_location(load_location, options = {}) ⇒ Object



25
26
27
# File 'lib/sprockets/secretary.rb', line 25

def add_load_location(load_location, options = {})
  add_load_locations([load_location], options)
end

#add_load_locations(load_locations, options = {}) ⇒ Object



29
30
31
32
33
# File 'lib/sprockets/secretary.rb', line 29

def add_load_locations(load_locations, options = {})
  expand_paths(load_locations, options).each do |load_location|
    environment.register_load_location(load_location)
  end
end

#add_source_file(source_file, options = {}) ⇒ Object



35
36
37
# File 'lib/sprockets/secretary.rb', line 35

def add_source_file(source_file, options = {})
  add_source_files([source_file], options)
end

#add_source_files(source_files, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/sprockets/secretary.rb', line 39

def add_source_files(source_files, options = {})
  expand_paths(source_files, options).each do |source_file|
    if pathname = environment.find(source_file)
      preprocessor.require(pathname.source_file)
    else
      raise Sprockets::LoadError, "no such file `#{source_file}'"
    end
  end
end

#concatenationObject



49
50
51
# File 'lib/sprockets/secretary.rb', line 49

def concatenation
  preprocessor.concatenation
end

#install_assetsObject



53
54
55
56
57
58
59
# File 'lib/sprockets/secretary.rb', line 53

def install_assets
  if @options[:asset_root]
    preprocessor.asset_paths.each do |asset_path|
      copy_assets_from(asset_path.absolute_location)
    end
  end
end

#reset!(options = @options) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/sprockets/secretary.rb', line 16

def reset!(options = @options)
  @options = DEFAULT_OPTIONS.merge(options)
  @environment  = Sprockets::Environment.new(@options[:root])
  @preprocessor = Sprockets::Preprocessor.new(@environment)

  add_load_locations(@options[:load_path])
  add_source_files(@options[:source_files])
end

#source_last_modifiedObject



61
62
63
# File 'lib/sprockets/secretary.rb', line 61

def source_last_modified
  preprocessor.source_files.map { |s| s.mtime }.max
end