Skip to content

Commit 907e24c

Browse files
committed
handle .css.sass and .css.scss extensions
1 parent 02cc4b6 commit 907e24c

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

lib/sassc/rails/importer.rb

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Importer < SassC::Importer
66
class Extension
77
attr_reader :postfix
88

9-
def initialize(postfix)
9+
def initialize(postfix=nil)
1010
@postfix = postfix
1111
end
1212

@@ -26,7 +26,34 @@ def import_for(original_path, parent_path, full_path, options)
2626
end
2727
end
2828

29+
class CssScssExtension < Extension
30+
def postfix
31+
".css.scss"
32+
end
33+
34+
def import_for(original_path, parent_path, full_path, options)
35+
source = File.open(full_path, 'rb') { |f| f.read }
36+
SassC::Importer::Import.new(full_path, source: source)
37+
end
38+
end
39+
40+
class CssSassExtension < Extension
41+
def postfix
42+
".css.sass"
43+
end
44+
45+
def import_for(original_path, parent_path, full_path, options)
46+
sass = File.open(full_path, 'rb') { |f| f.read }
47+
parsed_scss = SassC::Sass2Scss.convert(sass)
48+
SassC::Importer::Import.new(full_path, source: parsed_scss)
49+
end
50+
end
51+
2952
class SassERBExtension < Extension
53+
def postfix
54+
".sass.erb"
55+
end
56+
3057
def import_for(original_path, parent_path, full_path, options)
3158
template = Tilt::ERBTemplate.new(full_path)
3259
parsed_erb = template.render(options[:sprockets][:context], {})
@@ -48,8 +75,10 @@ def import_for(original_path, parent_path, full_path, options)
4875
Extension.new(".sass"),
4976
CSSExtension.new,
5077
ERBExtension.new(".scss.erb"),
51-
SassERBExtension.new(".sass.erb"),
5278
ERBExtension.new(".css.erb"),
79+
SassERBExtension.new,
80+
CssScssExtension.new,
81+
CssSassExtension.new
5382
]
5483

5584
PREFIXS = [ "", "_" ]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.css-sass-handler
2+
color: blue
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.css-scss-handler {
2+
color: yellow;
3+
}

test/dummy/app/assets/stylesheets/imports_test.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
@import "css_erb_handler";
99
@import "scss_erb_handler";
1010
@import "sass_erb_handler";
11+
@import "css_scss_handler";
12+
@import "css_sass_handler";
1113
@import "css_scss_erb_handler";
1214
@import "css_sass_erb_handler";
1315

test/sassc_rails_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ def test_sass_imports_work_correctly
118118
assert_match /plain-old-css/, css_output
119119
assert_match /another-plain-old-css/, css_output
120120
assert_match /without-css-ext/, css_output
121+
assert_match /css-scss-handler/, css_output
122+
assert_match /css-sass-handler/, css_output
121123
assert_match /css-erb-handler/, css_output
122124
assert_match /scss-erb-handler/, css_output
123125
assert_match /sass-erb-handler/, css_output

0 commit comments

Comments
 (0)