Skip to content

Commit 2635d43

Browse files
committed
Implement raw css imports
#318 Refactor lookup code for better readability
1 parent ccfcfd2 commit 2635d43

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
@@ -5,6 +5,7 @@
55
#include <iostream>
66
#include <fstream>
77
#include <cctype>
8+
#include <vector>
89
#include <algorithm>
910
#include <sys/stat.h>
1011
#include "file.hpp"
@@ -185,34 +186,38 @@ namespace Sass {
185186
// (4) given + extension
186187
char* contents = 0;
187188
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)
189195
if (!(contents = read_file(real_path))) {
190196
string dir(dir_name(path));
191197
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;
216221
}
217222
}
218223
}

0 commit comments

Comments
 (0)