@@ -26,11 +26,16 @@ def import_for(original_path, parent_path, full_path, options)
26
26
end
27
27
end
28
28
29
- class ERBExtension < Extension
30
- def initialize ( postfix )
31
- super
29
+ class SassERBExtension < Extension
30
+ def import_for ( original_path , parent_path , full_path , options )
31
+ template = Tilt ::ERBTemplate . new ( full_path )
32
+ parsed_erb = template . render ( options [ :sprockets ] [ :context ] , { } )
33
+ parsed_scss = SassC ::Sass2Scss . convert ( parsed_erb )
34
+ SassC ::Importer ::Import . new ( full_path , source : parsed_scss )
32
35
end
36
+ end
33
37
38
+ class ERBExtension < Extension
34
39
def import_for ( original_path , parent_path , full_path , options )
35
40
template = Tilt ::ERBTemplate . new ( full_path )
36
41
parsed_erb = template . render ( options [ :sprockets ] [ :context ] , { } )
@@ -43,42 +48,13 @@ def import_for(original_path, parent_path, full_path, options)
43
48
Extension . new ( ".sass" ) ,
44
49
CSSExtension . new ,
45
50
ERBExtension . new ( ".scss.erb" ) ,
46
- ERBExtension . new ( ".sass.erb" ) ,
51
+ SassERBExtension . new ( ".sass.erb" ) ,
47
52
ERBExtension . new ( ".css.erb" ) ,
48
53
]
49
54
50
55
PREFIXS = [ "" , "_" ]
51
56
52
57
def imports ( path , parent_path )
53
- # should return an Import, or array of Imports.
54
- # Import.new(path)
55
-
56
- # Imports can usually be passed with only a path. However,
57
- # when parsing ERB we need to return the import like this:
58
- # Import.new(path, source: parsed_erb)
59
- # in this case, the path is just for reference, i don't believe it
60
- # gets used.
61
-
62
- # the parent path is basically the file that's calling the
63
- # @import function. This necessary when we need to do an import
64
- # relative to the folder that the import function is being called from.
65
-
66
- # for the filename, it looks like libsass can properly resolve
67
- # filenames without extensions provided that the actual file has
68
- # a .sass or .scss filename.
69
-
70
- # it CANNOT resolve a .css file unless you explicitly pass the
71
- # filename with the .css extension.
72
-
73
- # lets ignore globbing for now.
74
-
75
- # for ERB parsing, check out the sass-rails importer below, it looks pretty
76
- # simple
77
-
78
- # check out
79
- # https://github.com/sass/sass/blob/stable/lib/sass/importers/filesystem.rb
80
- # for reference
81
-
82
58
parent_dir , _ = File . split ( parent_path )
83
59
specified_dir , specified_file = File . split ( path )
84
60
@@ -123,151 +99,3 @@ def load_paths
123
99
end
124
100
end
125
101
end
126
-
127
- #require 'active_support/deprecation/reporting'
128
- #require 'sass'
129
- #require 'sprockets/sass_importer'
130
- #require 'tilt'
131
-
132
- # module Sass
133
- # module Rails
134
- # class SassImporter < Sass::Importers::Filesystem
135
- # module Globbing
136
- # GLOB = /(\A|\/)(\*|\*\*\/\*)\z/
137
- #
138
- # def find_relative(name, base, options)
139
- # if options[:sprockets] && m = name.match(GLOB)
140
- # path = name.sub(m[0], "")
141
- # base = File.expand_path(path, File.dirname(base))
142
- # glob_imports(base, m[2], options)
143
- # else
144
- # super
145
- # end
146
- # end
147
- #
148
- # def find(name, options)
149
- # # globs must be relative
150
- # return if name =~ GLOB
151
- # super
152
- # end
153
- #
154
- # private
155
- # def glob_imports(base, glob, options)
156
- # contents = ""
157
- # context = options[:sprockets][:context]
158
- # each_globbed_file(base, glob, context) do |filename|
159
- # next if filename == options[:filename]
160
- # contents << "@import #{filename.inspect};\n"
161
- # end
162
- # return nil if contents == ""
163
- # Sass::Engine.new(contents, options.merge(
164
- # :filename => base,
165
- # :importer => self,
166
- # :syntax => :scss
167
- # ))
168
- # end
169
- #
170
- # def each_globbed_file(base, glob, context)
171
- # raise ArgumentError unless glob == "*" || glob == "**/*"
172
- #
173
- # exts = extensions.keys.map { |ext| Regexp.escape(".#{ext}") }.join("|")
174
- # sass_re = Regexp.compile("(#{exts})$")
175
- #
176
- # context.depend_on(base)
177
- #
178
- # Dir["#{base}/#{glob}"].sort.each do |path|
179
- # if File.directory?(path)
180
- # context.depend_on(path)
181
- # elsif sass_re =~ path
182
- # yield path
183
- # end
184
- # end
185
- # end
186
- # end
187
- #
188
- # module ERB
189
- # def extensions
190
- # {
191
- # 'css.erb' => :scss_erb,
192
- # 'scss.erb' => :scss_erb,
193
- # 'sass.erb' => :sass_erb
194
- # }.merge(super)
195
- # end
196
- #
197
- # def erb_extensions
198
- # {
199
- # :scss_erb => :scss,
200
- # :sass_erb => :sass
201
- # }
202
- # end
203
- #
204
- # def find_relative(*args)
205
- # process_erb_engine(super)
206
- # end
207
- #
208
- # def find(*args)
209
- # process_erb_engine(super)
210
- # end
211
- #
212
- # private
213
- # def process_erb_engine(engine)
214
- # if engine && engine.options[:sprockets] && syntax = erb_extensions[engine.options[:syntax]]
215
- # template = Tilt::ERBTemplate.new(engine.options[:filename])
216
- # contents = template.render(engine.options[:sprockets][:context], {})
217
- #
218
- # Sass::Engine.new(contents, engine.options.merge(:syntax => syntax))
219
- # else
220
- # engine
221
- # end
222
- # end
223
- # end
224
- #
225
- # module Deprecated
226
- # def extensions
227
- # {
228
- # 'css.scss' => :scss,
229
- # 'css.sass' => :sass,
230
- # 'css.scss.erb' => :scss_erb,
231
- # 'css.sass.erb' => :sass_erb
232
- # }.merge(super)
233
- # end
234
- #
235
- # def find_relative(*args)
236
- # deprecate_extra_css_extension(super)
237
- # end
238
- #
239
- # def find(*args)
240
- # deprecate_extra_css_extension(super)
241
- # end
242
- #
243
- # private
244
- # def deprecate_extra_css_extension(engine)
245
- # if engine && filename = engine.options[:filename]
246
- # if filename.end_with?('.css.scss')
247
- # msg = "Extra .css in SCSS file is unnecessary. Rename #{filename} to #{filename.sub('.css.scss', '.scss')}."
248
- # elsif filename.end_with?('.css.sass')
249
- # msg = "Extra .css in SASS file is unnecessary. Rename #{filename} to #{filename.sub('.css.sass', '.sass')}."
250
- # elsif filename.end_with?('.css.scss.erb')
251
- # msg = "Extra .css in SCSS/ERB file is unnecessary. Rename #{filename} to #{filename.sub('.css.scss.erb', '.scss.erb')}."
252
- # elsif filename.end_with?('.css.sass.erb')
253
- # msg = "Extra .css in SASS/ERB file is unnecessary. Rename #{filename} to #{filename.sub('.css.sass.erb', '.sass.erb')}."
254
- # end
255
- #
256
- # ActiveSupport::Deprecation.warn(msg) if msg
257
- # end
258
- #
259
- # engine
260
- # end
261
- # end
262
- #
263
- # include Deprecated
264
- # include ERB
265
- # include Globbing
266
- #
267
- # # Allow .css files to be @import'd
268
- # def extensions
269
- # { 'css' => :scss }.merge(super)
270
- # end
271
- # end
272
- # end
273
- # end
0 commit comments