|
5 | 5 | #include <iostream>
|
6 | 6 | #include <fstream>
|
7 | 7 | #include <cctype>
|
| 8 | +#include <vector> |
8 | 9 | #include <algorithm>
|
9 | 10 | #include <sys/stat.h>
|
10 | 11 | #include "file.hpp"
|
@@ -185,34 +186,38 @@ namespace Sass {
|
185 | 186 | // (4) given + extension
|
186 | 187 | char* contents = 0;
|
187 | 188 | real_path = path;
|
188 |
| - // if the file isn't found with the given filename ... |
| 189 | + vector<string> exts(3); |
| 190 | + exts[0] = ".scss"; |
| 191 | + exts[1] = ".sass"; |
| 192 | + exts[2] = ".css"; |
| 193 | + |
| 194 | + // if the file isn't found with the given filename (1) |
189 | 195 | if (!(contents = read_file(real_path))) {
|
190 | 196 | string dir(dir_name(path));
|
191 | 197 | string base(base_name(path));
|
192 |
| - string _base("_" + base); |
193 |
| - real_path = dir + _base; |
194 |
| - // if the file isn't found with '_' + filename ... |
195 |
| - if (!(contents = read_file(real_path))) { |
196 |
| - string _base_scss(_base + ".scss"); |
197 |
| - real_path = dir + _base_scss; |
198 |
| - // if the file isn't found with '_' + filename + ".scss" ... |
199 |
| - if (!(contents = read_file(real_path))) { |
200 |
| - string _base_sass(_base + ".sass"); |
201 |
| - real_path = dir + _base_sass; |
202 |
| - // if the file isn't found with '_' + filename + ".sass" ... |
203 |
| - if (!(contents = read_file(real_path))) { |
204 |
| - string base_scss(base + ".scss"); |
205 |
| - real_path = dir + base_scss; |
206 |
| - // if the file isn't found with filename + ".scss" ... |
207 |
| - if (!(contents = read_file(real_path))) { |
208 |
| - string base_sass(base + ".sass"); |
209 |
| - real_path = dir + base_sass; |
210 |
| - // if the file isn't found with filename + ".sass" ... |
211 |
| - if (!(contents = read_file(real_path))) { |
212 |
| - // default back to scss version |
213 |
| - real_path = dir + base_scss; |
214 |
| - } |
215 |
| - } |
| 198 | + real_path = dir + base; |
| 199 | + // (2) underscore + given |
| 200 | + string test_path(dir + "_" + base); |
| 201 | + if ((contents = read_file(test_path))) { |
| 202 | + real_path = test_path; |
| 203 | + } |
| 204 | + // (3) underscore + given + extension |
| 205 | + if (!contents) { |
| 206 | + for(auto ext : exts) { |
| 207 | + test_path = dir + "_" + base + ext; |
| 208 | + if ((contents = read_file(test_path))) { |
| 209 | + real_path = test_path; |
| 210 | + break; |
| 211 | + } |
| 212 | + } |
| 213 | + } |
| 214 | + // (4) given + extension |
| 215 | + if (!contents) { |
| 216 | + for(auto ext : exts) { |
| 217 | + test_path = dir + base + ext; |
| 218 | + if ((contents = read_file(test_path))) { |
| 219 | + real_path = test_path; |
| 220 | + break; |
216 | 221 | }
|
217 | 222 | }
|
218 | 223 | }
|
|
0 commit comments