|
9 | 9 | #include <iostream>
|
10 | 10 | #include <fstream>
|
11 | 11 | #include <cctype>
|
| 12 | +#include <vector> |
12 | 13 | #include <algorithm>
|
13 | 14 | #include <sys/stat.h>
|
14 | 15 | #include "file.hpp"
|
@@ -202,34 +203,38 @@ namespace Sass {
|
202 | 203 | // (4) given + extension
|
203 | 204 | char* contents = 0;
|
204 | 205 | real_path = path;
|
205 |
| - // if the file isn't found with the given filename ... |
| 206 | + vector<string> exts(3); |
| 207 | + exts[0] = ".scss"; |
| 208 | + exts[1] = ".sass"; |
| 209 | + exts[2] = ".css"; |
| 210 | + |
| 211 | + // if the file isn't found with the given filename (1) |
206 | 212 | if (!(contents = read_file(real_path))) {
|
207 | 213 | string dir(dir_name(path));
|
208 | 214 | string base(base_name(path));
|
209 |
| - string _base("_" + base); |
210 |
| - real_path = dir + _base; |
211 |
| - // if the file isn't found with '_' + filename ... |
212 |
| - if (!(contents = read_file(real_path))) { |
213 |
| - string _base_scss(_base + ".scss"); |
214 |
| - real_path = dir + _base_scss; |
215 |
| - // if the file isn't found with '_' + filename + ".scss" ... |
216 |
| - if (!(contents = read_file(real_path))) { |
217 |
| - string _base_sass(_base + ".sass"); |
218 |
| - real_path = dir + _base_sass; |
219 |
| - // if the file isn't found with '_' + filename + ".sass" ... |
220 |
| - if (!(contents = read_file(real_path))) { |
221 |
| - string base_scss(base + ".scss"); |
222 |
| - real_path = dir + base_scss; |
223 |
| - // if the file isn't found with filename + ".scss" ... |
224 |
| - if (!(contents = read_file(real_path))) { |
225 |
| - string base_sass(base + ".sass"); |
226 |
| - real_path = dir + base_sass; |
227 |
| - // if the file isn't found with filename + ".sass" ... |
228 |
| - if (!(contents = read_file(real_path))) { |
229 |
| - // default back to scss version |
230 |
| - real_path = dir + base_scss; |
231 |
| - } |
232 |
| - } |
| 215 | + real_path = dir + base; |
| 216 | + // (2) underscore + given |
| 217 | + string test_path(dir + "_" + base); |
| 218 | + if ((contents = read_file(test_path))) { |
| 219 | + real_path = test_path; |
| 220 | + } |
| 221 | + // (3) underscore + given + extension |
| 222 | + if (!contents) { |
| 223 | + for(auto ext : exts) { |
| 224 | + test_path = dir + "_" + base + ext; |
| 225 | + if ((contents = read_file(test_path))) { |
| 226 | + real_path = test_path; |
| 227 | + break; |
| 228 | + } |
| 229 | + } |
| 230 | + } |
| 231 | + // (4) given + extension |
| 232 | + if (!contents) { |
| 233 | + for(auto ext : exts) { |
| 234 | + test_path = dir + base + ext; |
| 235 | + if ((contents = read_file(test_path))) { |
| 236 | + real_path = test_path; |
| 237 | + break; |
233 | 238 | }
|
234 | 239 | }
|
235 | 240 | }
|
|
0 commit comments