sprockets 3.0.0.beta.6 → 3.0.0.beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +171 -100
  3. data/lib/rake/sprocketstask.rb +2 -2
  4. data/lib/sprockets.rb +69 -63
  5. data/lib/sprockets/asset.rb +2 -61
  6. data/lib/sprockets/autoload_processor.rb +48 -0
  7. data/lib/sprockets/base.rb +4 -6
  8. data/lib/sprockets/bower.rb +8 -5
  9. data/lib/sprockets/bundle.rb +9 -13
  10. data/lib/sprockets/cache.rb +19 -14
  11. data/lib/sprockets/cache/file_store.rb +2 -1
  12. data/lib/sprockets/cached_environment.rb +15 -68
  13. data/lib/sprockets/closure_compressor.rb +17 -4
  14. data/lib/sprockets/coffee_script_processor.rb +26 -0
  15. data/lib/sprockets/coffee_script_template.rb +3 -20
  16. data/lib/sprockets/compressing.rb +10 -4
  17. data/lib/sprockets/configuration.rb +21 -37
  18. data/lib/sprockets/context.rb +37 -67
  19. data/lib/sprockets/dependencies.rb +73 -0
  20. data/lib/sprockets/digest_utils.rb +8 -2
  21. data/lib/sprockets/directive_processor.rb +122 -165
  22. data/lib/sprockets/eco_processor.rb +32 -0
  23. data/lib/sprockets/eco_template.rb +3 -26
  24. data/lib/sprockets/ejs_processor.rb +31 -0
  25. data/lib/sprockets/ejs_template.rb +3 -25
  26. data/lib/sprockets/encoding_utils.rb +9 -21
  27. data/lib/sprockets/engines.rb +25 -27
  28. data/lib/sprockets/environment.rb +9 -1
  29. data/lib/sprockets/erb_processor.rb +30 -0
  30. data/lib/sprockets/erb_template.rb +3 -20
  31. data/lib/sprockets/file_reader.rb +15 -0
  32. data/lib/sprockets/http_utils.rb +2 -0
  33. data/lib/sprockets/jst_processor.rb +9 -2
  34. data/lib/sprockets/legacy.rb +212 -3
  35. data/lib/sprockets/legacy_tilt_processor.rb +1 -1
  36. data/lib/sprockets/loader.rb +95 -89
  37. data/lib/sprockets/manifest.rb +23 -59
  38. data/lib/sprockets/mime.rb +28 -41
  39. data/lib/sprockets/path_dependency_utils.rb +76 -0
  40. data/lib/sprockets/path_utils.rb +21 -1
  41. data/lib/sprockets/paths.rb +23 -8
  42. data/lib/sprockets/processing.rb +102 -91
  43. data/lib/sprockets/processor_utils.rb +97 -0
  44. data/lib/sprockets/resolve.rb +110 -97
  45. data/lib/sprockets/sass_cache_store.rb +2 -2
  46. data/lib/sprockets/sass_compressor.rb +17 -4
  47. data/lib/sprockets/sass_functions.rb +2 -2
  48. data/lib/sprockets/sass_importer.rb +2 -2
  49. data/lib/sprockets/sass_processor.rb +305 -0
  50. data/lib/sprockets/sass_template.rb +4 -286
  51. data/lib/sprockets/server.rb +1 -13
  52. data/lib/sprockets/transformers.rb +62 -25
  53. data/lib/sprockets/uglifier_compressor.rb +17 -4
  54. data/lib/sprockets/uri_utils.rb +190 -0
  55. data/lib/sprockets/utils.rb +87 -6
  56. data/lib/sprockets/version.rb +1 -1
  57. data/lib/sprockets/yui_compressor.rb +17 -4
  58. metadata +14 -5
  59. data/lib/sprockets/asset_uri.rb +0 -80
  60. data/lib/sprockets/lazy_processor.rb +0 -15
@@ -1,5 +1,5 @@
1
- require 'sprockets/digest_utils'
2
1
  require 'logger'
2
+ require 'sprockets/digest_utils'
3
3
 
4
4
  module Sprockets
5
5
  # Public: Wrapper interface to backend cache stores. Ensures a consistent API
@@ -76,7 +76,7 @@ module Sprockets
76
76
  #
77
77
  # Returns a JSON serializable object.
78
78
  def fetch(key)
79
- start = Utils.benchmark_start
79
+ start = Time.now.to_f
80
80
  expanded_key = expand_key(key)
81
81
  value = @fetch_cache.get(expanded_key)
82
82
  if value.nil?
@@ -85,7 +85,7 @@ module Sprockets
85
85
  value = yield
86
86
  @cache_wrapper.set(expanded_key, value)
87
87
  @logger.debug do
88
- ms = "(#{Utils.benchmark_end(start)}ms)"
88
+ ms = "(#{((Time.now.to_f - start) * 1000).to_i}ms)"
89
89
  "Sprockets Cache miss #{peek_key(key)} #{ms}"
90
90
  end
91
91
  end
@@ -98,31 +98,36 @@ module Sprockets
98
98
  # store.
99
99
  #
100
100
  # This API may be used publicaly, but may have undefined behavior
101
- # depending on the backend store being used. Therefore it must be used
102
- # with caution, which is why its prefixed with an underscore. Prefer the
101
+ # depending on the backend store being used. Prefer the
103
102
  # Cache#fetch API over using this.
104
103
  #
105
104
  # key - JSON serializable key
106
- # value - A consistent JSON serializable object for the given key. Setting
107
- # a different value for the given key has undefined behavior.
105
+ # local - Check local cache first (default: false)
108
106
  #
109
107
  # Returns a JSON serializable object or nil if there was a cache miss.
110
- def _get(key)
111
- @cache_wrapper.get(expand_key(key))
108
+ def get(key, local = false)
109
+ expanded_key = expand_key(key)
110
+ value = @fetch_cache.get(expanded_key) if local
111
+ value = @cache_wrapper.get(expanded_key) if value.nil?
112
+ value
112
113
  end
113
114
 
114
115
  # Public: Low level API to set item directly to the backend cache store.
115
116
  #
116
117
  # This API may be used publicaly, but may have undefined behavior
117
- # depending on the backend store being used. Therefore it must be used
118
- # with caution, which is why its prefixed with an underscore. Prefer the
118
+ # depending on the backend store being used. Prefer the
119
119
  # Cache#fetch API over using this.
120
120
  #
121
- # key - JSON serializable key
121
+ # key - JSON serializable key
122
+ # value - A consistent JSON serializable object for the given key. Setting
123
+ # a different value for the given key has undefined behavior.
124
+ # local - Set on local cache (default: false)
122
125
  #
123
126
  # Returns the value argument.
124
- def _set(key, value)
125
- @cache_wrapper.set(expand_key(key), value)
127
+ def set(key, value, local = false)
128
+ expanded_key = expand_key(key)
129
+ @fetch_cache.set(expanded_key, value)
130
+ @cache_wrapper.set(expanded_key, value)
126
131
  end
127
132
 
128
133
  # Public: Pretty inspect
@@ -1,6 +1,7 @@
1
- require 'digest/md5'
2
1
  require 'fileutils'
3
2
  require 'logger'
3
+ require 'sprockets/encoding_utils'
4
+ require 'sprockets/path_utils'
4
5
  require 'zlib'
5
6
 
6
7
  module Sprockets
@@ -1,4 +1,3 @@
1
- require 'sprockets/asset_uri'
2
1
  require 'sprockets/base'
3
2
 
4
3
  module Sprockets
@@ -18,8 +17,10 @@ module Sprockets
18
17
  @cache = environment.cache
19
18
  @stats = Hash.new { |h, k| h[k] = _stat(k) }
20
19
  @entries = Hash.new { |h, k| h[k] = _entries(k) }
21
- @digests = Hash.new { |h, k| h[k] = _file_digest(k) }
22
20
  @uris = Hash.new { |h, k| h[k] = _load(k) }
21
+
22
+ @processor_cache_keys = Hash.new { |h, k| h[k] = _processor_cache_key(k) }
23
+ @resolved_dependencies = Hash.new { |h, k| h[k] = _resolve_dependency(k) }
23
24
  end
24
25
 
25
26
  # No-op return self as cached environment.
@@ -40,83 +41,29 @@ module Sprockets
40
41
  @stats[path]
41
42
  end
42
43
 
43
- # Internal: Cache Environment#file_digest
44
- alias_method :_file_digest, :file_digest
45
- def file_digest(path)
46
- @digests[path]
47
- end
48
-
49
44
  # Internal: Cache Environment#load
50
45
  alias_method :_load, :load
51
46
  def load(uri)
52
47
  @uris[uri]
53
48
  end
54
49
 
55
- protected
56
- def asset_dependency_graph_cache_key(uri)
57
- filename, _ = AssetURI.parse(uri)
58
- [
59
- 'asset-uri-dep-graph',
60
- VERSION,
61
- self.version,
62
- self.paths,
63
- uri,
64
- file_digest(filename)
65
- ]
66
- end
67
-
68
- def asset_uri_cache_key(uri)
69
- [
70
- 'asset-uri',
71
- VERSION,
72
- self.version,
73
- uri
74
- ]
75
- end
76
-
77
- def load_asset_by_id_uri(uri)
78
- cache.fetch(asset_uri_cache_key(uri)) do
79
- super
80
- end
81
- end
82
-
83
- def load_asset_by_uri(uri)
84
- dep_graph_key = asset_dependency_graph_cache_key(uri)
85
-
86
- if asset = get_asset_dependency_graph_cache(dep_graph_key)
87
- asset
88
- else
89
- asset = super
90
- set_asset_dependency_graph_cache(dep_graph_key, asset)
91
- asset
92
- end
93
- end
94
-
95
- def get_asset_dependency_graph_cache(key)
96
- return unless cached = cache._get(key)
97
- paths, digest, uri = cached
98
-
99
- if files_digest(paths) == digest
100
- cache._get(asset_uri_cache_key(uri))
101
- end
102
- end
50
+ # Internal: Cache Environment#processor_cache_key
51
+ alias_method :_processor_cache_key, :processor_cache_key
52
+ def processor_cache_key(str)
53
+ @processor_cache_keys[str]
54
+ end
103
55
 
104
- def set_asset_dependency_graph_cache(key, asset)
105
- uri = asset[:uri]
106
- digest, paths = asset[:metadata].values_at(:dependency_sources_digest, :dependency_paths)
107
- cache._set(key, [paths, digest, uri])
108
- cache.fetch(asset_uri_cache_key(uri)) { asset }
109
- asset
110
- end
56
+ # Internal: Cache Environment#resolve_dependency
57
+ alias_method :_resolve_dependency, :resolve_dependency
58
+ def resolve_dependency(str)
59
+ @resolved_dependencies[str]
60
+ end
111
61
 
112
62
  private
113
- # Cache is immutable, any methods that try to clear the cache
63
+ # Cache is immutable, any methods that try to change the runtime config
114
64
  # should bomb.
115
- def mutate_config(*args)
65
+ def config=(config)
116
66
  raise RuntimeError, "can't modify immutable cached environment"
117
67
  end
118
68
  end
119
-
120
- # Deprecated
121
- Index = CachedEnvironment
122
69
  end
@@ -16,19 +16,32 @@ module Sprockets
16
16
  class ClosureCompressor
17
17
  VERSION = '1'
18
18
 
19
- def self.call(*args)
20
- new.call(*args)
19
+ # Public: Return singleton instance with default options.
20
+ #
21
+ # Returns ClosureCompressor object.
22
+ def self.instance
23
+ @instance ||= new
21
24
  end
22
25
 
26
+ def self.call(input)
27
+ instance.call(input)
28
+ end
29
+
30
+ def self.cache_key
31
+ instance.cache_key
32
+ end
33
+
34
+ attr_reader :cache_key
35
+
23
36
  def initialize(options = {})
24
37
  @compiler = ::Closure::Compiler.new(options)
25
38
  @cache_key = [
26
- 'ClosureCompressor',
39
+ self.class.name,
27
40
  ::Closure::VERSION,
28
41
  ::Closure::COMPILER_VERSION,
29
42
  VERSION,
30
43
  options
31
- ]
44
+ ].freeze
32
45
  end
33
46
 
34
47
  def call(input)
@@ -0,0 +1,26 @@
1
+ require 'coffee_script'
2
+
3
+ module Sprockets
4
+ # Processor engine class for the CoffeeScript compiler.
5
+ # Depends on the `coffee-script` and `coffee-script-source` gems.
6
+ #
7
+ # For more infomation see:
8
+ #
9
+ # https://github.com/josh/ruby-coffee-script
10
+ #
11
+ module CoffeeScriptProcessor
12
+ VERSION = '1'
13
+ SOURCE_VERSION = ::CoffeeScript::Source.version
14
+
15
+ def self.cache_key
16
+ @cache_key ||= [name, SOURCE_VERSION, VERSION].freeze
17
+ end
18
+
19
+ def self.call(input)
20
+ data = input[:data]
21
+ input[:cache].fetch(self.cache_key + [data]) do
22
+ ::CoffeeScript.compile(data)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,23 +1,6 @@
1
- require 'coffee_script'
1
+ require 'sprockets/coffee_script_processor'
2
2
 
3
3
  module Sprockets
4
- # Template engine class for the CoffeeScript compiler.
5
- # Depends on the `coffee-script` and `coffee-script-source` gems.
6
- #
7
- # For more infomation see:
8
- #
9
- # https://github.com/josh/ruby-coffee-script
10
- #
11
- module CoffeeScriptTemplate
12
- VERSION = '1'
13
- SOURCE_VERSION = ::CoffeeScript::Source.version
14
-
15
- def self.call(input)
16
- data = input[:data]
17
- key = ['CoffeeScriptTemplate', SOURCE_VERSION, VERSION, data]
18
- input[:cache].fetch(key) do
19
- ::CoffeeScript.compile(data)
20
- end
21
- end
22
- end
4
+ # Deprecated
5
+ CoffeeScriptTemplate = CoffeeScriptProcessor
23
6
  end
@@ -1,11 +1,17 @@
1
+ require 'sprockets/utils'
2
+
1
3
  module Sprockets
2
4
  # `Compressing` is an internal mixin whose public methods are exposed on
3
5
  # the `Environment` and `CachedEnvironment` classes.
4
6
  module Compressing
5
- attr_reader :compressors
7
+ include Utils
8
+
9
+ def compressors
10
+ config[:compressors]
11
+ end
6
12
 
7
13
  def register_compressor(mime_type, sym, klass)
8
- mutate_hash_config(:compressors, mime_type) do |compressors|
14
+ self.config = hash_reassoc(config, :compressors, mime_type) do |compressors|
9
15
  compressors[sym] = klass
10
16
  compressors
11
17
  end
@@ -14,7 +20,7 @@ module Sprockets
14
20
  # Return CSS compressor or nil if none is set
15
21
  def css_compressor
16
22
  if defined? @css_compressor
17
- unwrap_processor(@css_compressor)
23
+ @css_compressor
18
24
  end
19
25
  end
20
26
 
@@ -41,7 +47,7 @@ module Sprockets
41
47
  # Return JS compressor or nil if none is set
42
48
  def js_compressor
43
49
  if defined? @js_compressor
44
- unwrap_processor(@js_compressor)
50
+ @js_compressor
45
51
  end
46
52
  end
47
53
 
@@ -1,33 +1,27 @@
1
1
  require 'sprockets/compressing'
2
+ require 'sprockets/dependencies'
2
3
  require 'sprockets/engines'
3
4
  require 'sprockets/mime'
4
5
  require 'sprockets/paths'
5
6
  require 'sprockets/processing'
6
7
  require 'sprockets/transformers'
8
+ require 'sprockets/utils'
7
9
 
8
10
  module Sprockets
9
11
  module Configuration
10
- include Paths, Mime, Engines, Transformers, Processing, Compressing
12
+ include Paths, Mime, Engines, Transformers, Processing, Compressing, Dependencies, Utils
11
13
 
12
14
  def initialize_configuration(parent)
13
- @logger = parent.logger
14
- @version = parent.version
15
- @digest_class = parent.digest_class
16
- @context_class = Class.new(parent.context_class)
17
- @root = parent.root
18
- @paths = parent.paths
19
- @mime_types = parent.mime_types
20
- @mime_exts = parent.mime_exts
21
- @encodings = parent.encodings
22
- @engines = parent.engines
23
- @engine_mime_types = parent.engine_mime_types
24
- @transformers = parent.transformers
25
- @inverted_transformers = parent.inverted_transformers
26
- @preprocessors = parent.preprocessors
27
- @postprocessors = parent.postprocessors
28
- @bundle_reducers = parent.bundle_reducers
29
- @bundle_processors = parent.bundle_processors
30
- @compressors = parent.compressors
15
+ @config = parent.config
16
+ @logger = parent.logger
17
+ @context_class = Class.new(parent.context_class)
18
+ end
19
+
20
+ attr_reader :config
21
+
22
+ def config=(config)
23
+ raise TypeError, "can't assign mutable config" unless config.frozen?
24
+ @config = config
31
25
  end
32
26
 
33
27
  # Get and set `Logger` instance.
@@ -43,20 +37,24 @@ module Sprockets
43
37
  #
44
38
  # It would be wise to increment this value anytime you make a
45
39
  # configuration change to the `Environment` object.
46
- attr_reader :version
40
+ def version
41
+ config[:version]
42
+ end
47
43
 
48
44
  # Assign an environment version.
49
45
  #
50
46
  # environment.version = '2.0'
51
47
  #
52
48
  def version=(version)
53
- mutate_config(:version) { version.dup }
49
+ self.config = hash_reassoc(config, :version) { version.dup }
54
50
  end
55
51
 
56
52
  # Public: Returns a `Digest` implementation class.
57
53
  #
58
54
  # Defaults to `Digest::SHA256`.
59
- attr_reader :digest_class
55
+ def digest_class
56
+ config[:digest_class]
57
+ end
60
58
 
61
59
  # Deprecated: Assign a `Digest` implementation class. This maybe any Ruby
62
60
  # `Digest::` implementation such as `Digest::SHA256` or
@@ -65,7 +63,7 @@ module Sprockets
65
63
  # environment.digest_class = Digest::MD5
66
64
  #
67
65
  def digest_class=(klass)
68
- @digest_class = klass
66
+ self.config = config.merge(digest_class: klass).freeze
69
67
  end
70
68
 
71
69
  # Deprecated: Get `Context` class.
@@ -78,19 +76,5 @@ module Sprockets
78
76
  # end
79
77
  #
80
78
  attr_reader :context_class
81
-
82
- private
83
- def mutate_config(sym)
84
- obj = yield self.instance_variable_get("@#{sym}").dup
85
- self.instance_variable_set("@#{sym}", obj.freeze)
86
- end
87
-
88
- def mutate_hash_config(sym, key)
89
- mutate_config(sym) do |hash|
90
- obj = yield hash[key].dup
91
- hash[key] = obj.freeze
92
- hash
93
- end
94
- end
95
79
  end
96
80
  end
@@ -4,7 +4,7 @@ require 'set'
4
4
  require 'sprockets/errors'
5
5
 
6
6
  module Sprockets
7
- # Deprecated: `Context` provides helper methods to all `Template` processors.
7
+ # Deprecated: `Context` provides helper methods to all processors.
8
8
  # They are typically accessed by ERB templates. You can mix in custom helpers
9
9
  # by injecting them into `Environment#context_class`. Do not mix them into
10
10
  # `Context` directly.
@@ -34,17 +34,17 @@ module Sprockets
34
34
  @pathname = Pathname.new(@filename)
35
35
  @content_type = input[:content_type]
36
36
 
37
- @required = Set.new(@metadata[:required])
38
- @stubbed = Set.new(@metadata[:stubbed])
39
- @links = Set.new(@metadata[:links])
40
- @dependency_paths = Set.new(@metadata[:dependency_paths])
37
+ @required = Set.new(@metadata[:required])
38
+ @stubbed = Set.new(@metadata[:stubbed])
39
+ @links = Set.new(@metadata[:links])
40
+ @dependencies = Set.new(input[:metadata][:dependencies])
41
41
  end
42
42
 
43
43
  def metadata
44
44
  { required: @required,
45
45
  stubbed: @stubbed,
46
46
  links: @links,
47
- dependency_paths: @dependency_paths }
47
+ dependencies: @dependencies }
48
48
  end
49
49
 
50
50
  # Returns the environment path that contains the file.
@@ -69,61 +69,36 @@ module Sprockets
69
69
  #
70
70
  attr_reader :content_type
71
71
 
72
- # Internal
73
- # TODO: Cleanup relative resolver logic shared between directive processor.
74
- def _resolve(method, path, options = {})
75
- options[:content_type] = self.content_type if options[:content_type] == :self
76
- options[:accept] = options.delete(:content_type)
77
-
78
- if environment.absolute_path?(path)
79
- filename = path
80
- elsif environment.relative_path?(path)
81
- path = File.expand_path(path, @dirname)
82
- if logical_path = @environment.split_subpath(load_path, path)
83
- if filename = environment.send(method, logical_path, options.merge(load_paths: [load_path]))
84
- accept = options[:accept]
85
- message = "couldn't find file '#{logical_path}' under '#{load_path}'"
86
- message << " with type '#{accept}'" if accept
87
- raise FileNotFound, message
88
- end
89
- else
90
- raise FileOutsidePaths, "#{path} isn't under path: #{load_path}"
91
- end
92
- else
93
- filename = environment.send(method, path, options)
94
- end
95
-
96
- if filename
97
- filename
98
- else
99
- accept = options[:accept]
100
- message = "couldn't find file '#{path}'"
101
- message << " with type '#{accept}'" if accept
102
- raise FileNotFound, message
103
- end
104
- end
105
-
106
- # Given a logical path, `resolve` will find and return the fully
107
- # expanded path. Relative paths will also be resolved. An optional
108
- # `:content_type` restriction can be supplied to restrict the
109
- # search.
72
+ # Public: Given a logical path, `resolve` will find and return an Asset URI.
73
+ # Relative paths will also be resolved. An accept type maybe given to
74
+ # restrict the search.
110
75
  #
111
76
  # resolve("foo.js")
112
- # # => "/path/to/app/javascripts/foo.js"
77
+ # # => "file:///path/to/app/javascripts/foo.js?type=application/javascript"
113
78
  #
114
79
  # resolve("./bar.js")
115
- # # => "/path/to/app/javascripts/bar.js"
80
+ # # => "file:///path/to/app/javascripts/bar.js?type=application/javascript"
81
+ #
82
+ # path - String logical or absolute path
83
+ # options
84
+ # accept - String content accept type
116
85
  #
86
+ # Returns an Asset URI String.
117
87
  def resolve(path, options = {})
118
- _resolve(:resolve, path, options)
88
+ uri, deps = environment.resolve!(path, options.merge(base_path: @dirname))
89
+ @dependencies.merge(deps)
90
+ uri
119
91
  end
120
92
 
121
- def locate(path, options = {})
122
- if AssetURI.valid?(path)
123
- path
124
- else
125
- _resolve(:locate, path, options)
126
- end
93
+ # Public: Load Asset by AssetURI and track it as a dependency.
94
+ #
95
+ # uri - AssetURI
96
+ #
97
+ # Returns Asset.
98
+ def load(uri)
99
+ asset = environment.load(uri)
100
+ @dependencies.merge(asset.metadata[:dependencies])
101
+ asset
127
102
  end
128
103
 
129
104
  # `depend_on` allows you to state a dependency on a file without
@@ -133,7 +108,7 @@ module Sprockets
133
108
  # the dependency file with invalidate the cache of the
134
109
  # source file.
135
110
  def depend_on(path)
136
- @dependency_paths << resolve(path).to_s
111
+ resolve(path, compat: false)
137
112
  nil
138
113
  end
139
114
 
@@ -145,10 +120,7 @@ module Sprockets
145
120
  # file. Unlike `depend_on`, this will include recursively include
146
121
  # the target asset's dependencies.
147
122
  def depend_on_asset(path)
148
- if asset = @environment.load(locate(path))
149
- @dependency_paths.merge(asset.metadata[:dependency_paths])
150
- end
151
- nil
123
+ load(resolve(path, compat: false))
152
124
  end
153
125
 
154
126
  # `require_asset` declares `path` as a dependency of the file. The
@@ -161,7 +133,7 @@ module Sprockets
161
133
  # <%= require_asset "#{framework}.js" %>
162
134
  #
163
135
  def require_asset(path)
164
- @required << locate(path, accept: @content_type, bundle: false)
136
+ @required << resolve(path, accept: @content_type, bundle: false, compat: false)
165
137
  nil
166
138
  end
167
139
 
@@ -169,7 +141,7 @@ module Sprockets
169
141
  # `path` must be an asset which may or may not already be included
170
142
  # in the bundle.
171
143
  def stub_asset(path)
172
- @stubbed << locate(path, accept: @content_type, bundle: false)
144
+ @stubbed << resolve(path, accept: @content_type, bundle: false, compat: false)
173
145
  nil
174
146
  end
175
147
 
@@ -179,10 +151,8 @@ module Sprockets
179
151
  #
180
152
  # Returns an Asset or nil.
181
153
  def link_asset(path)
182
- if asset = @environment.load(locate(path))
183
- @dependency_paths.merge(asset.metadata[:dependency_paths])
184
- @links << asset.uri
185
- end
154
+ asset = depend_on_asset(path)
155
+ @links << asset.uri
186
156
  asset
187
157
  end
188
158
 
@@ -197,9 +167,9 @@ module Sprockets
197
167
  # $('<img>').attr('src', '<%= asset_data_uri 'avatar.jpg' %>')
198
168
  #
199
169
  def asset_data_uri(path)
200
- depend_on_asset(path)
201
- asset = environment.find_asset(path, accept_encoding: 'base64')
202
- "data:#{asset.content_type};base64,#{Rack::Utils.escape(asset.to_s)}"
170
+ asset = depend_on_asset(path)
171
+ data = EncodingUtils.base64(asset.source)
172
+ "data:#{asset.content_type};base64,#{Rack::Utils.escape(data)}"
203
173
  end
204
174
 
205
175
  # Expands logical path to full url to asset.