Skip to content

Commit 6905879

Browse files
committed
Implement raw css imports
#318 Refactor lookup code for better readability
1 parent d9b3f4b commit 6905879

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

file.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <iostream>
1010
#include <fstream>
1111
#include <cctype>
12+
#include <vector>
1213
#include <algorithm>
1314
#include <sys/stat.h>
1415
#include "file.hpp"
@@ -202,34 +203,38 @@ namespace Sass {
202203
// (4) given + extension
203204
char* contents = 0;
204205
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)
206212
if (!(contents = read_file(real_path))) {
207213
string dir(dir_name(path));
208214
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;
233238
}
234239
}
235240
}

0 commit comments

Comments
 (0)