@@ -10,7 +10,7 @@ def initialize(postfix=nil)
10
10
@postfix = postfix
11
11
end
12
12
13
- def import_for ( original_path , parent_path , full_path , options )
13
+ def import_for ( full_path , parent_dir , options )
14
14
SassC ::Importer ::Import . new ( full_path )
15
15
end
16
16
end
@@ -20,7 +20,7 @@ def postfix
20
20
".css"
21
21
end
22
22
23
- def import_for ( original_path , parent_path , full_path , options )
23
+ def import_for ( full_path , parent_dir , options )
24
24
import_path = full_path . gsub ( /\. css$/ , "" )
25
25
SassC ::Importer ::Import . new ( import_path )
26
26
end
@@ -31,7 +31,7 @@ def postfix
31
31
".css.scss"
32
32
end
33
33
34
- def import_for ( original_path , parent_path , full_path , options )
34
+ def import_for ( full_path , parent_dir , options )
35
35
source = File . open ( full_path , 'rb' ) { |f | f . read }
36
36
SassC ::Importer ::Import . new ( full_path , source : source )
37
37
end
@@ -42,7 +42,7 @@ def postfix
42
42
".css.sass"
43
43
end
44
44
45
- def import_for ( original_path , parent_path , full_path , options )
45
+ def import_for ( full_path , parent_dir , options )
46
46
sass = File . open ( full_path , 'rb' ) { |f | f . read }
47
47
parsed_scss = SassC ::Sass2Scss . convert ( sass )
48
48
SassC ::Importer ::Import . new ( full_path , source : parsed_scss )
@@ -54,7 +54,7 @@ def postfix
54
54
".sass.erb"
55
55
end
56
56
57
- def import_for ( original_path , parent_path , full_path , options )
57
+ def import_for ( full_path , parent_dir , options )
58
58
template = Tilt ::ERBTemplate . new ( full_path )
59
59
parsed_erb = template . render ( options [ :sprockets ] [ :context ] , { } )
60
60
parsed_scss = SassC ::Sass2Scss . convert ( parsed_erb )
@@ -63,30 +63,37 @@ def import_for(original_path, parent_path, full_path, options)
63
63
end
64
64
65
65
class ERBExtension < Extension
66
- def import_for ( original_path , parent_path , full_path , options )
66
+ def import_for ( full_path , parent_dir , options )
67
67
template = Tilt ::ERBTemplate . new ( full_path )
68
68
parsed_erb = template . render ( options [ :sprockets ] [ :context ] , { } )
69
69
SassC ::Importer ::Import . new ( full_path , source : parsed_erb )
70
70
end
71
71
end
72
72
73
73
EXTENSIONS = [
74
+ CssScssExtension . new ,
75
+ CssSassExtension . new ,
74
76
Extension . new ( ".scss" ) ,
75
77
Extension . new ( ".sass" ) ,
76
78
CSSExtension . new ,
77
79
ERBExtension . new ( ".scss.erb" ) ,
78
80
ERBExtension . new ( ".css.erb" ) ,
79
- SassERBExtension . new ,
80
- CssScssExtension . new ,
81
- CssSassExtension . new
81
+ SassERBExtension . new
82
82
]
83
83
84
84
PREFIXS = [ "" , "_" ]
85
+ GLOB = /(\A |\/ )(\* |\* \* \/ \* )\z /
85
86
86
87
def imports ( path , parent_path )
87
88
parent_dir , _ = File . split ( parent_path )
88
89
specified_dir , specified_file = File . split ( path )
89
90
91
+ if m = path . match ( GLOB )
92
+ path = path . sub ( m [ 0 ] , "" )
93
+ base = File . expand_path ( path , File . dirname ( parent_path ) )
94
+ return glob_imports ( base , m [ 2 ] , parent_path )
95
+ end
96
+
90
97
search_paths = ( [ parent_dir ] + load_paths ) . uniq
91
98
92
99
if specified_dir != "."
@@ -103,17 +110,24 @@ def imports(path, parent_path)
103
110
try_path = File . join ( search_path , file_name + extension . postfix )
104
111
if File . exists? ( try_path )
105
112
record_import_as_dependency try_path
106
- return extension . import_for ( path , parent_path , try_path , options )
113
+ return extension . import_for ( try_path , parent_dir , options )
107
114
end
108
115
end
109
116
end
110
117
end
111
118
112
- Import . new ( path )
119
+ # TODO: Raise an error from SassC here
120
+ raise ArgumentError . new ( "file not found: #{ path } " )
113
121
end
114
122
115
123
private
116
124
125
+ def extension_for_file ( file )
126
+ EXTENSIONS . detect do |extension |
127
+ file . include? extension . postfix
128
+ end
129
+ end
130
+
117
131
def record_import_as_dependency ( path )
118
132
context . depend_on path
119
133
end
@@ -125,6 +139,39 @@ def context
125
139
def load_paths
126
140
options [ :load_paths ]
127
141
end
142
+
143
+ def glob_imports ( base , glob , current_file )
144
+ files = globbed_files ( base , glob )
145
+ files = files . reject { |f | f == current_file }
146
+
147
+ files . map do |filename |
148
+ record_import_as_dependency ( filename )
149
+ extension = extension_for_file ( filename )
150
+ extension . import_for ( filename , base , options )
151
+ end
152
+ end
153
+
154
+ def globbed_files ( base , glob )
155
+ # TODO: Raise an error from SassC here
156
+ raise ArgumentError unless glob == "*" || glob == "**/*"
157
+
158
+ extensions = EXTENSIONS . map ( &:postfix )
159
+ exts = extensions . map { |ext | Regexp . escape ( "#{ ext } " ) } . join ( "|" )
160
+ sass_re = Regexp . compile ( "(#{ exts } )$" )
161
+
162
+ record_import_as_dependency ( base )
163
+
164
+ files = Dir [ "#{ base } /#{ glob } " ] . sort . map do |path |
165
+ if File . directory? ( path )
166
+ record_import_as_dependency ( path )
167
+ nil
168
+ elsif sass_re =~ path
169
+ path
170
+ end
171
+ end
172
+
173
+ files . compact
174
+ end
128
175
end
129
176
end
130
177
end
0 commit comments