Skip to content

Commit e563be8

Browse files
author
Francesco Rodriguez
committed
Add support for importing (.css,.scss,.sass).erb files. Fixes #139 #153.
1 parent bbd9105 commit e563be8

File tree

8 files changed

+49
-6
lines changed

8 files changed

+49
-6
lines changed

lib/sass/rails/importer.rb

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ class SassImporter < Sass::Importers::Filesystem
88

99
def extensions
1010
{
11-
"css" => :scss,
12-
"css.sass" => :sass,
13-
"css.scss" => :scss
11+
'css' => :scss,
12+
'css.scss' => :scss,
13+
'css.sass' => :sass,
14+
'css.erb' => :scss,
15+
'scss.erb' => :scss,
16+
'sass.erb' => :sass,
17+
'css.scss.erb' => :scss,
18+
'css.sass.erb' => :sass
1419
}.merge!(super)
1520
end
1621

@@ -58,5 +63,25 @@ def glob_imports(glob, base_pathname, options)
5863
:syntax => :scss
5964
))
6065
end
66+
67+
private
68+
69+
def _find(dir, name, options)
70+
full_filename, syntax = Sass::Util.destructure(find_real_file(dir, name, options))
71+
return unless full_filename && File.readable?(full_filename)
72+
73+
Sass::Engine.new(evaluate(full_filename), options.merge(
74+
syntax: syntax,
75+
filename: full_filename,
76+
importer: self
77+
))
78+
end
79+
80+
def evaluate(filename)
81+
processors = context.environment.attributes_for(filename).processors.reject { |processor|
82+
processor.in? [Sprockets::ScssTemplate, Sprockets::SassTemplate]
83+
}
84+
context.evaluate(filename, processors: processors)
85+
end
6186
end
6287
end

test/fixtures/scss_project/app/assets/stylesheets/application.css.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
@import "subfolder/plain";
55
@import "subfolder/second_level";
66
@import "partials/without_css_ext";
7-
@import "erb_handler";
7+
@import "css_erb_handler";
8+
@import "scss_erb_handler";
9+
@import "sass_erb_handler";
10+
@import "css_scss_erb_handler";
11+
@import "css_sass_erb_handler";
812

913
.main {
1014
color: yellow;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
.erb-handler {
1+
.css-erb-handler {
22
margin: <%= 0 %>;
33
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.css-sass-erb-handler
2+
margin: <%= 0 %>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.css-scss-erb-handler {
2+
margin: <%= 0 %>;
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.sass-erb-handler
2+
margin: <%= 0 %>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.scss-erb-handler {
2+
margin: <%= 0 %>;
3+
}

test/sass_rails_test.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ class SassRailsTest < Sass::Rails::TestCase
8181
assert_match /plain-old-css/, css_output
8282
assert_match /another-plain-old-css/, css_output
8383
assert_match /without-css-ext/, css_output
84-
assert_match /erb-handler/, css_output
84+
assert_match /css-erb-handler/, css_output
85+
assert_match /scss-erb-handler/, css_output
86+
assert_match /sass-erb-handler/, css_output
87+
assert_match /css-sass-erb-handler/, css_output
88+
assert_match /css-scss-erb-handler/, css_output
8589
end
8690

8791
test 'sass asset paths work' do

0 commit comments

Comments
 (0)