class Sprockets::BundledAsset

`BundledAsset`s are used for files that need to be processed and concatenated with other assets. Use for `.js` and `.css` files.

Attributes

source[R]

Public Instance Methods

body() click to toggle source

Get asset’s own processed contents. Excludes any of its required dependencies but does run any processors or engines on the original file.

# File lib/sprockets/bundled_asset.rb, line 59
def body
  @processed_asset.source
end
dependencies() click to toggle source

Return an `Array` of `Asset` files that are declared dependencies.

# File lib/sprockets/bundled_asset.rb, line 64
def dependencies
  to_a.reject { |a| a.eql?(@processed_asset) }
end
encode_with(coder) click to toggle source

Serialize custom attributes in `BundledAsset`.

# File lib/sprockets/bundled_asset.rb, line 49
def encode_with(coder)
  super

  coder['source'] = source
  coder['required_assets_digest'] = @processed_asset.dependency_digest
end
fresh?(environment) click to toggle source

Checks if Asset is stale by comparing the actual mtime and digest to the inmemory model.

# File lib/sprockets/bundled_asset.rb, line 75
def fresh?(environment)
  @processed_asset.fresh?(environment)
end
init_with(environment, coder) click to toggle source

Initialize `BundledAsset` from serialized `Hash`.

# File lib/sprockets/bundled_asset.rb, line 35
def init_with(environment, coder)
  super

  @processed_asset = environment.find_asset(pathname, :bundle => false)
  @required_assets = @processed_asset.required_assets

  if @processed_asset.dependency_digest != coder['required_assets_digest']
    raise UnserializeError, "processed asset belongs to a stale environment"
  end

  @source = coder['source']
end
to_a() click to toggle source

Expand asset into an `Array` of parts.

# File lib/sprockets/bundled_asset.rb, line 69
def to_a
  required_assets
end

Public Class Methods

new(environment, logical_path, pathname) click to toggle source
# File lib/sprockets/bundled_asset.rb, line 13
def initialize(environment, logical_path, pathname)
  super(environment, logical_path, pathname)

  @processed_asset = environment.find_asset(pathname, :bundle => false)
  @required_assets = @processed_asset.required_assets

  @source = ""

  # Explode Asset into parts and gather the dependency bodies
  to_a.each { |dependency| @source << dependency.to_s }

  # Run bundle processors on concatenated source
  context = environment.context_class.new(environment, logical_path, pathname)
  @source = context.evaluate(pathname, :data => @source,
              :processors => environment.bundle_processors(content_type))

  @mtime  = to_a.map(&:mtime).max
  @length = Rack::Utils.bytesize(source)
  @digest = environment.digest.update(source).hexdigest
end