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 Class Methods

new(environment, logical_path, pathname) click to toggle source
    # File lib/sprockets/bundled_asset.rb, line 13
13:     def initialize(environment, logical_path, pathname)
14:       super(environment, logical_path, pathname)
15: 
16:       @processed_asset = environment.find_asset(pathname, :bundle => false)
17:       @required_assets = @processed_asset.required_assets
18: 
19:       @source = ""
20: 
21:       # Explode Asset into parts and gather the dependency bodies
22:       to_a.each { |dependency| @source << dependency.to_s }
23: 
24:       # Run bundle processors on concatenated source
25:       context = environment.context_class.new(environment, logical_path, pathname)
26:       @source = context.evaluate(pathname, :data => @source,
27:                   :processors => environment.bundle_processors(content_type))
28: 
29:       @mtime  = to_a.map(&:mtime).max
30:       @length = Rack::Utils.bytesize(source)
31:       @digest = environment.digest.update(source).hexdigest
32:     end

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
59:     def body
60:       @processed_asset.source
61:     end
dependencies() click to toggle source

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

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

Serialize custom attributes in `BundledAsset`.

    # File lib/sprockets/bundled_asset.rb, line 49
49:     def encode_with(coder)
50:       super
51: 
52:       coder['source'] = source
53:       coder['required_assets_digest'] = @processed_asset.dependency_digest
54:     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
75:     def fresh?(environment)
76:       @processed_asset.fresh?(environment)
77:     end
init_with(environment, coder) click to toggle source

Initialize `BundledAsset` from serialized `Hash`.

    # File lib/sprockets/bundled_asset.rb, line 35
35:     def init_with(environment, coder)
36:       super
37: 
38:       @processed_asset = environment.find_asset(pathname, :bundle => false)
39:       @required_assets = @processed_asset.required_assets
40: 
41:       if @processed_asset.dependency_digest != coder['required_assets_digest']
42:         raise UnserializeError, "processed asset belongs to a stale environment"
43:       end
44: 
45:       @source = coder['source']
46:     end
to_a() click to toggle source

Expand asset into an `Array` of parts.

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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.