sassc 2.2.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +18 -0
- data/Rakefile +1 -3
- data/ext/extconf.rb +13 -5
- data/ext/libsass/VERSION +1 -1
- data/ext/libsass/include/sass/base.h +2 -1
- data/ext/libsass/include/sass/context.h +4 -0
- data/ext/libsass/src/MurmurHash2.hpp +91 -0
- data/ext/libsass/src/ast.cpp +158 -168
- data/ext/libsass/src/ast.hpp +389 -230
- data/ext/libsass/src/ast_def_macros.hpp +18 -10
- data/ext/libsass/src/ast_fwd_decl.cpp +4 -3
- data/ext/libsass/src/ast_fwd_decl.hpp +98 -165
- data/ext/libsass/src/ast_helpers.hpp +292 -0
- data/ext/libsass/src/ast_sel_cmp.cpp +219 -732
- data/ext/libsass/src/ast_sel_super.cpp +539 -0
- data/ext/libsass/src/ast_sel_unify.cpp +207 -212
- data/ext/libsass/src/ast_sel_weave.cpp +616 -0
- data/ext/libsass/src/ast_selectors.cpp +594 -1026
- data/ext/libsass/src/ast_selectors.hpp +339 -385
- data/ext/libsass/src/ast_supports.cpp +36 -52
- data/ext/libsass/src/ast_supports.hpp +29 -29
- data/ext/libsass/src/ast_values.cpp +271 -84
- data/ext/libsass/src/ast_values.hpp +116 -107
- data/ext/libsass/src/backtrace.cpp +9 -9
- data/ext/libsass/src/backtrace.hpp +5 -5
- data/ext/libsass/src/base64vlq.cpp +2 -2
- data/ext/libsass/src/base64vlq.hpp +1 -1
- data/ext/libsass/src/bind.cpp +18 -18
- data/ext/libsass/src/bind.hpp +1 -1
- data/ext/libsass/src/c2ast.cpp +3 -3
- data/ext/libsass/src/c2ast.hpp +1 -1
- data/ext/libsass/src/cencode.c +4 -6
- data/ext/libsass/src/check_nesting.cpp +40 -41
- data/ext/libsass/src/check_nesting.hpp +6 -2
- data/ext/libsass/src/color_maps.cpp +14 -13
- data/ext/libsass/src/color_maps.hpp +1 -9
- data/ext/libsass/src/constants.cpp +5 -0
- data/ext/libsass/src/constants.hpp +6 -0
- data/ext/libsass/src/context.cpp +92 -119
- data/ext/libsass/src/context.hpp +41 -53
- data/ext/libsass/src/cssize.cpp +66 -149
- data/ext/libsass/src/cssize.hpp +17 -23
- data/ext/libsass/src/dart_helpers.hpp +199 -0
- data/ext/libsass/src/debugger.hpp +451 -295
- data/ext/libsass/src/emitter.cpp +15 -16
- data/ext/libsass/src/emitter.hpp +10 -12
- data/ext/libsass/src/environment.cpp +27 -27
- data/ext/libsass/src/environment.hpp +29 -24
- data/ext/libsass/src/error_handling.cpp +62 -41
- data/ext/libsass/src/error_handling.hpp +61 -51
- data/ext/libsass/src/eval.cpp +167 -281
- data/ext/libsass/src/eval.hpp +27 -29
- data/ext/libsass/src/eval_selectors.cpp +75 -0
- data/ext/libsass/src/expand.cpp +275 -222
- data/ext/libsass/src/expand.hpp +36 -16
- data/ext/libsass/src/extender.cpp +1188 -0
- data/ext/libsass/src/extender.hpp +399 -0
- data/ext/libsass/src/extension.cpp +43 -0
- data/ext/libsass/src/extension.hpp +89 -0
- data/ext/libsass/src/file.cpp +81 -72
- data/ext/libsass/src/file.hpp +28 -37
- data/ext/libsass/src/fn_colors.cpp +20 -18
- data/ext/libsass/src/fn_lists.cpp +30 -29
- data/ext/libsass/src/fn_maps.cpp +3 -3
- data/ext/libsass/src/fn_miscs.cpp +34 -46
- data/ext/libsass/src/fn_numbers.cpp +20 -13
- data/ext/libsass/src/fn_selectors.cpp +98 -128
- data/ext/libsass/src/fn_strings.cpp +47 -33
- data/ext/libsass/src/fn_utils.cpp +31 -29
- data/ext/libsass/src/fn_utils.hpp +17 -11
- data/ext/libsass/src/inspect.cpp +186 -148
- data/ext/libsass/src/inspect.hpp +31 -29
- data/ext/libsass/src/lexer.cpp +20 -82
- data/ext/libsass/src/lexer.hpp +5 -16
- data/ext/libsass/src/listize.cpp +23 -37
- data/ext/libsass/src/listize.hpp +8 -9
- data/ext/libsass/src/mapping.hpp +1 -0
- data/ext/libsass/src/memory/allocator.cpp +48 -0
- data/ext/libsass/src/memory/allocator.hpp +138 -0
- data/ext/libsass/src/memory/config.hpp +20 -0
- data/ext/libsass/src/memory/memory_pool.hpp +186 -0
- data/ext/libsass/src/memory/{SharedPtr.cpp → shared_ptr.cpp} +2 -2
- data/ext/libsass/src/memory/{SharedPtr.hpp → shared_ptr.hpp} +55 -9
- data/ext/libsass/src/memory.hpp +12 -0
- data/ext/libsass/src/operation.hpp +71 -61
- data/ext/libsass/src/operators.cpp +19 -18
- data/ext/libsass/src/operators.hpp +11 -11
- data/ext/libsass/src/ordered_map.hpp +112 -0
- data/ext/libsass/src/output.cpp +45 -64
- data/ext/libsass/src/output.hpp +6 -6
- data/ext/libsass/src/parser.cpp +512 -700
- data/ext/libsass/src/parser.hpp +89 -97
- data/ext/libsass/src/parser_selectors.cpp +189 -0
- data/ext/libsass/src/permutate.hpp +164 -0
- data/ext/libsass/src/plugins.cpp +7 -7
- data/ext/libsass/src/plugins.hpp +8 -8
- data/ext/libsass/src/position.cpp +7 -26
- data/ext/libsass/src/position.hpp +44 -21
- data/ext/libsass/src/prelexer.cpp +6 -6
- data/ext/libsass/src/remove_placeholders.cpp +55 -56
- data/ext/libsass/src/remove_placeholders.hpp +21 -18
- data/ext/libsass/src/sass.cpp +16 -15
- data/ext/libsass/src/sass.hpp +10 -5
- data/ext/libsass/src/sass2scss.cpp +4 -4
- data/ext/libsass/src/sass_context.cpp +91 -122
- data/ext/libsass/src/sass_context.hpp +2 -2
- data/ext/libsass/src/sass_functions.cpp +1 -1
- data/ext/libsass/src/sass_values.cpp +8 -11
- data/ext/libsass/src/settings.hpp +19 -0
- data/ext/libsass/src/source.cpp +69 -0
- data/ext/libsass/src/source.hpp +95 -0
- data/ext/libsass/src/source_data.hpp +32 -0
- data/ext/libsass/src/source_map.cpp +22 -18
- data/ext/libsass/src/source_map.hpp +12 -9
- data/ext/libsass/src/stylesheet.cpp +22 -0
- data/ext/libsass/src/stylesheet.hpp +57 -0
- data/ext/libsass/src/to_value.cpp +2 -2
- data/ext/libsass/src/to_value.hpp +1 -1
- data/ext/libsass/src/units.cpp +24 -22
- data/ext/libsass/src/units.hpp +8 -8
- data/ext/libsass/src/utf8_string.cpp +9 -10
- data/ext/libsass/src/utf8_string.hpp +7 -6
- data/ext/libsass/src/util.cpp +48 -50
- data/ext/libsass/src/util.hpp +20 -21
- data/ext/libsass/src/util_string.cpp +111 -61
- data/ext/libsass/src/util_string.hpp +62 -8
- data/ext/libsass/src/values.cpp +12 -12
- data/lib/sassc/engine.rb +5 -3
- data/lib/sassc/functions_handler.rb +8 -8
- data/lib/sassc/native.rb +4 -6
- data/lib/sassc/script.rb +4 -4
- data/lib/sassc/version.rb +1 -1
- data/test/functions_test.rb +18 -1
- data/test/native_test.rb +4 -4
- metadata +29 -15
- data/ext/libsass/src/extend.cpp +0 -2132
- data/ext/libsass/src/extend.hpp +0 -86
- data/ext/libsass/src/node.cpp +0 -322
- data/ext/libsass/src/node.hpp +0 -118
- data/ext/libsass/src/paths.hpp +0 -71
- data/ext/libsass/src/sass_util.cpp +0 -152
- data/ext/libsass/src/sass_util.hpp +0 -256
- data/ext/libsass/src/subset_map.cpp +0 -58
- data/ext/libsass/src/subset_map.hpp +0 -76
- data/lib/sassc/native/lib_c.rb +0 -21
data/ext/libsass/src/file.cpp
CHANGED
@@ -13,7 +13,6 @@
|
|
13
13
|
#else
|
14
14
|
# include <unistd.h>
|
15
15
|
#endif
|
16
|
-
#include <cctype>
|
17
16
|
#include <cstdio>
|
18
17
|
#include <vector>
|
19
18
|
#include <algorithm>
|
@@ -25,6 +24,7 @@
|
|
25
24
|
#include "sass_functions.hpp"
|
26
25
|
#include "error_handling.hpp"
|
27
26
|
#include "util.hpp"
|
27
|
+
#include "util_string.hpp"
|
28
28
|
#include "sass2scss.h"
|
29
29
|
|
30
30
|
#ifdef _WIN32
|
@@ -32,16 +32,16 @@
|
|
32
32
|
|
33
33
|
# ifdef _MSC_VER
|
34
34
|
# include <codecvt>
|
35
|
-
inline static
|
35
|
+
inline static Sass::sass::string wstring_to_string(const std::wstring& wstr)
|
36
36
|
{
|
37
37
|
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> wchar_converter;
|
38
38
|
return wchar_converter.to_bytes(wstr);
|
39
39
|
}
|
40
40
|
# else // mingw(/gcc) does not support C++11's codecvt yet.
|
41
|
-
inline static
|
41
|
+
inline static Sass::sass::string wstring_to_string(const std::wstring &wstr)
|
42
42
|
{
|
43
43
|
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
|
44
|
-
|
44
|
+
Sass::sass::string strTo(size_needed, 0);
|
45
45
|
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
|
46
46
|
return strTo;
|
47
47
|
}
|
@@ -54,7 +54,7 @@ namespace Sass {
|
|
54
54
|
// return the current directory
|
55
55
|
// always with forward slashes
|
56
56
|
// always with trailing slash
|
57
|
-
|
57
|
+
sass::string get_cwd()
|
58
58
|
{
|
59
59
|
const size_t wd_len = 4096;
|
60
60
|
#ifndef _WIN32
|
@@ -63,12 +63,12 @@ namespace Sass {
|
|
63
63
|
// we should check error for more detailed info (e.g. ENOENT)
|
64
64
|
// http://man7.org/linux/man-pages/man2/getcwd.2.html#ERRORS
|
65
65
|
if (pwd == NULL) throw Exception::OperationError("cwd gone missing");
|
66
|
-
|
66
|
+
sass::string cwd = pwd;
|
67
67
|
#else
|
68
68
|
wchar_t wd[wd_len];
|
69
69
|
wchar_t* pwd = _wgetcwd(wd, wd_len);
|
70
70
|
if (pwd == NULL) throw Exception::OperationError("cwd gone missing");
|
71
|
-
|
71
|
+
sass::string cwd = wstring_to_string(pwd);
|
72
72
|
//convert backslashes to forward slashes
|
73
73
|
replace(cwd.begin(), cwd.end(), '\\', '/');
|
74
74
|
#endif
|
@@ -77,12 +77,12 @@ namespace Sass {
|
|
77
77
|
}
|
78
78
|
|
79
79
|
// test if path exists and is a file
|
80
|
-
bool file_exists(const
|
80
|
+
bool file_exists(const sass::string& path)
|
81
81
|
{
|
82
82
|
#ifdef _WIN32
|
83
83
|
wchar_t resolved[32768];
|
84
84
|
// windows unicode filepaths are encoded in utf16
|
85
|
-
|
85
|
+
sass::string abspath(join_paths(get_cwd(), path));
|
86
86
|
if (!(abspath[0] == '/' && abspath[1] == '/')) {
|
87
87
|
abspath = "//?/" + abspath;
|
88
88
|
}
|
@@ -103,35 +103,35 @@ namespace Sass {
|
|
103
103
|
|
104
104
|
// return if given path is absolute
|
105
105
|
// works with *nix and windows paths
|
106
|
-
bool is_absolute_path(const
|
106
|
+
bool is_absolute_path(const sass::string& path)
|
107
107
|
{
|
108
108
|
#ifdef _WIN32
|
109
|
-
if (path.length() >= 2 &&
|
109
|
+
if (path.length() >= 2 && Util::ascii_isalpha(path[0]) && path[1] == ':') return true;
|
110
110
|
#endif
|
111
111
|
size_t i = 0;
|
112
112
|
// check if we have a protocol
|
113
|
-
if (path[i] &&
|
113
|
+
if (path[i] && Util::ascii_isalpha(static_cast<unsigned char>(path[i]))) {
|
114
114
|
// skip over all alphanumeric characters
|
115
|
-
while (path[i] &&
|
115
|
+
while (path[i] && Util::ascii_isalnum(static_cast<unsigned char>(path[i]))) ++i;
|
116
116
|
i = i && path[i] == ':' ? i + 1 : 0;
|
117
117
|
}
|
118
118
|
return path[i] == '/';
|
119
119
|
}
|
120
120
|
|
121
|
-
// helper function to find the last directory
|
122
|
-
inline size_t find_last_folder_separator(const
|
121
|
+
// helper function to find the last directory separator
|
122
|
+
inline size_t find_last_folder_separator(const sass::string& path, size_t limit = sass::string::npos)
|
123
123
|
{
|
124
124
|
size_t pos;
|
125
125
|
size_t pos_p = path.find_last_of('/', limit);
|
126
126
|
#ifdef _WIN32
|
127
127
|
size_t pos_w = path.find_last_of('\\', limit);
|
128
128
|
#else
|
129
|
-
size_t pos_w =
|
129
|
+
size_t pos_w = sass::string::npos;
|
130
130
|
#endif
|
131
|
-
if (pos_p !=
|
131
|
+
if (pos_p != sass::string::npos && pos_w != sass::string::npos) {
|
132
132
|
pos = std::max(pos_p, pos_w);
|
133
133
|
}
|
134
|
-
else if (pos_p !=
|
134
|
+
else if (pos_p != sass::string::npos) {
|
135
135
|
pos = pos_p;
|
136
136
|
}
|
137
137
|
else {
|
@@ -141,24 +141,24 @@ namespace Sass {
|
|
141
141
|
}
|
142
142
|
|
143
143
|
// return only the directory part of path
|
144
|
-
|
144
|
+
sass::string dir_name(const sass::string& path)
|
145
145
|
{
|
146
146
|
size_t pos = find_last_folder_separator(path);
|
147
|
-
if (pos ==
|
147
|
+
if (pos == sass::string::npos) return "";
|
148
148
|
else return path.substr(0, pos+1);
|
149
149
|
}
|
150
150
|
|
151
151
|
// return only the filename part of path
|
152
|
-
|
152
|
+
sass::string base_name(const sass::string& path)
|
153
153
|
{
|
154
154
|
size_t pos = find_last_folder_separator(path);
|
155
|
-
if (pos ==
|
155
|
+
if (pos == sass::string::npos) return path;
|
156
156
|
else return path.substr(pos+1);
|
157
157
|
}
|
158
158
|
|
159
159
|
// do a logical clean up of the path
|
160
160
|
// no physical check on the filesystem
|
161
|
-
|
161
|
+
sass::string make_canonical_path (sass::string path)
|
162
162
|
{
|
163
163
|
|
164
164
|
// declarations
|
@@ -170,18 +170,18 @@ namespace Sass {
|
|
170
170
|
#endif
|
171
171
|
|
172
172
|
pos = 0; // remove all self references inside the path string
|
173
|
-
while((pos = path.find("/./", pos)) !=
|
173
|
+
while((pos = path.find("/./", pos)) != sass::string::npos) path.erase(pos, 2);
|
174
174
|
|
175
175
|
// remove all leading and trailing self references
|
176
|
-
while(path.
|
177
|
-
while((pos = path.length()) > 1 && path
|
176
|
+
while(path.size() >= 2 && path[0] == '.' && path[1] == '/') path.erase(0, 2);
|
177
|
+
while((pos = path.length()) > 1 && path[pos - 2] == '/' && path[pos - 1] == '.') path.erase(pos - 2);
|
178
178
|
|
179
179
|
|
180
180
|
size_t proto = 0;
|
181
181
|
// check if we have a protocol
|
182
|
-
if (path[proto] &&
|
182
|
+
if (path[proto] && Util::ascii_isalpha(static_cast<unsigned char>(path[proto]))) {
|
183
183
|
// skip over all alphanumeric characters
|
184
|
-
while (path[proto] &&
|
184
|
+
while (path[proto] && Util::ascii_isalnum(static_cast<unsigned char>(path[proto++]))) {}
|
185
185
|
// then skip over the mandatory colon
|
186
186
|
if (proto && path[proto] == ':') ++ proto;
|
187
187
|
}
|
@@ -190,7 +190,7 @@ namespace Sass {
|
|
190
190
|
while (path[proto++] == '/') {}
|
191
191
|
|
192
192
|
pos = proto; // collapse multiple delimiters into a single one
|
193
|
-
while((pos = path.find("//", pos)) !=
|
193
|
+
while((pos = path.find("//", pos)) != sass::string::npos) path.erase(pos, 1);
|
194
194
|
|
195
195
|
return path;
|
196
196
|
|
@@ -198,7 +198,7 @@ namespace Sass {
|
|
198
198
|
|
199
199
|
// join two path segments cleanly together
|
200
200
|
// but only if right side is not absolute yet
|
201
|
-
|
201
|
+
sass::string join_paths(sass::string l, sass::string r)
|
202
202
|
{
|
203
203
|
|
204
204
|
#ifdef _WIN32
|
@@ -225,16 +225,16 @@ namespace Sass {
|
|
225
225
|
bool is_slash = pos + 2 == L && (l[pos+1] == '/' || l[pos+1] == '\\');
|
226
226
|
bool is_self = pos + 3 == L && (l[pos+1] == '.');
|
227
227
|
if (!is_self && !is_slash) r = r.substr(3);
|
228
|
-
else if (pos ==
|
229
|
-
l = l.substr(0, pos ==
|
228
|
+
else if (pos == sass::string::npos) break;
|
229
|
+
l = l.substr(0, pos == sass::string::npos ? pos : pos + 1);
|
230
230
|
}
|
231
231
|
|
232
232
|
return l + r;
|
233
233
|
}
|
234
234
|
|
235
|
-
|
235
|
+
sass::string path_for_console(const sass::string& rel_path, const sass::string& abs_path, const sass::string& orig_path)
|
236
236
|
{
|
237
|
-
// magic
|
237
|
+
// magic algorithm goes here!!
|
238
238
|
|
239
239
|
// if the file is outside this directory show the absolute path
|
240
240
|
if (rel_path.substr(0, 3) == "../") {
|
@@ -245,24 +245,32 @@ namespace Sass {
|
|
245
245
|
}
|
246
246
|
|
247
247
|
// create an absolute path by resolving relative paths with cwd
|
248
|
-
|
248
|
+
sass::string rel2abs(const sass::string& path, const sass::string& base, const sass::string& cwd)
|
249
249
|
{
|
250
|
-
|
250
|
+
sass::string rv = make_canonical_path(join_paths(join_paths(cwd + "/", base + "/"), path));
|
251
|
+
#ifdef _WIN32
|
252
|
+
// On windows we may get an absolute path without directory
|
253
|
+
// In that case we should prepend the directory from the root
|
254
|
+
if (rv[0] == '/' && rv[1] != '/') {
|
255
|
+
rv.insert(0, cwd, 0, 2);
|
256
|
+
}
|
257
|
+
#endif
|
258
|
+
return rv;
|
251
259
|
}
|
252
260
|
|
253
261
|
// create a path that is relative to the given base directory
|
254
262
|
// path and base will first be resolved against cwd to make them absolute
|
255
|
-
|
263
|
+
sass::string abs2rel(const sass::string& path, const sass::string& base, const sass::string& cwd)
|
256
264
|
{
|
257
265
|
|
258
|
-
|
259
|
-
|
266
|
+
sass::string abs_path = rel2abs(path, cwd);
|
267
|
+
sass::string abs_base = rel2abs(base, cwd);
|
260
268
|
|
261
269
|
size_t proto = 0;
|
262
270
|
// check if we have a protocol
|
263
|
-
if (path[proto] &&
|
271
|
+
if (path[proto] && Util::ascii_isalpha(static_cast<unsigned char>(path[proto]))) {
|
264
272
|
// skip over all alphanumeric characters
|
265
|
-
while (path[proto] &&
|
273
|
+
while (path[proto] && Util::ascii_isalnum(static_cast<unsigned char>(path[proto++]))) {}
|
266
274
|
// then skip over the mandatory colon
|
267
275
|
if (proto && path[proto] == ':') ++ proto;
|
268
276
|
}
|
@@ -277,8 +285,8 @@ namespace Sass {
|
|
277
285
|
if (abs_base[0] != abs_path[0]) return abs_path;
|
278
286
|
#endif
|
279
287
|
|
280
|
-
|
281
|
-
|
288
|
+
sass::string stripped_uri = "";
|
289
|
+
sass::string stripped_base = "";
|
282
290
|
|
283
291
|
size_t index = 0;
|
284
292
|
size_t minSize = std::min(abs_path.size(), abs_base.size());
|
@@ -288,7 +296,8 @@ namespace Sass {
|
|
288
296
|
#else
|
289
297
|
// compare the charactes in a case insensitive manner
|
290
298
|
// windows fs is only case insensitive in ascii ranges
|
291
|
-
if (
|
299
|
+
if (Util::ascii_tolower(static_cast<unsigned char>(abs_path[i])) !=
|
300
|
+
Util::ascii_tolower(static_cast<unsigned char>(abs_base[i]))) break;
|
292
301
|
#endif
|
293
302
|
if (abs_path[i] == '/') index = i + 1;
|
294
303
|
}
|
@@ -316,7 +325,7 @@ namespace Sass {
|
|
316
325
|
}
|
317
326
|
}
|
318
327
|
|
319
|
-
|
328
|
+
sass::string result = "";
|
320
329
|
for (size_t i = 0; i < directories; ++i) {
|
321
330
|
result += "../";
|
322
331
|
}
|
@@ -332,16 +341,16 @@ namespace Sass {
|
|
332
341
|
// (4) given + extension
|
333
342
|
// (5) given + _index.scss
|
334
343
|
// (6) given + _index.sass
|
335
|
-
|
344
|
+
sass::vector<Include> resolve_includes(const sass::string& root, const sass::string& file, const sass::vector<sass::string>& exts)
|
336
345
|
{
|
337
|
-
|
346
|
+
sass::string filename = join_paths(root, file);
|
338
347
|
// split the filename
|
339
|
-
|
340
|
-
|
341
|
-
|
348
|
+
sass::string base(dir_name(file));
|
349
|
+
sass::string name(base_name(file));
|
350
|
+
sass::vector<Include> includes;
|
342
351
|
// create full path (maybe relative)
|
343
|
-
|
344
|
-
|
352
|
+
sass::string rel_path(join_paths(base, name));
|
353
|
+
sass::string abs_path(join_paths(root, rel_path));
|
345
354
|
if (file_exists(abs_path)) includes.push_back({{ rel_path, root }, abs_path });
|
346
355
|
// next test variation with underscore
|
347
356
|
rel_path = join_paths(base, "_" + name);
|
@@ -382,24 +391,24 @@ namespace Sass {
|
|
382
391
|
return includes;
|
383
392
|
}
|
384
393
|
|
385
|
-
|
394
|
+
sass::vector<sass::string> find_files(const sass::string& file, const sass::vector<sass::string> paths)
|
386
395
|
{
|
387
|
-
|
388
|
-
for (
|
389
|
-
|
396
|
+
sass::vector<sass::string> includes;
|
397
|
+
for (sass::string path : paths) {
|
398
|
+
sass::string abs_path(join_paths(path, file));
|
390
399
|
if (file_exists(abs_path)) includes.push_back(abs_path);
|
391
400
|
}
|
392
401
|
return includes;
|
393
402
|
}
|
394
403
|
|
395
|
-
|
404
|
+
sass::vector<sass::string> find_files(const sass::string& file, struct Sass_Compiler* compiler)
|
396
405
|
{
|
397
406
|
// get the last import entry to get current base directory
|
398
407
|
// struct Sass_Options* options = sass_compiler_get_options(compiler);
|
399
408
|
Sass_Import_Entry import = sass_compiler_get_last_import(compiler);
|
400
|
-
const
|
409
|
+
const sass::vector<sass::string>& incs = compiler->cpp_ctx->include_paths;
|
401
410
|
// create the vector with paths to lookup
|
402
|
-
|
411
|
+
sass::vector<sass::string> paths(1 + incs.size());
|
403
412
|
paths.push_back(dir_name(import->abs_path));
|
404
413
|
paths.insert(paths.end(), incs.begin(), incs.end());
|
405
414
|
// dispatch to find files in paths
|
@@ -408,7 +417,7 @@ namespace Sass {
|
|
408
417
|
|
409
418
|
// helper function to search one file in all include paths
|
410
419
|
// this is normally not used internally by libsass (C-API sugar)
|
411
|
-
|
420
|
+
sass::string find_file(const sass::string& file, const sass::vector<sass::string> paths)
|
412
421
|
{
|
413
422
|
if (file.empty()) return file;
|
414
423
|
auto res = find_files(file, paths);
|
@@ -416,29 +425,29 @@ namespace Sass {
|
|
416
425
|
}
|
417
426
|
|
418
427
|
// helper function to resolve a filename
|
419
|
-
|
428
|
+
sass::string find_include(const sass::string& file, const sass::vector<sass::string> paths)
|
420
429
|
{
|
421
430
|
// search in every include path for a match
|
422
431
|
for (size_t i = 0, S = paths.size(); i < S; ++i)
|
423
432
|
{
|
424
|
-
|
433
|
+
sass::vector<Include> resolved(resolve_includes(paths[i], file));
|
425
434
|
if (resolved.size()) return resolved[0].abs_path;
|
426
435
|
}
|
427
436
|
// nothing found
|
428
|
-
return
|
437
|
+
return sass::string("");
|
429
438
|
}
|
430
439
|
|
431
440
|
// try to load the given filename
|
432
441
|
// returned memory must be freed
|
433
442
|
// will auto convert .sass files
|
434
|
-
char* read_file(const
|
443
|
+
char* read_file(const sass::string& path)
|
435
444
|
{
|
436
445
|
#ifdef _WIN32
|
437
446
|
BYTE* pBuffer;
|
438
447
|
DWORD dwBytes;
|
439
448
|
wchar_t resolved[32768];
|
440
449
|
// windows unicode filepaths are encoded in utf16
|
441
|
-
|
450
|
+
sass::string abspath(join_paths(get_cwd(), path));
|
442
451
|
if (!(abspath[0] == '/' && abspath[1] == '/')) {
|
443
452
|
abspath = "//?/" + abspath;
|
444
453
|
}
|
@@ -474,6 +483,7 @@ namespace Sass {
|
|
474
483
|
char* contents = static_cast<char*>(malloc(st.st_size + 2 * sizeof(char)));
|
475
484
|
if (std::fread(static_cast<void*>(contents), 1, size, fd) != size) {
|
476
485
|
free(contents);
|
486
|
+
std::fclose(fd);
|
477
487
|
return nullptr;
|
478
488
|
}
|
479
489
|
if (std::fclose(fd) != 0) {
|
@@ -483,12 +493,11 @@ namespace Sass {
|
|
483
493
|
contents[size] = '\0';
|
484
494
|
contents[size + 1] = '\0';
|
485
495
|
#endif
|
486
|
-
|
496
|
+
sass::string extension;
|
487
497
|
if (path.length() > 5) {
|
488
498
|
extension = path.substr(path.length() - 5, 5);
|
489
499
|
}
|
490
|
-
|
491
|
-
extension[i] = tolower(extension[i]);
|
500
|
+
Util::ascii_str_tolower(&extension);
|
492
501
|
if (extension == ".sass" && contents != 0) {
|
493
502
|
char * converted = sass2scss(contents, SASS2SCSS_PRETTIFY_1 | SASS2SCSS_KEEP_COMMENT);
|
494
503
|
free(contents); // free the indented contents
|
@@ -499,21 +508,21 @@ namespace Sass {
|
|
499
508
|
}
|
500
509
|
|
501
510
|
// split a path string delimited by semicolons or colons (OS dependent)
|
502
|
-
|
511
|
+
sass::vector<sass::string> split_path_list(const char* str)
|
503
512
|
{
|
504
|
-
|
513
|
+
sass::vector<sass::string> paths;
|
505
514
|
if (str == NULL) return paths;
|
506
515
|
// find delimiter via prelexer (return zero at end)
|
507
516
|
const char* end = Prelexer::find_first<PATH_SEP>(str);
|
508
517
|
// search until null delimiter
|
509
518
|
while (end) {
|
510
519
|
// add path from current position to delimiter
|
511
|
-
paths.push_back(
|
520
|
+
paths.push_back(sass::string(str, end - str));
|
512
521
|
str = end + 1; // skip delimiter
|
513
522
|
end = Prelexer::find_first<PATH_SEP>(str);
|
514
523
|
}
|
515
524
|
// add path from current position to end
|
516
|
-
paths.push_back(
|
525
|
+
paths.push_back(sass::string(str));
|
517
526
|
// return back
|
518
527
|
return paths;
|
519
528
|
}
|
data/ext/libsass/src/file.hpp
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
#ifndef SASS_FILE_H
|
2
2
|
#define SASS_FILE_H
|
3
3
|
|
4
|
+
// sass.hpp must go before all system headers to get the
|
5
|
+
// __EXTENSIONS__ fix on Solaris.
|
6
|
+
#include "sass.hpp"
|
7
|
+
|
4
8
|
#include <string>
|
5
9
|
#include <vector>
|
6
10
|
|
@@ -13,56 +17,56 @@ namespace Sass {
|
|
13
17
|
|
14
18
|
// return the current directory
|
15
19
|
// always with forward slashes
|
16
|
-
|
20
|
+
sass::string get_cwd();
|
17
21
|
|
18
22
|
// test if path exists and is a file
|
19
|
-
bool file_exists(const
|
23
|
+
bool file_exists(const sass::string& file);
|
20
24
|
|
21
25
|
// return if given path is absolute
|
22
26
|
// works with *nix and windows paths
|
23
|
-
bool is_absolute_path(const
|
27
|
+
bool is_absolute_path(const sass::string& path);
|
24
28
|
|
25
29
|
// return only the directory part of path
|
26
|
-
|
30
|
+
sass::string dir_name(const sass::string& path);
|
27
31
|
|
28
32
|
// return only the filename part of path
|
29
|
-
|
33
|
+
sass::string base_name(const sass::string&);
|
30
34
|
|
31
35
|
// do a locigal clean up of the path
|
32
36
|
// no physical check on the filesystem
|
33
|
-
|
37
|
+
sass::string make_canonical_path (sass::string path);
|
34
38
|
|
35
39
|
// join two path segments cleanly together
|
36
40
|
// but only if right side is not absolute yet
|
37
|
-
|
41
|
+
sass::string join_paths(sass::string root, sass::string name);
|
38
42
|
|
39
43
|
// if the relative path is outside of the cwd we want want to
|
40
44
|
// show the absolute path in console messages
|
41
|
-
|
45
|
+
sass::string path_for_console(const sass::string& rel_path, const sass::string& abs_path, const sass::string& orig_path);
|
42
46
|
|
43
47
|
// create an absolute path by resolving relative paths with cwd
|
44
|
-
|
48
|
+
sass::string rel2abs(const sass::string& path, const sass::string& base = ".", const sass::string& cwd = get_cwd());
|
45
49
|
|
46
50
|
// create a path that is relative to the given base directory
|
47
51
|
// path and base will first be resolved against cwd to make them absolute
|
48
|
-
|
52
|
+
sass::string abs2rel(const sass::string& path, const sass::string& base = ".", const sass::string& cwd = get_cwd());
|
49
53
|
|
50
54
|
// helper function to resolve a filename
|
51
55
|
// searching without variations in all paths
|
52
|
-
|
53
|
-
|
56
|
+
sass::string find_file(const sass::string& file, struct Sass_Compiler* options);
|
57
|
+
sass::string find_file(const sass::string& file, const sass::vector<sass::string> paths);
|
54
58
|
|
55
59
|
// helper function to resolve a include filename
|
56
60
|
// this has the original resolve logic for sass include
|
57
|
-
|
61
|
+
sass::string find_include(const sass::string& file, const sass::vector<sass::string> paths);
|
58
62
|
|
59
63
|
// split a path string delimited by semicolons or colons (OS dependent)
|
60
|
-
|
64
|
+
sass::vector<sass::string> split_path_list(const char* paths);
|
61
65
|
|
62
66
|
// try to load the given filename
|
63
67
|
// returned memory must be freed
|
64
68
|
// will auto convert .sass files
|
65
|
-
char* read_file(const
|
69
|
+
char* read_file(const sass::string& file);
|
66
70
|
|
67
71
|
}
|
68
72
|
|
@@ -70,14 +74,14 @@ namespace Sass {
|
|
70
74
|
class Importer {
|
71
75
|
public:
|
72
76
|
// requested import path
|
73
|
-
|
77
|
+
sass::string imp_path;
|
74
78
|
// parent context path
|
75
|
-
|
79
|
+
sass::string ctx_path;
|
76
80
|
// base derived from context path
|
77
81
|
// this really just acts as a cache
|
78
|
-
|
82
|
+
sass::string base_path;
|
79
83
|
public:
|
80
|
-
Importer(
|
84
|
+
Importer(sass::string imp_path, sass::string ctx_path)
|
81
85
|
: imp_path(File::make_canonical_path(imp_path)),
|
82
86
|
ctx_path(File::make_canonical_path(ctx_path)),
|
83
87
|
base_path(File::dir_name(ctx_path))
|
@@ -88,9 +92,9 @@ namespace Sass {
|
|
88
92
|
class Include : public Importer {
|
89
93
|
public:
|
90
94
|
// resolved absolute path
|
91
|
-
|
95
|
+
sass::string abs_path;
|
92
96
|
public:
|
93
|
-
Include(const Importer& imp,
|
97
|
+
Include(const Importer& imp, sass::string abs_path)
|
94
98
|
: Importer(imp), abs_path(abs_path)
|
95
99
|
{ }
|
96
100
|
};
|
@@ -100,7 +104,7 @@ namespace Sass {
|
|
100
104
|
public:
|
101
105
|
// the file contents
|
102
106
|
char* contents;
|
103
|
-
//
|
107
|
+
// connected sourcemap
|
104
108
|
char* srcmap;
|
105
109
|
public:
|
106
110
|
Resource(char* contents, char* srcmap)
|
@@ -108,23 +112,10 @@ namespace Sass {
|
|
108
112
|
{ }
|
109
113
|
};
|
110
114
|
|
111
|
-
// parsed stylesheet from loaded resource
|
112
|
-
class StyleSheet : public Resource {
|
113
|
-
public:
|
114
|
-
// parsed root block
|
115
|
-
Block_Obj root;
|
116
|
-
public:
|
117
|
-
StyleSheet(const Resource& res, Block_Obj root)
|
118
|
-
: Resource(res), root(root)
|
119
|
-
{ }
|
120
|
-
};
|
121
|
-
|
122
115
|
namespace File {
|
123
116
|
|
124
|
-
|
125
|
-
|
126
|
-
std::vector<Include> resolve_includes(const std::string& root, const std::string& file,
|
127
|
-
const std::vector<std::string>& exts = defaultExtensions);
|
117
|
+
sass::vector<Include> resolve_includes(const sass::string& root, const sass::string& file,
|
118
|
+
const sass::vector<sass::string>& exts = { ".scss", ".sass", ".css" });
|
128
119
|
|
129
120
|
}
|
130
121
|
|