From ef00e62489b152b9a8e7fb4632dff502784770ec Mon Sep 17 00:00:00 2001 From: Adeel Date: Sat, 12 Jul 2014 17:36:22 +0300 Subject: [PATCH 1/2] SourceMap: Fix relative paths for Windows. (#242) It required converting all paths to lower-case, the rest of the implementation was there. This lower-casing is not locale-aware, as NTFS is all case-sensitive when it goes beyond ASCII. --- file.cpp | 18 +++++++++++++++++- file.hpp | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/file.cpp b/file.cpp index e958e3ab0b..bf851e865d 100644 --- a/file.cpp +++ b/file.cpp @@ -82,8 +82,24 @@ namespace Sass { return (is_absolute_path(path) ? path : join_paths(cwd, path)); } - string resolve_relative_path(const string& uri, const string& base, const string& cwd) + string resolve_relative_path(const string& uri, const string& base, const string& cwd, const bool recurse) { + if (!recurse) { + #ifdef _WIN32 + // Convert all paths to lower case for Windows + string uri2(uri); + transform(uri.begin(), uri.end(), uri2.begin(), tolower); + + string base2(base); + transform(base.begin(), base.end(), base2.begin(), tolower); + + string cwd2(cwd); + transform(cwd.begin(), cwd.end(), cwd2.begin(), tolower); + + return resolve_relative_path(uri2, base2, cwd2, true); + #endif + } + string absolute_uri = make_absolute_path(uri, cwd); string absolute_base = make_absolute_path(base, cwd); diff --git a/file.hpp b/file.hpp index e095040cda..6fd8e93b8a 100644 --- a/file.hpp +++ b/file.hpp @@ -9,7 +9,7 @@ namespace Sass { string join_paths(string, string); bool is_absolute_path(const string& path); string make_absolute_path(const string& path, const string& cwd); - string resolve_relative_path(const string& uri, const string& base, const string& cwd); + string resolve_relative_path(const string& uri, const string& base, const string& cwd, const bool recurse=false); char* resolve_and_load(string path, string& real_path); char* read_file(string path); } From bbc02f32bb1d5dea61d2e024cb0ffe85b99174b1 Mon Sep 17 00:00:00 2001 From: Adeel Date: Sat, 12 Jul 2014 20:17:18 +0300 Subject: [PATCH 2/2] Interface: Use input filename to contruct the default value of output. --- sass_interface.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/sass_interface.cpp b/sass_interface.cpp index 49fd1fbb47..c3f3803eea 100644 --- a/sass_interface.cpp +++ b/sass_interface.cpp @@ -93,12 +93,18 @@ extern "C" { source_maps = true; source_map_file = c_ctx->source_map_file; } - string output_path = c_ctx->output_path ? c_ctx->output_path : ""; + string input_path = c_ctx->input_path ? c_ctx->input_path : ""; + int lastindex = input_path.find_last_of("."); + string output_path; + if (!c_ctx->output_path) { + output_path = (lastindex > -1 ? input_path.substr(0, lastindex) : input_path) + ".css"; + } + else { + output_path = c_ctx->output_path; + } Context cpp_ctx( Context::Data().source_c_str(c_ctx->source_string) - .entry_point(c_ctx->input_path ? - c_ctx->input_path : - "") + .entry_point(input_path) .output_path(output_path) .output_style((Output_Style) c_ctx->options.output_style) .source_comments(c_ctx->options.source_comments == SASS_SOURCE_COMMENTS_DEFAULT) @@ -156,11 +162,17 @@ extern "C" { source_maps = true; source_map_file = c_ctx->source_map_file; } - string output_path = c_ctx->output_path ? c_ctx->output_path : ""; + string input_path = c_ctx->input_path ? c_ctx->input_path : ""; + int lastindex = input_path.find_last_of("."); + string output_path; + if (!c_ctx->output_path) { + output_path = (lastindex > -1 ? input_path.substr(0, lastindex) : input_path) + ".css"; + } + else { + output_path = c_ctx->output_path; + } Context cpp_ctx( - Context::Data().entry_point(c_ctx->input_path ? - c_ctx->input_path : - "") + Context::Data().entry_point(input_path) .output_path(output_path) .output_style((Output_Style) c_ctx->options.output_style) .source_comments(c_ctx->options.source_comments == SASS_SOURCE_COMMENTS_DEFAULT)