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.



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

def initialize(options={})
  @imported_assets = []
  @appended_paths = []
  @prepended_paths = []
  @ignored_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

#ignored_pathsObject (readonly)

Returns the value of attribute ignored_paths.



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

def ignored_paths
  @ignored_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



43
44
45
# File 'lib/middleman-sprockets/config_only_environment.rb', line 43

def append_path(path)
  @appended_paths << path
end

#apply_to_environment(environment) ⇒ Object



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

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

#ignore_path(path) ⇒ Object



51
52
53
# File 'lib/middleman-sprockets/config_only_environment.rb', line 51

def ignore_path(path)
  @ignored_paths << path
end

#import_asset(asset_logical_path, &output_directory) ⇒ Object



39
40
41
# File 'lib/middleman-sprockets/config_only_environment.rb', line 39

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

#method_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NoMethodError)


21
22
23
# File 'lib/middleman-sprockets/config_only_environment.rb', line 21

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



47
48
49
# File 'lib/middleman-sprockets/config_only_environment.rb', line 47

def prepend_path(path)
  @prepended_paths << path
end