Class: Middleman::Sprockets::ConfigOnlyEnvironment

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-sprockets/config_only_environment.rb

Overview

A fake Sprockets environment that just exposes the waits to create the environment until asked, but can still service most of the interesting configuration methods. This allows sprockets to be configured any time in config.rb, rather than having to use an after_configuration block.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ConfigOnlyEnvironment

Returns a new instance of ConfigOnlyEnvironment.



13
14
15
16
17
# File 'lib/middleman-sprockets/config_only_environment.rb', line 13

def initialize(options={})
  @imported_assets = []
  @appended_paths = []
  @prepended_paths = []
end

Instance Attribute Details

#appended_pathsObject (readonly)

Returns the value of attribute appended_paths.



10
11
12
# File 'lib/middleman-sprockets/config_only_environment.rb', line 10

def appended_paths
  @appended_paths
end

#imported_assetsObject (readonly)

Returns the value of attribute imported_assets.



9
10
11
# File 'lib/middleman-sprockets/config_only_environment.rb', line 9

def imported_assets
  @imported_assets
end

#prepended_pathsObject (readonly)

Returns the value of attribute prepended_paths.



11
12
13
# File 'lib/middleman-sprockets/config_only_environment.rb', line 11

def prepended_paths
  @prepended_paths
end

Instance Method Details

#append_path(path) ⇒ Object



41
42
43
# File 'lib/middleman-sprockets/config_only_environment.rb', line 41

def append_path(path)
  @appended_paths << path
end

#apply_to_environment(environment) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/middleman-sprockets/config_only_environment.rb', line 23

def apply_to_environment(environment)
  @imported_assets.each do |(path, directory)|
    environment.import_asset path, &directory
  end

  @appended_paths.each do |path|
    environment.append_path path
  end

  @prepended_paths.each do |path|
    environment.prepend_path path
  end
end

#import_asset(asset_logical_path, &output_directory) ⇒ Object



37
38
39
# File 'lib/middleman-sprockets/config_only_environment.rb', line 37

def import_asset(asset_logical_path, &output_directory)
  @imported_assets << [asset_logical_path, output_directory]
end

#method_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NoMethodError)


19
20
21
# File 'lib/middleman-sprockets/config_only_environment.rb', line 19

def method_missing?(method)
  raise NoMethodError, "The Sprockets environment is not ready yet, so you can't call #{method} on it. If you need to call this method do it in a 'ready' block."
end

#prepend_path(path) ⇒ Object



45
46
47
# File 'lib/middleman-sprockets/config_only_environment.rb', line 45

def prepend_path(path)
  @prepended_paths << path
end