|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 | 3 | require "sprockets/version"
|
4 |
| - |
5 |
| -begin |
6 |
| - require 'sprockets/sass_processor' |
7 |
| -rescue LoadError |
8 |
| - require "sprockets/sass_template" |
9 |
| -end |
10 |
| - |
| 4 | +require 'sprockets/sass_processor' |
11 | 5 | require "sprockets/utils"
|
12 | 6 |
|
13 | 7 | module SassC::Rails
|
14 |
| - |
15 |
| - class SassTemplate < defined?(Sprockets::SassProcessor) ? Sprockets::SassProcessor : Sprockets::SassTemplate |
16 |
| - module Sprockets3 |
17 |
| - def call(input) |
18 |
| - context = input[:environment].context_class.new(input) |
19 |
| - |
20 |
| - options = { |
21 |
| - filename: input[:filename], |
22 |
| - line_comments: line_comments?, |
23 |
| - syntax: self.class.syntax, |
24 |
| - load_paths: input[:environment].paths, |
25 |
| - importer: SassC::Rails::Importer, |
26 |
| - sprockets: { |
27 |
| - context: context, |
28 |
| - environment: input[:environment], |
29 |
| - dependencies: context.metadata[:dependency_paths] |
30 |
| - } |
31 |
| - }.merge(config_options) { |*args| safe_merge(*args) } |
32 |
| - |
33 |
| - engine = ::SassC::Engine.new(input[:data], options) |
34 |
| - |
35 |
| - css = Sprockets::Utils.module_include(::SassC::Script::Functions, @functions) do |
36 |
| - engine.render |
37 |
| - end |
38 |
| - |
39 |
| - context.metadata.merge(data: css) |
| 8 | + class SassTemplate < Sprockets::SassProcessor |
| 9 | + def initialize(options = {}, &block) |
| 10 | + @cache_version = options[:cache_version] |
| 11 | + @cache_key = "#{self.class.name}:#{VERSION}:#{SassC::VERSION}:#{@cache_version}".freeze |
| 12 | + #@importer_class = options[:importer] || Sass::Importers::Filesystem |
| 13 | + @sass_config = options[:sass_config] || {} |
| 14 | + @functions = Module.new do |
| 15 | + include Functions |
| 16 | + include options[:functions] if options[:functions] |
| 17 | + class_eval(&block) if block_given? |
40 | 18 | end
|
41 | 19 | end
|
42 | 20 |
|
43 |
| - module Sprockets2 |
44 |
| - def self.included(base) |
45 |
| - base.class_eval do |
46 |
| - self.default_mime_type = "text/css" |
47 |
| - end |
48 |
| - end |
49 |
| - |
50 |
| - def evaluate(context, locals, &block) |
51 |
| - options = { |
52 |
| - filename: eval_file, |
53 |
| - line_comments: line_comments?, |
54 |
| - syntax: syntax, |
55 |
| - load_paths: context.environment.paths, |
56 |
| - importer: SassC::Rails::Importer, |
57 |
| - sprockets: { |
58 |
| - context: context, |
59 |
| - environment: context.environment |
60 |
| - } |
61 |
| - }.merge(config_options, &method(:safe_merge)) |
62 |
| - |
63 |
| - ::SassC::Engine.new(data, options).render |
| 21 | + def call(input) |
| 22 | + context = input[:environment].context_class.new(input) |
| 23 | + |
| 24 | + options = { |
| 25 | + filename: input[:filename], |
| 26 | + line_comments: line_comments?, |
| 27 | + syntax: self.class.syntax, |
| 28 | + load_paths: input[:environment].paths, |
| 29 | + importer: SassC::Rails::Importer, |
| 30 | + sprockets: { |
| 31 | + context: context, |
| 32 | + environment: input[:environment], |
| 33 | + dependencies: context.metadata[:dependency_paths] |
| 34 | + } |
| 35 | + }.merge(config_options) { |*args| safe_merge(*args) } |
| 36 | + |
| 37 | + engine = ::SassC::Engine.new(input[:data], options) |
| 38 | + |
| 39 | + css = Sprockets::Utils.module_include(::SassC::Script::Functions, @functions) do |
| 40 | + engine.render |
64 | 41 | end
|
65 |
| - end |
66 | 42 |
|
67 |
| - if Sprockets::VERSION > "3.0.0" |
68 |
| - include Sprockets3 |
69 |
| - else |
70 |
| - include Sprockets2 |
| 43 | + context.metadata.merge(data: css) |
71 | 44 | end
|
72 | 45 |
|
73 | 46 | def config_options
|
@@ -109,18 +82,8 @@ def safe_merge(key, left, right)
|
109 | 82 | end
|
110 | 83 |
|
111 | 84 | class ScssTemplate < SassTemplate
|
112 |
| - unless Sprockets::VERSION > "3.0.0" |
113 |
| - self.default_mime_type = 'text/css' |
114 |
| - end |
115 |
| - |
116 |
| - # Sprockets 3 |
117 | 85 | def self.syntax
|
118 | 86 | :scss
|
119 | 87 | end
|
120 |
| - |
121 |
| - # Sprockets 2 |
122 |
| - def syntax |
123 |
| - :scss |
124 |
| - end |
125 | 88 | end
|
126 | 89 | end
|
0 commit comments