Sprockets::Environment

Public Class Methods

new(root = ".") click to toggle source

`Environment` should initialized with your application’s root directory. This should be the same as your Rails or Rack root.

    env = Environment.new(Rails.root)
    # File lib/sprockets/environment.rb, line 20
20:     def initialize(root = ".")
21:       @trail = Hike::Trail.new(root)
22: 
23:       self.logger = Logger.new($stderr)
24:       self.logger.level = Logger::FATAL
25: 
26:       if respond_to?(:default_external_encoding)
27:         self.default_external_encoding = Encoding::UTF_8
28:       end
29: 
30:       # Create a safe `Context` subclass to mutate
31:       @context_class = Class.new(Context)
32: 
33:       # Set MD5 as the default digest
34:       require 'digest/md5'
35:       @digest_class = ::Digest::MD5
36:       @version = ''
37: 
38:       @mime_types        = {}
39:       @engines           = Sprockets.engines
40:       @preprocessors     = Hash.new { |h, k| h[k] = [] }
41:       @postprocessors    = Hash.new { |h, k| h[k] = [] }
42:       @bundle_processors = Hash.new { |h, k| h[k] = [] }
43: 
44:       @engines.each do |ext, klass|
45:         add_engine_to_trail(ext, klass)
46:       end
47: 
48:       register_mime_type 'text/css', '.css'
49:       register_mime_type 'application/javascript', '.js'
50: 
51:       register_preprocessor 'text/css', DirectiveProcessor
52:       register_preprocessor 'application/javascript', DirectiveProcessor
53: 
54:       register_postprocessor 'application/javascript', SafetyColons
55:       register_bundle_processor 'text/css', CharsetNormalizer
56: 
57:       expire_index!
58: 
59:       yield self if block_given?
60:     end

Public Instance Methods

find_asset(path, options = {}) click to toggle source

Cache `find_asset` calls

    # File lib/sprockets/environment.rb, line 72
72:     def find_asset(path, options = {})
73:       options[:bundle] = true unless options.key?(:bundle)
74: 
75:       # Ensure inmemory cached assets are still fresh on every lookup
76:       if (asset = @assets[cache_key_for(path, options)]) && asset.fresh?(self)
77:         asset
78:       elsif asset = index.find_asset(path, options)
79:         # Cache is pushed upstream by Index#find_asset
80:         asset
81:       end
82:     end
index() click to toggle source

Returns a cached version of the environment.

All its file system calls are cached which makes `index` much faster. This behavior is ideal in production since the file system only changes between deploys.

    # File lib/sprockets/environment.rb, line 67
67:     def index
68:       Index.new(self)
69:     end

Protected Instance Methods

expire_index!() click to toggle source
    # File lib/sprockets/environment.rb, line 85
85:       def expire_index!
86:         # Clear digest to be recomputed
87:         @digest = nil
88:         @assets = {}
89:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.