lib/sprockets/context.rb in sprockets-3.7.5 vs lib/sprockets/context.rb in sprockets-4.0.0.beta1
- old
+ new
@@ -1,12 +1,10 @@
-require 'pathname'
require 'rack/utils'
require 'set'
require 'sprockets/errors'
module Sprockets
- # Deprecated: `Context` provides helper methods to all processors.
# They are typically accessed by ERB templates. You can mix in custom helpers
# by injecting them into `Environment#context_class`. Do not mix them into
# `Context` directly.
#
# environment.context_class.class_eval do
@@ -17,23 +15,19 @@
# <%= asset_url "foo.png" %>
#
# The `Context` also collects dependencies declared by
# assets. See `DirectiveProcessor` for an example of this.
class Context
- attr_reader :environment, :filename, :pathname
+ attr_reader :environment, :filename
- # Deprecated
- attr_accessor :__LINE__
-
def initialize(input)
@environment = input[:environment]
@metadata = input[:metadata]
@load_path = input[:load_path]
@logical_path = input[:name]
@filename = input[:filename]
@dirname = File.dirname(@filename)
- @pathname = Pathname.new(@filename)
@content_type = input[:content_type]
@required = Set.new(@metadata[:required])
@stubbed = Set.new(@metadata[:stubbed])
@links = Set.new(@metadata[:links])
@@ -77,17 +71,17 @@
# # => "file:///path/to/app/javascripts/foo.js?type=application/javascript"
#
# resolve("./bar.js")
# # => "file:///path/to/app/javascripts/bar.js?type=application/javascript"
#
- # path - String logical or absolute path
- # options
- # accept - String content accept type
+ # path - String logical or absolute path
+ # accept - String content accept type
#
# Returns an Asset URI String.
- def resolve(path, options = {})
- uri, deps = environment.resolve!(path, options.merge(base_path: @dirname))
+ def resolve(path, **kargs)
+ kargs[:base_path] = @dirname
+ uri, deps = environment.resolve!(path, **kargs)
@dependencies.merge(deps)
uri
end
# Public: Load Asset by AssetURI and track it as a dependency.
@@ -106,16 +100,14 @@
#
# This is used for caching purposes. Any changes made to
# the dependency file with invalidate the cache of the
# source file.
def depend_on(path)
- path = path.to_s if path.is_a?(Pathname)
-
if environment.absolute_path?(path) && environment.stat(path)
@dependencies << environment.build_file_digest_uri(path)
else
- resolve(path, compat: false)
+ resolve(path)
end
nil
end
# `depend_on_asset` allows you to state an asset dependency
@@ -124,11 +116,11 @@
# This is used for caching purposes. Any changes that would
# invalidate the dependency asset will invalidate the source
# file. Unlike `depend_on`, this will include recursively include
# the target asset's dependencies.
def depend_on_asset(path)
- load(resolve(path, compat: false))
+ load(resolve(path))
end
# `require_asset` declares `path` as a dependency of the file. The
# dependency will be inserted before the file and will only be
# included once.
@@ -137,18 +129,18 @@
# require assets.
#
# <%= require_asset "#{framework}.js" %>
#
def require_asset(path)
- @required << resolve(path, accept: @content_type, pipeline: :self, compat: false)
+ @required << resolve(path, accept: @content_type, pipeline: :self)
nil
end
# `stub_asset` blacklists `path` from being included in the bundle.
# `path` must be an asset which may or may not already be included
# in the bundle.
def stub_asset(path)
- @stubbed << resolve(path, accept: @content_type, pipeline: :self, compat: false)
+ @stubbed << resolve(path, accept: @content_type, pipeline: :self)
nil
end
# `link_asset` declares an external dependency on an asset without directly
# including it. The target asset is returned from this function making it