Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ce2abd4

Browse files
committedMar 28, 2015
Refactor file resolving and internal API
Expose sass_file_resolve for consumers (WIP) Deprecate include_paths_array and plugin_paths_array
1 parent 10ef5de commit ce2abd4

9 files changed

+235
-166
lines changed
 

‎context.cpp

+25-38
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ namespace Sass {
9191

9292
include_paths.push_back(cwd);
9393
collect_include_paths(initializers.include_paths_c_str());
94-
collect_include_paths(initializers.include_paths_array());
94+
// collect_include_paths(initializers.include_paths_array());
9595
collect_plugin_paths(initializers.plugin_paths_c_str());
96-
collect_plugin_paths(initializers.plugin_paths_array());
96+
// collect_plugin_paths(initializers.plugin_paths_array());
9797

9898
setup_color_map();
9999

@@ -225,50 +225,37 @@ namespace Sass {
225225
include_links.push_back(resolve_relative_path(abs_path, source_map_file, cwd));
226226
}
227227

228-
string Context::add_file(string path)
228+
// Add a new import file to the context
229+
string Context::add_file(const string& file)
229230
{
230231
using namespace File;
231-
char* contents = 0;
232-
string real_path;
233-
path = make_canonical_path(path);
234-
for (size_t i = 0, S = include_paths.size(); i < S; ++i) {
235-
string full_path(join_paths(include_paths[i], path));
236-
if (style_sheets.count(full_path)) return full_path;
237-
contents = resolve_and_load(full_path, real_path);
238-
if (contents) {
239-
add_source(full_path, real_path, contents);
240-
style_sheets[full_path] = 0;
241-
return full_path;
242-
}
232+
string path(make_canonical_path(file));
233+
string resolved(find_file(path, include_paths));
234+
if (resolved == "") return resolved;
235+
if (char* contents = read_file(resolved)) {
236+
add_source(path, resolved, contents);
237+
style_sheets[path] = 0;
238+
return path;
243239
}
244-
return string();
240+
return string("");
245241
}
246242

247-
string Context::add_file(string dir, string rel_filepath)
243+
// Add a new import file to the context
244+
// This has some previous directory context
245+
string Context::add_file(const string& base, const string& file)
248246
{
249247
using namespace File;
250-
char* contents = 0;
251-
string real_path;
252-
rel_filepath = make_canonical_path(rel_filepath);
253-
string full_path(join_paths(dir, rel_filepath));
254-
if (style_sheets.count(full_path)) return full_path;
255-
contents = resolve_and_load(full_path, real_path);
256-
if (contents) {
257-
add_source(full_path, real_path, contents);
258-
style_sheets[full_path] = 0;
259-
return full_path;
260-
}
261-
for (size_t i = 0, S = include_paths.size(); i < S; ++i) {
262-
string full_path(join_paths(include_paths[i], rel_filepath));
263-
if (style_sheets.count(full_path)) return full_path;
264-
contents = resolve_and_load(full_path, real_path);
265-
if (contents) {
266-
add_source(full_path, real_path, contents);
267-
style_sheets[full_path] = 0;
268-
return full_path;
269-
}
248+
string path(make_canonical_path(file));
249+
string base_file(join_paths(base, path));
250+
string resolved(resolve_file(base_file));
251+
if (style_sheets.count(base_file)) return base_file;
252+
if (char* contents = read_file(resolved)) {
253+
add_source(base_file, resolved, contents);
254+
style_sheets[base_file] = 0;
255+
return base_file;
270256
}
271-
return string();
257+
// now go the regular code path
258+
return add_file(path);
272259
}
273260

274261
void register_function(Context&, Signature sig, Native_Function f, Env* env);

‎context.hpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ namespace Sass {
8484
KWD_ARG(Data, string, linefeed);
8585
KWD_ARG(Data, const char*, include_paths_c_str);
8686
KWD_ARG(Data, const char*, plugin_paths_c_str);
87-
KWD_ARG(Data, const char**, include_paths_array);
88-
KWD_ARG(Data, const char**, plugin_paths_array);
87+
// KWD_ARG(Data, const char**, include_paths_array);
88+
// KWD_ARG(Data, const char**, plugin_paths_array);
8989
KWD_ARG(Data, vector<string>, include_paths);
9090
KWD_ARG(Data, vector<string>, plugin_paths);
9191
KWD_ARG(Data, bool, source_comments);
@@ -104,11 +104,15 @@ namespace Sass {
104104
~Context();
105105
static string get_cwd();
106106
void setup_color_map();
107-
string add_file(string);
107+
108108
Block* parse_file();
109-
string add_file(string, string);
110109
Block* parse_string();
111110
void add_source(string, string, const char*);
111+
112+
string add_file(const string& file);
113+
string add_file(const string& base, const string& file);
114+
115+
112116
// allow to optionally overwrite the input path
113117
// default argument for input_path is string("stdin")
114118
// usefull to influence the source-map generating etc.

0 commit comments

Comments
 (0)
Please sign in to comment.