Skip to content

Commit

Permalink
Prepare context for refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Nov 1, 2015
1 parent 7249944 commit 05c176e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 39 deletions.
18 changes: 8 additions & 10 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ namespace Sass {
linefeed (initializers.linefeed()),
input_path (make_canonical_path(initializers.input_path())),
output_path (make_canonical_path(initializers.output_path())),
source_comments (initializers.source_comments()),
output_style (initializers.output_style()),
source_map_file (make_canonical_path(initializers.source_map_file())),
source_map_root (initializers.source_map_root()), // pass-through
source_comments (initializers.source_comments()),
output_style (initializers.output_style()),
source_map_embed (initializers.source_map_embed()),
source_map_contents (initializers.source_map_contents()),
omit_source_map_url (initializers.omit_source_map_url()),
Expand Down Expand Up @@ -181,10 +181,9 @@ namespace Sass {

void Context::collect_include_paths(const char** paths_array)
{
if (paths_array) {
for (size_t i = 0; paths_array[i]; i++) {
collect_include_paths(paths_array[i]);
}
if (!paths_array) return;
for (size_t i = 0; paths_array[i]; i++) {
collect_include_paths(paths_array[i]);
}
}

Expand Down Expand Up @@ -215,10 +214,9 @@ namespace Sass {

void Context::collect_plugin_paths(const char** paths_array)
{
if (paths_array) {
for (size_t i = 0; paths_array[i]; i++) {
collect_plugin_paths(paths_array[i]);
}
if (!paths_array) return;
for (size_t i = 0; paths_array[i]; i++) {
collect_plugin_paths(paths_array[i]);
}
}
void Context::add_source(std::string load_path, std::string abs_path, char* contents)
Expand Down
22 changes: 12 additions & 10 deletions src/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Sass {
std::vector<char*> strings;
// absolute paths to includes
std::vector<std::string> included_files;
// relative links to includes
// relative includes for sourcemap
std::vector<std::string> srcmap_links;
// vectors above have same size

Expand All @@ -58,14 +58,19 @@ namespace Sass {
void add_c_importer(Sass_Importer_Entry importer);
void add_c_function(Sass_Function_Entry function);

std::string indent; // String to be used for indentation
std::string linefeed; // String to be used for line feeds
std::string input_path; // for relative paths in src-map
std::string output_path; // for relative paths to the output
std::string indent; // String to be used for indentation
std::string linefeed; // String to be used for line feeds
std::string input_path; // for relative paths in src-map
std::string output_path; // for relative paths to the output
std::string source_map_file; // path to source map file (enables feature)
std::string source_map_root; // path for sourceRoot property (pass-through)

virtual ~Context();
virtual char* render(Block* root);
virtual char* render_srcmap();

bool source_comments; // for inline debug comments in css output
Sass_Output_Style output_style; // output style for the generated css code
std::string source_map_file; // path to source map file (enables feature)
std::string source_map_root; // path for sourceRoot property (pass-through)
bool source_map_embed; // embed in sourceMappingUrl (as data-url)
bool source_map_contents; // insert included contents into source map
bool omit_source_map_url; // disable source map comment in css output
Expand Down Expand Up @@ -103,7 +108,6 @@ namespace Sass {
};

Context(Data);
~Context();
static std::string get_cwd();

Block* parse_file();
Expand All @@ -120,8 +124,6 @@ namespace Sass {
// usefull to influence the source-map generating etc.
char* compile_file();
char* compile_string();
char* render(Block* root);
char* render_srcmap();

std::vector<std::string> get_included_files(bool skip = false, size_t headers = 0);

Expand Down
4 changes: 3 additions & 1 deletion src/expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,15 @@ namespace Sass {
Statement* Expand::operator()(Import* imp)
{
Import* result = SASS_MEMORY_NEW(ctx.mem, Import, imp->pstate());
if (imp->media_queries()) {
if (imp->media_queries() && imp->media_queries()->size()) {
Expression* ex = imp->media_queries()->perform(&eval);
result->media_queries(dynamic_cast<List*>(ex));
}
for ( size_t i = 0, S = imp->urls().size(); i < S; ++i) {
result->urls().push_back(imp->urls()[i]->perform(&eval));
}
// all resources have been dropped for Input_Stubs
// for ( size_t i = 0, S = imp->incs().size(); i < S; ++i) {}
return result;
}

Expand Down
34 changes: 17 additions & 17 deletions src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace Sass {
else return path.substr(pos+1);
}

// do a locigal clean up of the path
// do a logical clean up of the path
// no physical check on the filesystem
std::string make_canonical_path (std::string path)
{
Expand Down Expand Up @@ -200,51 +200,51 @@ namespace Sass {

// create a path that is relative to the given base directory
// path and base will first be resolved against cwd to make them absolute
std::string abs2rel(const std::string& uri, const std::string& base, const std::string& cwd)
std::string abs2rel(const std::string& path, const std::string& base, const std::string& cwd)
{

std::string absolute_uri = rel2abs(uri, cwd);
std::string absolute_base = rel2abs(base, cwd);
std::string abs_path = rel2abs(path, cwd);
std::string abs_base = rel2abs(base, cwd);

size_t proto = 0;
// check if we have a protocol
if (uri[proto] && Prelexer::is_alpha(uri[proto])) {
if (path[proto] && Prelexer::is_alpha(path[proto])) {
// skip over all alphanumeric characters
while (uri[proto] && Prelexer::is_alnum(uri[proto++])) {}
while (path[proto] && Prelexer::is_alnum(path[proto++])) {}
// then skip over the mandatory colon
if (proto && uri[proto] == ':') ++ proto;
if (proto && path[proto] == ':') ++ proto;
}

// distinguish between windows absolute paths and valid protocols
// we assume that protocols must at least have two chars to be valid
if (proto && uri[proto++] == '/' && proto > 3) return uri;
if (proto && path[proto++] == '/' && proto > 3) return path;

#ifdef _WIN32
// absolute link must have a drive letter, and we know that we
// can only create relative links if both are on the same drive
if (absolute_base[0] != absolute_uri[0]) return absolute_uri;
if (abs_base[0] != abs_path[0]) return abs_path;
#endif

std::string stripped_uri = "";
std::string stripped_base = "";

size_t index = 0;
size_t minSize = std::min(absolute_uri.size(), absolute_base.size());
size_t minSize = std::min(abs_path.size(), abs_base.size());
for (size_t i = 0; i < minSize; ++i) {
#ifdef FS_CASE_SENSITIVE
if (absolute_uri[i] != absolute_base[i]) break;
if (abs_path[i] != abs_base[i]) break;
#else
// compare the charactes in a case insensitive manner
// windows fs is only case insensitive in ascii ranges
if (tolower(absolute_uri[i]) != tolower(absolute_base[i])) break;
if (tolower(abs_path[i]) != tolower(abs_base[i])) break;
#endif
if (absolute_uri[i] == '/') index = i + 1;
if (abs_path[i] == '/') index = i + 1;
}
for (size_t i = index; i < absolute_uri.size(); ++i) {
stripped_uri += absolute_uri[i];
for (size_t i = index; i < abs_path.size(); ++i) {
stripped_uri += abs_path[i];
}
for (size_t i = index; i < absolute_base.size(); ++i) {
stripped_base += absolute_base[i];
for (size_t i = index; i < abs_base.size(); ++i) {
stripped_base += abs_base[i];
}

size_t left = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ static bool parse_object(const char **sp, JsonNode **out)
bool parse_string(const char **sp, char **out)
{
const char *s = *sp;
SB sb = { 0, 0, 0};
SB sb = { 0, 0, 0 };
char throwaway_buffer[4];
/* enough space for a UTF-8 character */
char *b;
Expand Down

0 comments on commit 05c176e

Please sign in to comment.