Class: Sprockets::UnprocessedAsset

Inherits:
AssetWithDependencies show all
Defined in:
lib/sprockets/unprocessed_asset.rb

Instance Attribute Summary

Attributes inherited from AssetWithDependencies

#dependency_digest, #source

Instance Method Summary collapse

Methods inherited from AssetWithDependencies

#encode_with, #fresh?, #init_with

Constructor Details

#initialize(environment, logical_path, pathname) ⇒ UnprocessedAsset

Returns a new instance of UnprocessedAsset.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sprockets/unprocessed_asset.rb', line 3

def initialize(environment, logical_path, pathname)
  super

  @environment = environment
  context = environment.context_class.new(environment, logical_path, pathname)
  attributes = environment.attributes_for(pathname)

  # Remove all engine processors except ERB to return unprocessed source file
  allowed_engines = [Tilt::ERBTemplate]
  processors = attributes.processors - (attributes.engines - allowed_engines)

  @source = context.evaluate(pathname, :processors => processors)

  # If the source contains any '@import' directives, add Sass and Less processors.
  # (@import is quite difficult to handle properly without processing.)
  if @source.include?("@import")
    # Process Sass and Less files, since @import is too tricky to handle properly.
    allowed_engines << Sass::Rails::ScssTemplate if defined?(Sass::Rails::ScssTemplate)
    allowed_engines << Sass::Rails::SassTemplate if defined?(Sass::Rails::SassTemplate)
    allowed_engines << Less::Rails::LessTemplate if defined?(Less::Rails::LessTemplate)
    processors = attributes.processors - (attributes.engines - allowed_engines)
    @source = context.evaluate(pathname, :processors => processors)
  end

  build_required_assets(environment, context,  :process => false)
  build_dependency_paths(environment, context, :process => false)

  @dependency_digest = compute_dependency_digest(environment)
end