Object
`AssetAttributes` is a wrapper similar to `Pathname` that provides some helper accessors.
These methods should be considered internalish.
Returns the content type for the pathname. Falls back to `application/octet-stream`.
# File lib/sprockets/asset_attributes.rb, line 94 def content_type @content_type ||= begin if format_extension.nil? engine_content_type || 'application/octet-stream' else @environment.mime_types(format_extension) || engine_content_type || 'application/octet-stream' end end end
Returns an `Array` of engine extensions.
"foo.js.coffee.erb" # => [".coffee", ".erb"]
# File lib/sprockets/asset_attributes.rb, line 71 def engine_extensions exts = extensions if offset = extensions.index(format_extension) exts = extensions[offset+1..-1] end exts.select { |ext| @environment.engines(ext) } end
Returns engine classes.
# File lib/sprockets/asset_attributes.rb, line 82 def engines engine_extensions.map { |ext| @environment.engines(ext) } end
Returns `Array` of extension `String`s.
"foo.js.coffee" # => [".js", ".coffee"]
# File lib/sprockets/asset_attributes.rb, line 51 def extensions @extensions ||= @pathname.basename.to_s.scan(/\.[^.]+/) end
Returns the format extension.
"foo.js.coffee" # => ".js"
# File lib/sprockets/asset_attributes.rb, line 60 def format_extension extensions.reverse.detect { |ext| @environment.mime_types(ext) && !@environment.engines(ext) } end
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 def logical_path if root_path = environment.paths.detect { |path| pathname.to_s[path] } path = pathname.to_s.sub("#{root_path}/", '') path = pathname.relative_path_from(Pathname.new(root_path)).to_s path = engine_extensions.inject(path) { |p, ext| p.sub(ext, '') } path = "#{path}#{engine_format_extension}" unless format_extension path else raise FileOutsidePaths, "#{pathname} isn't in paths: #{environment.paths.join(', ')}" end end
Returns all processors to run on the path.
# File lib/sprockets/asset_attributes.rb, line 87 def processors environment.preprocessors(content_type) + engines.reverse + environment.postprocessors(content_type) end
Returns paths search the load path for.
# File lib/sprockets/asset_attributes.rb, line 17 def search_paths paths = [pathname.to_s] if pathname.basename(extensions.join).to_s != 'index' path_without_extensions = extensions.inject(pathname) { |p, ext| p.sub(ext, '') } index_path = path_without_extensions.join("index#{extensions.join}").to_s paths << index_path end paths end
Generated with the Darkfish Rdoc Generator 2.