Parent

Sprockets::AssetAttributes

`AssetAttributes` is a wrapper similar to `Pathname` that provides some helper accessors.

These methods should be considered internalish.

Attributes

environment[R]
pathname[R]

Public Class Methods

new(environment, path) click to toggle source
    # File lib/sprockets/asset_attributes.rb, line 11
11:     def initialize(environment, path)
12:       @environment = environment
13:       @pathname = path.is_a?(Pathname) ? path : Pathname.new(path.to_s)
14:     end

Public Instance Methods

content_type() click to toggle source

Returns the content type for the pathname. Falls back to `application/octet-stream`.

     # File lib/sprockets/asset_attributes.rb, line 94
 94:     def content_type
 95:       @content_type ||= begin
 96:         if format_extension.nil?
 97:           engine_content_type || 'application/octet-stream'
 98:         else
 99:           @environment.mime_types(format_extension) ||
100:             engine_content_type ||
101:             'application/octet-stream'
102:         end
103:       end
104:     end
engine_extensions() click to toggle source

Returns an `Array` of engine extensions.

    "foo.js.coffee.erb"
    # => [".coffee", ".erb"]
    # File lib/sprockets/asset_attributes.rb, line 71
71:     def engine_extensions
72:       exts = extensions
73: 
74:       if offset = extensions.index(format_extension)
75:         exts = extensions[offset+1..1]
76:       end
77: 
78:       exts.select { |ext| @environment.engines(ext) }
79:     end
engines() click to toggle source

Returns engine classes.

    # File lib/sprockets/asset_attributes.rb, line 82
82:     def engines
83:       engine_extensions.map { |ext| @environment.engines(ext) }
84:     end
extensions() click to toggle source

Returns `Array` of extension `String`s.

    "foo.js.coffee"
    # => [".js", ".coffee"]
    # File lib/sprockets/asset_attributes.rb, line 51
51:     def extensions
52:       @extensions ||= @pathname.basename.to_s.scan(/\.[^.]+/)
53:     end
format_extension() click to toggle source

Returns the format extension.

    "foo.js.coffee"
    # => ".js"
    # File lib/sprockets/asset_attributes.rb, line 60
60:     def format_extension
61:       extensions.reverse.detect { |ext|
62:         @environment.mime_types(ext) && !@environment.engines(ext)
63:       }
64:     end
logical_path() click to toggle source

Reverse guess logical path for fully expanded path.

This has some known issues. For an example if a file is shaddowed in the path, but is required relatively, its logical path will be incorrect.

    # File lib/sprockets/asset_attributes.rb, line 34
34:     def logical_path
35:       if root_path = environment.paths.detect { |path| pathname.to_s[path] }
36:         path = pathname.to_s.sub("#{root_path}/", '')
37:         path = pathname.relative_path_from(Pathname.new(root_path)).to_s
38:         path = engine_extensions.inject(path) { |p, ext| p.sub(ext, '') }
39:         path = "#{path}#{engine_format_extension}" unless format_extension
40:         path
41:       else
42:         raise FileOutsidePaths, "#{pathname} isn't in paths: #{environment.paths.join(', ')}"
43:       end
44:     end
processors() click to toggle source

Returns all processors to run on the path.

    # File lib/sprockets/asset_attributes.rb, line 87
87:     def processors
88:       environment.preprocessors(content_type) +
89:         engines.reverse +
90:         environment.postprocessors(content_type)
91:     end
search_paths() click to toggle source

Returns paths search the load path for.

    # File lib/sprockets/asset_attributes.rb, line 17
17:     def search_paths
18:       paths = [pathname.to_s]
19: 
20:       if pathname.basename(extensions.join).to_s != 'index'
21:         path_without_extensions = extensions.inject(pathname) { |p, ext| p.sub(ext, '') }
22:         index_path = path_without_extensions.join("index#{extensions.join}").to_s
23:         paths << index_path
24:       end
25: 
26:       paths
27:     end

Private Instance Methods

engine_content_type() click to toggle source

Returns implicit engine content type.

`.coffee` files carry an implicit `application/javascript` content type.

     # File lib/sprockets/asset_attributes.rb, line 111
111:       def engine_content_type
112:         engines.reverse.each do |engine|
113:           if engine.respond_to?(:default_mime_type) && engine.default_mime_type
114:             return engine.default_mime_type
115:           end
116:         end
117:         nil
118:       end
engine_format_extension() click to toggle source
     # File lib/sprockets/asset_attributes.rb, line 120
120:       def engine_format_extension
121:         if content_type = engine_content_type
122:           environment.extension_for_mime_type(content_type)
123:         end
124:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.