sprockets 2.3.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sprockets might be problematic. Click here for more details.

Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +2 -2
  3. data/README.md +332 -115
  4. data/bin/sprockets +8 -0
  5. data/lib/rake/sprocketstask.rb +25 -13
  6. data/lib/sprockets/asset.rb +143 -205
  7. data/lib/sprockets/autoload/closure.rb +7 -0
  8. data/lib/sprockets/autoload/coffee_script.rb +7 -0
  9. data/lib/sprockets/autoload/eco.rb +7 -0
  10. data/lib/sprockets/autoload/ejs.rb +7 -0
  11. data/lib/sprockets/autoload/sass.rb +7 -0
  12. data/lib/sprockets/autoload/uglifier.rb +7 -0
  13. data/lib/sprockets/autoload/yui.rb +7 -0
  14. data/lib/sprockets/autoload.rb +11 -0
  15. data/lib/sprockets/base.rb +49 -257
  16. data/lib/sprockets/bower.rb +58 -0
  17. data/lib/sprockets/bundle.rb +65 -0
  18. data/lib/sprockets/cache/file_store.rb +165 -14
  19. data/lib/sprockets/cache/memory_store.rb +66 -0
  20. data/lib/sprockets/cache/null_store.rb +46 -0
  21. data/lib/sprockets/cache.rb +234 -0
  22. data/lib/sprockets/cached_environment.rb +69 -0
  23. data/lib/sprockets/closure_compressor.rb +53 -0
  24. data/lib/sprockets/coffee_script_processor.rb +25 -0
  25. data/lib/sprockets/coffee_script_template.rb +6 -0
  26. data/lib/sprockets/compressing.rb +74 -0
  27. data/lib/sprockets/configuration.rb +83 -0
  28. data/lib/sprockets/context.rb +125 -131
  29. data/lib/sprockets/dependencies.rb +73 -0
  30. data/lib/sprockets/digest_utils.rb +156 -0
  31. data/lib/sprockets/directive_processor.rb +209 -211
  32. data/lib/sprockets/eco_processor.rb +32 -0
  33. data/lib/sprockets/eco_template.rb +3 -35
  34. data/lib/sprockets/ejs_processor.rb +31 -0
  35. data/lib/sprockets/ejs_template.rb +3 -34
  36. data/lib/sprockets/encoding_utils.rb +258 -0
  37. data/lib/sprockets/engines.rb +45 -38
  38. data/lib/sprockets/environment.rb +17 -67
  39. data/lib/sprockets/erb_processor.rb +30 -0
  40. data/lib/sprockets/erb_template.rb +6 -0
  41. data/lib/sprockets/errors.rb +6 -13
  42. data/lib/sprockets/file_reader.rb +15 -0
  43. data/lib/sprockets/http_utils.rb +115 -0
  44. data/lib/sprockets/jst_processor.rb +35 -19
  45. data/lib/sprockets/legacy.rb +314 -0
  46. data/lib/sprockets/legacy_proc_processor.rb +35 -0
  47. data/lib/sprockets/legacy_tilt_processor.rb +29 -0
  48. data/lib/sprockets/loader.rb +176 -0
  49. data/lib/sprockets/manifest.rb +179 -98
  50. data/lib/sprockets/manifest_utils.rb +45 -0
  51. data/lib/sprockets/mime.rb +114 -32
  52. data/lib/sprockets/path_dependency_utils.rb +85 -0
  53. data/lib/sprockets/path_digest_utils.rb +47 -0
  54. data/lib/sprockets/path_utils.rb +282 -0
  55. data/lib/sprockets/paths.rb +81 -0
  56. data/lib/sprockets/processing.rb +157 -189
  57. data/lib/sprockets/processor_utils.rb +103 -0
  58. data/lib/sprockets/resolve.rb +208 -0
  59. data/lib/sprockets/sass_cache_store.rb +19 -15
  60. data/lib/sprockets/sass_compressor.rb +59 -0
  61. data/lib/sprockets/sass_functions.rb +2 -0
  62. data/lib/sprockets/sass_importer.rb +2 -29
  63. data/lib/sprockets/sass_processor.rb +285 -0
  64. data/lib/sprockets/sass_template.rb +4 -44
  65. data/lib/sprockets/server.rb +109 -84
  66. data/lib/sprockets/transformers.rb +145 -0
  67. data/lib/sprockets/uglifier_compressor.rb +63 -0
  68. data/lib/sprockets/uri_utils.rb +190 -0
  69. data/lib/sprockets/utils.rb +193 -44
  70. data/lib/sprockets/version.rb +1 -1
  71. data/lib/sprockets/yui_compressor.rb +65 -0
  72. data/lib/sprockets.rb +144 -53
  73. metadata +248 -238
  74. data/lib/sprockets/asset_attributes.rb +0 -126
  75. data/lib/sprockets/bundled_asset.rb +0 -79
  76. data/lib/sprockets/caching.rb +0 -96
  77. data/lib/sprockets/charset_normalizer.rb +0 -41
  78. data/lib/sprockets/index.rb +0 -99
  79. data/lib/sprockets/processed_asset.rb +0 -152
  80. data/lib/sprockets/processor.rb +0 -32
  81. data/lib/sprockets/safety_colons.rb +0 -28
  82. data/lib/sprockets/scss_template.rb +0 -13
  83. data/lib/sprockets/static_asset.rb +0 -57
  84. data/lib/sprockets/trail.rb +0 -90
@@ -0,0 +1,208 @@
1
+ require 'set'
2
+ require 'sprockets/http_utils'
3
+ require 'sprockets/path_dependency_utils'
4
+ require 'sprockets/uri_utils'
5
+
6
+ module Sprockets
7
+ module Resolve
8
+ include HTTPUtils, PathDependencyUtils, URIUtils
9
+
10
+ # Public: Find Asset URI for given a logical path by searching the
11
+ # environment's load paths.
12
+ #
13
+ # resolve("application.js")
14
+ # # => "file:///path/to/app/javascripts/application.js?type=application/javascript"
15
+ #
16
+ # An accept content type can be given if the logical path doesn't have a
17
+ # format extension.
18
+ #
19
+ # resolve("application", accept: "application/javascript")
20
+ # # => "file:///path/to/app/javascripts/application.coffee?type=application/javascript"
21
+ #
22
+ # The String Asset URI is returned or nil if no results are found.
23
+ def resolve(path, options = {})
24
+ path = path.to_s
25
+ paths = options[:load_paths] || config[:paths]
26
+ accept = options[:accept]
27
+
28
+ if valid_asset_uri?(path)
29
+ uri, deps = resolve_asset_uri(path)
30
+ elsif absolute_path?(path)
31
+ filename, type, deps = resolve_absolute_path(paths, path, accept)
32
+ elsif relative_path?(path)
33
+ filename, type, pipeline, deps = resolve_relative_path(paths, path, options[:base_path], accept)
34
+ else
35
+ filename, type, pipeline, deps = resolve_logical_path(paths, path, accept)
36
+ end
37
+
38
+ if filename
39
+ params = {}
40
+ params[:type] = type if type
41
+ params[:pipeline] = pipeline if pipeline
42
+ params[:pipeline] = options[:pipeline] if options[:pipeline]
43
+ uri = build_asset_uri(filename, params)
44
+ end
45
+
46
+ return uri, deps
47
+ end
48
+
49
+ # Public: Same as resolve() but raises a FileNotFound exception instead of
50
+ # nil if no assets are found.
51
+ def resolve!(path, options = {})
52
+ uri, deps = resolve(path, options.merge(compat: false))
53
+
54
+ unless uri
55
+ message = "couldn't find file '#{path}'"
56
+ message << " with type '#{options[:accept]}'" if options[:accept]
57
+ raise FileNotFound, message
58
+ end
59
+
60
+ return uri, deps
61
+ end
62
+
63
+ protected
64
+ def resolve_asset_uri(uri)
65
+ filename, _ = parse_asset_uri(uri)
66
+ return uri, Set.new([build_file_digest_uri(filename)])
67
+ end
68
+
69
+ def resolve_absolute_path(paths, filename, accept)
70
+ deps = Set.new
71
+ filename = File.expand_path(filename)
72
+
73
+ # Ensure path is under load paths
74
+ return nil, nil, deps unless paths_split(paths, filename)
75
+
76
+ _, mime_type, _, _ = parse_path_extnames(filename)
77
+ type = resolve_transform_type(mime_type, accept)
78
+ return nil, nil, deps if accept && !type
79
+
80
+ return nil, nil, deps unless file?(filename)
81
+
82
+ deps << build_file_digest_uri(filename)
83
+ return filename, type, deps
84
+ end
85
+
86
+ def resolve_relative_path(paths, path, dirname, accept)
87
+ filename = File.expand_path(path, dirname)
88
+ load_path, _ = paths_split(paths, dirname)
89
+ if load_path && logical_path = split_subpath(load_path, filename)
90
+ resolve_logical_path([load_path], logical_path, accept)
91
+ else
92
+ return nil, nil, Set.new
93
+ end
94
+ end
95
+
96
+ def resolve_logical_path(paths, logical_path, accept)
97
+ logical_name, mime_type, _, pipeline = parse_path_extnames(logical_path)
98
+ parsed_accept = parse_accept_options(mime_type, accept)
99
+ transformed_accepts = expand_transform_accepts(parsed_accept)
100
+ filename, mime_type, deps = resolve_under_paths(paths, logical_name, transformed_accepts)
101
+
102
+ if filename
103
+ deps << build_file_digest_uri(filename)
104
+ type = resolve_transform_type(mime_type, parsed_accept)
105
+ return filename, type, pipeline, deps
106
+ else
107
+ return nil, nil, nil, deps
108
+ end
109
+ end
110
+
111
+ def resolve_under_paths(paths, logical_name, accepts)
112
+ all_deps = Set.new
113
+ return nil, nil, all_deps if accepts.empty?
114
+
115
+ logical_basename = File.basename(logical_name)
116
+ paths.each do |load_path|
117
+ candidates, deps = path_matches(load_path, logical_name, logical_basename)
118
+ all_deps.merge(deps)
119
+ candidate = find_best_q_match(accepts, candidates) do |c, matcher|
120
+ match_mime_type?(c[1] || "application/octet-stream", matcher)
121
+ end
122
+ return candidate + [all_deps] if candidate
123
+ end
124
+
125
+ return nil, nil, all_deps
126
+ end
127
+
128
+ def parse_accept_options(mime_type, types)
129
+ accepts = []
130
+ accepts += parse_q_values(types) if types
131
+
132
+ if mime_type
133
+ if accepts.empty? || accepts.any? { |accept, _| match_mime_type?(mime_type, accept) }
134
+ accepts = [[mime_type, 1.0]]
135
+ else
136
+ return []
137
+ end
138
+ end
139
+
140
+ if accepts.empty?
141
+ accepts << ['*/*', 1.0]
142
+ end
143
+
144
+ accepts
145
+ end
146
+
147
+ def normalize_logical_path(path)
148
+ dirname, basename = File.split(path)
149
+ path = dirname if basename == 'index'
150
+ path
151
+ end
152
+
153
+ def path_matches(load_path, logical_name, logical_basename)
154
+ dirname = File.dirname(File.join(load_path, logical_name))
155
+ candidates = dirname_matches(dirname, logical_basename)
156
+ deps = file_digest_dependency_set(dirname)
157
+
158
+ result = resolve_alternates(load_path, logical_name)
159
+ result[0].each do |fn|
160
+ candidates << [fn, parse_path_extnames(fn)[1]]
161
+ end
162
+ deps.merge(result[1])
163
+
164
+ dirname = File.join(load_path, logical_name)
165
+ if directory? dirname
166
+ result = dirname_matches(dirname, "index")
167
+ candidates.concat(result)
168
+ end
169
+
170
+ deps.merge(file_digest_dependency_set(dirname))
171
+
172
+ return candidates.select { |fn, _| file?(fn) }, deps
173
+ end
174
+
175
+ def dirname_matches(dirname, basename)
176
+ candidates = []
177
+ entries = self.entries(dirname)
178
+ entries.each do |entry|
179
+ name, type, _, _ = parse_path_extnames(entry)
180
+ if basename == name
181
+ candidates << [File.join(dirname, entry), type]
182
+ end
183
+ end
184
+ candidates
185
+ end
186
+
187
+ def resolve_alternates(load_path, logical_name)
188
+ return [], Set.new
189
+ end
190
+
191
+ # Internal: Returns the name, mime type and `Array` of engine extensions.
192
+ #
193
+ # "foo.js.coffee.erb"
194
+ # # => ["foo", "application/javascript", [".coffee", ".erb"]]
195
+ #
196
+ def parse_path_extnames(path)
197
+ engines = []
198
+ extname, value = match_path_extname(path, extname_map)
199
+
200
+ if extname
201
+ path = path.chomp(extname)
202
+ type, engines, pipeline = value.values_at(:type, :engines, :pipeline)
203
+ end
204
+
205
+ return path, type, engines, pipeline
206
+ end
207
+ end
208
+ end
@@ -1,25 +1,29 @@
1
1
  require 'sass'
2
2
 
3
3
  module Sprockets
4
- class SassCacheStore < ::Sass::CacheStores::Base
5
- attr_reader :environment
4
+ class SassProcessor
5
+ # Internal: Cache wrapper for Sprockets cache adapter.
6
+ class CacheStore < ::Sass::CacheStores::Base
7
+ VERSION = '1'
6
8
 
7
- def initialize(environment)
8
- @environment = environment
9
- end
9
+ def initialize(cache, version)
10
+ @cache, @version = cache, "#{VERSION}/#{version}"
11
+ end
10
12
 
11
- def _store(key, version, sha, contents)
12
- environment.cache_set("sass/#{key}", {:version => version, :sha => sha, :contents => contents})
13
- end
13
+ def _store(key, version, sha, contents)
14
+ @cache.set("#{@version}/#{version}/#{key}/#{sha}", contents, true)
15
+ end
14
16
 
15
- def _retrieve(key, version, sha)
16
- if obj = environment.cache_get("sass/#{key}")
17
- return unless obj[:version] == version
18
- return unless obj[:sha] == sha
19
- obj[:obj]
20
- else
21
- nil
17
+ def _retrieve(key, version, sha)
18
+ @cache.get("#{@version}/#{version}/#{key}/#{sha}", true)
19
+ end
20
+
21
+ def path_to(key)
22
+ key
22
23
  end
23
24
  end
24
25
  end
26
+
27
+ # Deprecated: Use Sprockets::SassProcessor::CacheStore instead.
28
+ SassCacheStore = SassProcessor::CacheStore
25
29
  end
@@ -0,0 +1,59 @@
1
+ require 'sprockets/autoload'
2
+
3
+ module Sprockets
4
+ # Public: Sass CSS minifier.
5
+ #
6
+ # To accept the default options
7
+ #
8
+ # environment.register_bundle_processor 'text/css',
9
+ # Sprockets::SassCompressor
10
+ #
11
+ # Or to pass options to the Sass::Engine class.
12
+ #
13
+ # environment.register_bundle_processor 'text/css',
14
+ # Sprockets::SassCompressor.new({ ... })
15
+ #
16
+ class SassCompressor
17
+ VERSION = '1'
18
+
19
+ # Public: Return singleton instance with default options.
20
+ #
21
+ # Returns SassCompressor object.
22
+ def self.instance
23
+ @instance ||= new
24
+ end
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
+
36
+ def initialize(options = {})
37
+ @options = options
38
+ @cache_key = [
39
+ self.class.name,
40
+ Autoload::Sass::VERSION,
41
+ VERSION,
42
+ options
43
+ ].freeze
44
+ end
45
+
46
+ def call(input)
47
+ data = input[:data]
48
+ input[:cache].fetch(@cache_key + [data]) do
49
+ options = {
50
+ syntax: :scss,
51
+ cache: false,
52
+ read_cache: false,
53
+ style: :compressed
54
+ }.merge(@options)
55
+ Autoload::Sass::Engine.new(data, options).render
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,2 @@
1
+ # Deprecated: Require sprockets/sass_processor instead
2
+ require 'sprockets/sass_processor'
@@ -1,29 +1,2 @@
1
- require 'sass'
2
-
3
- module Sprockets
4
- # This custom importer adds sprockets dependency tracking on to Sass
5
- # `@import` statements. This makes the Sprockets and Sass caching
6
- # systems work together.
7
- class SassImporter < Sass::Importers::Filesystem
8
- def initialize(context, root)
9
- @context = context
10
- super root.to_s
11
- end
12
-
13
- def find_relative(*args)
14
- engine = super
15
- if engine && (filename = engine.options[:filename])
16
- @context.depend_on_asset(filename)
17
- end
18
- engine
19
- end
20
-
21
- def find(*args)
22
- engine = super
23
- if engine && (filename = engine.options[:filename])
24
- @context.depend_on_asset(filename)
25
- end
26
- engine
27
- end
28
- end
29
- end
1
+ # Deprecated: Require sprockets/sass_processor instead
2
+ require 'sprockets/sass_processor'
@@ -0,0 +1,285 @@
1
+ require 'rack/utils'
2
+ require 'sprockets/autoload'
3
+ require 'uri'
4
+
5
+ module Sprockets
6
+ # Processor engine class for the SASS/SCSS compiler. Depends on the `sass` gem.
7
+ #
8
+ # For more infomation see:
9
+ #
10
+ # https://github.com/sass/sass
11
+ # https://github.com/rails/sass-rails
12
+ #
13
+ class SassProcessor
14
+ autoload :CacheStore, 'sprockets/sass_cache_store'
15
+
16
+ # Internal: Defines default sass syntax to use. Exposed so the ScssProcessor
17
+ # may override it.
18
+ def self.syntax
19
+ :sass
20
+ end
21
+
22
+ # Public: Return singleton instance with default options.
23
+ #
24
+ # Returns SassProcessor object.
25
+ def self.instance
26
+ @instance ||= new
27
+ end
28
+
29
+ def self.call(input)
30
+ instance.call(input)
31
+ end
32
+
33
+ def self.cache_key
34
+ instance.cache_key
35
+ end
36
+
37
+ attr_reader :cache_key
38
+
39
+ # Public: Initialize template with custom options.
40
+ #
41
+ # options - Hash
42
+ # cache_version - String custom cache version. Used to force a cache
43
+ # change after code changes are made to Sass Functions.
44
+ #
45
+ def initialize(options = {}, &block)
46
+ @cache_version = options[:cache_version]
47
+ @cache_key = [
48
+ self.class.name,
49
+ VERSION,
50
+ Autoload::Sass::VERSION,
51
+ @cache_version
52
+ ].freeze
53
+
54
+ @functions = Module.new do
55
+ include Functions
56
+ include options[:functions] if options[:functions]
57
+ class_eval(&block) if block_given?
58
+ end
59
+ end
60
+
61
+ def call(input)
62
+ context = input[:environment].context_class.new(input)
63
+
64
+ options = {
65
+ filename: input[:filename],
66
+ syntax: self.class.syntax,
67
+ cache_store: CacheStore.new(input[:cache], @cache_version),
68
+ load_paths: input[:environment].paths,
69
+ sprockets: {
70
+ context: context,
71
+ environment: input[:environment],
72
+ dependencies: context.metadata[:dependencies]
73
+ }
74
+ }
75
+
76
+ engine = Autoload::Sass::Engine.new(input[:data], options)
77
+
78
+ css = Utils.module_include(Autoload::Sass::Script::Functions, @functions) do
79
+ engine.render
80
+ end
81
+
82
+ # Track all imported files
83
+ sass_dependencies = Set.new([input[:filename]])
84
+ engine.dependencies.map do |dependency|
85
+ sass_dependencies << dependency.options[:filename]
86
+ context.metadata[:dependencies] << URIUtils.build_file_digest_uri(dependency.options[:filename])
87
+ end
88
+
89
+ context.metadata.merge(data: css, sass_dependencies: sass_dependencies)
90
+ end
91
+
92
+ # Public: Functions injected into Sass context during Sprockets evaluation.
93
+ #
94
+ # This module may be extended to add global functionality to all Sprockets
95
+ # Sass environments. Though, scoping your functions to just your environment
96
+ # is preferred.
97
+ #
98
+ # module Sprockets::SassProcessor::Functions
99
+ # def asset_path(path, options = {})
100
+ # end
101
+ # end
102
+ #
103
+ module Functions
104
+ # Public: Generate a url for asset path.
105
+ #
106
+ # Default implementation is deprecated. Currently defaults to
107
+ # Context#asset_path.
108
+ #
109
+ # Will raise NotImplementedError in the future. Users should provide their
110
+ # own base implementation.
111
+ #
112
+ # Returns a Sass::Script::String.
113
+ def asset_path(path, options = {})
114
+ path = path.value
115
+
116
+ path, _, query, fragment = URI.split(path)[5..8]
117
+ path = sprockets_context.asset_path(path, options)
118
+ query = "?#{query}" if query
119
+ fragment = "##{fragment}" if fragment
120
+
121
+ Autoload::Sass::Script::String.new("#{path}#{query}#{fragment}", :string)
122
+ end
123
+
124
+ # Public: Generate a asset url() link.
125
+ #
126
+ # path - Sass::Script::String URL path
127
+ #
128
+ # Returns a Sass::Script::String.
129
+ def asset_url(path, options = {})
130
+ Autoload::Sass::Script::String.new("url(#{asset_path(path, options).value})")
131
+ end
132
+
133
+ # Public: Generate url for image path.
134
+ #
135
+ # path - Sass::Script::String URL path
136
+ #
137
+ # Returns a Sass::Script::String.
138
+ def image_path(path)
139
+ asset_path(path, type: :image)
140
+ end
141
+
142
+ # Public: Generate a image url() link.
143
+ #
144
+ # path - Sass::Script::String URL path
145
+ #
146
+ # Returns a Sass::Script::String.
147
+ def image_url(path)
148
+ asset_url(path, type: :image)
149
+ end
150
+
151
+ # Public: Generate url for video path.
152
+ #
153
+ # path - Sass::Script::String URL path
154
+ #
155
+ # Returns a Sass::Script::String.
156
+ def video_path(path)
157
+ asset_path(path, type: :video)
158
+ end
159
+
160
+ # Public: Generate a video url() link.
161
+ #
162
+ # path - Sass::Script::String URL path
163
+ #
164
+ # Returns a Sass::Script::String.
165
+ def video_url(path)
166
+ asset_url(path, type: :video)
167
+ end
168
+
169
+ # Public: Generate url for audio path.
170
+ #
171
+ # path - Sass::Script::String URL path
172
+ #
173
+ # Returns a Sass::Script::String.
174
+ def audio_path(path)
175
+ asset_path(path, type: :audio)
176
+ end
177
+
178
+ # Public: Generate a audio url() link.
179
+ #
180
+ # path - Sass::Script::String URL path
181
+ #
182
+ # Returns a Sass::Script::String.
183
+ def audio_url(path)
184
+ asset_url(path, type: :audio)
185
+ end
186
+
187
+ # Public: Generate url for font path.
188
+ #
189
+ # path - Sass::Script::String URL path
190
+ #
191
+ # Returns a Sass::Script::String.
192
+ def font_path(path)
193
+ asset_path(path, type: :font)
194
+ end
195
+
196
+ # Public: Generate a font url() link.
197
+ #
198
+ # path - Sass::Script::String URL path
199
+ #
200
+ # Returns a Sass::Script::String.
201
+ def font_url(path)
202
+ asset_url(path, type: :font)
203
+ end
204
+
205
+ # Public: Generate url for javascript path.
206
+ #
207
+ # path - Sass::Script::String URL path
208
+ #
209
+ # Returns a Sass::Script::String.
210
+ def javascript_path(path)
211
+ asset_path(path, type: :javascript)
212
+ end
213
+
214
+ # Public: Generate a javascript url() link.
215
+ #
216
+ # path - Sass::Script::String URL path
217
+ #
218
+ # Returns a Sass::Script::String.
219
+ def javascript_url(path)
220
+ asset_url(path, type: :javascript)
221
+ end
222
+
223
+ # Public: Generate url for stylesheet path.
224
+ #
225
+ # path - Sass::Script::String URL path
226
+ #
227
+ # Returns a Sass::Script::String.
228
+ def stylesheet_path(path)
229
+ asset_path(path, type: :stylesheet)
230
+ end
231
+
232
+ # Public: Generate a stylesheet url() link.
233
+ #
234
+ # path - Sass::Script::String URL path
235
+ #
236
+ # Returns a Sass::Script::String.
237
+ def stylesheet_url(path)
238
+ asset_url(path, type: :stylesheet)
239
+ end
240
+
241
+ # Public: Generate a data URI for asset path.
242
+ #
243
+ # path - Sass::Script::String logical asset path
244
+ #
245
+ # Returns a Sass::Script::String.
246
+ def asset_data_url(path)
247
+ url = sprockets_context.asset_data_uri(path.value)
248
+ Autoload::Sass::Script::String.new("url(" + url + ")")
249
+ end
250
+
251
+ protected
252
+ # Public: The Environment.
253
+ #
254
+ # Returns Sprockets::Environment.
255
+ def sprockets_environment
256
+ options[:sprockets][:environment]
257
+ end
258
+
259
+ # Public: Mutatable set of dependencies.
260
+ #
261
+ # Returns a Set.
262
+ def sprockets_dependencies
263
+ options[:sprockets][:dependencies]
264
+ end
265
+
266
+ # Deprecated: Get the Context instance. Use APIs on
267
+ # sprockets_environment or sprockets_dependencies directly.
268
+ #
269
+ # Returns a Context instance.
270
+ def sprockets_context
271
+ options[:sprockets][:context]
272
+ end
273
+
274
+ end
275
+ end
276
+
277
+ class ScssProcessor < SassProcessor
278
+ def self.syntax
279
+ :scss
280
+ end
281
+ end
282
+
283
+ # Deprecated: Use Sprockets::SassProcessor::Functions instead.
284
+ SassFunctions = SassProcessor::Functions
285
+ end
@@ -1,47 +1,7 @@
1
- require 'tilt'
1
+ require 'sprockets/sass_processor'
2
2
 
3
3
  module Sprockets
4
- # This custom Tilt handler replaces the one built into Tilt. The
5
- # main difference is that it uses a custom importer that plays nice
6
- # with sprocket's caching system.
7
- #
8
- # See `SassImporter` for more infomation.
9
- class SassTemplate < Tilt::Template
10
- self.default_mime_type = 'text/css'
11
-
12
- def self.engine_initialized?
13
- defined? ::Sass::Engine
14
- end
15
-
16
- def initialize_engine
17
- require_template_library 'sass'
18
- end
19
-
20
- def prepare
21
- end
22
-
23
- def syntax
24
- :sass
25
- end
26
-
27
- def evaluate(context, locals, &block)
28
- # Use custom importer that knows about Sprockets Caching
29
- cache_store = SassCacheStore.new(context.environment)
30
-
31
- options = {
32
- :filename => eval_file,
33
- :line => line,
34
- :syntax => syntax,
35
- :cache_store => cache_store,
36
- :importer => SassImporter.new(context, context.pathname),
37
- :load_paths => context.environment.paths.map { |path| SassImporter.new(context, path) }
38
- }
39
-
40
- ::Sass::Engine.new(data, options).render
41
- rescue ::Sass::SyntaxError => e
42
- # Annotates exception message with parse line number
43
- context.__LINE__ = e.sass_backtrace.first[:line]
44
- raise e
45
- end
46
- end
4
+ # Deprecated
5
+ SassTemplate = SassProcessor
6
+ ScssTemplate = ScssProcessor
47
7
  end