|
1 | 1 | require "sprockets/sass_template"
|
2 | 2 |
|
3 |
| -module Sprockets |
4 |
| - class SassTemplate |
5 |
| - def evaluate(context, locals, &block) |
6 |
| - cache_store = SassCacheStore.new(context.environment) |
7 |
| - |
8 |
| - options = { |
9 |
| - :filename => eval_file, |
10 |
| - :line => line, |
11 |
| - :syntax => syntax, |
12 |
| - :cache_store => cache_store, |
13 |
| - :importer => SassImporter.new(context, context.pathname), |
14 |
| - :load_paths => context.environment.paths.map { |path| SassImporter.new(context, path) }, |
15 |
| - :sprockets => { |
16 |
| - :context => context, |
17 |
| - :environment => context.environment |
| 3 | +module Sass |
| 4 | + module Rails |
| 5 | + class SassTemplate < Sprockets::SassTemplate |
| 6 | + |
| 7 | + def evaluate(context, locals, &block) |
| 8 | + cache_store = Sprockets::SassCacheStore.new(context.environment) |
| 9 | + |
| 10 | + options = { |
| 11 | + :filename => eval_file, |
| 12 | + :line => line, |
| 13 | + :syntax => syntax, |
| 14 | + :cache_store => cache_store, |
| 15 | + :importer => Sprockets::SassImporter.new(context.pathname.to_s), |
| 16 | + :load_paths => context.environment.paths.map { |path| Sprockets::SassImporter.new(path.to_s) }, |
| 17 | + :sprockets => { |
| 18 | + :context => context, |
| 19 | + :environment => context.environment |
| 20 | + } |
18 | 21 | }
|
19 |
| - } |
20 | 22 |
|
21 |
| - sass_config = context.environment.context_class.sass_config.merge(options) |
22 |
| - ::Sass::Engine.new(data, sass_config).render |
23 |
| - rescue ::Sass::SyntaxError => e |
24 |
| - context.__LINE__ = e.sass_backtrace.first[:line] |
25 |
| - raise e |
| 23 | + sass_config = context.environment.context_class.sass_config.merge(options) |
| 24 | + |
| 25 | + result = ::Sass::Engine.new(data, sass_config).render |
| 26 | + |
| 27 | + filenames = ([options[:importer].imported_filenames] + options[:load_path].map(&:imported_filenames)).flatten.uniq |
| 28 | + filenames.each { |filename| context.depend_on(filename) } |
| 29 | + |
| 30 | + result |
| 31 | + rescue ::Sass::SyntaxError => e |
| 32 | + context.__LINE__ = e.sass_backtrace.first[:line] |
| 33 | + raise e |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + class ScssTemplate < SassTemplate |
| 38 | + def self.default_mime_type |
| 39 | + 'text/css' |
| 40 | + end |
| 41 | + |
| 42 | + def syntax |
| 43 | + :scss |
| 44 | + end |
26 | 45 | end
|
27 | 46 | end
|
28 | 47 | end
|
0 commit comments