Skip to content

Commit b1ce9a8

Browse files
committed
Merge pull request #505 from mgreter/fix/sass_interface_api
Straightens out some sass_interface api issues
2 parents 3e9e074 + 0dbcec4 commit b1ce9a8

File tree

7 files changed

+35
-43
lines changed

7 files changed

+35
-43
lines changed

context.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ namespace Sass {
5555
image_path (initializers.image_path()),
5656
output_path (make_canonical_path(initializers.output_path())),
5757
source_comments (initializers.source_comments()),
58-
source_maps (initializers.source_maps()),
5958
output_style (initializers.output_style()),
6059
source_map_file (make_canonical_path(initializers.source_map_file())),
6160
omit_source_map_url (initializers.omit_source_map_url()),
@@ -270,7 +269,7 @@ namespace Sass {
270269

271270
char* Context::generate_source_map()
272271
{
273-
if (!source_maps) return 0;
272+
if (source_map_file == "") return 0;
274273
char* result = 0;
275274
string map = source_map.generate_source_map();
276275
result = copy_c_str(map.c_str());

context.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,10 @@ namespace Sass {
5050

5151
string image_path; // for the image-url Sass function
5252
string output_path; // for relative paths to the output
53-
bool source_comments;
54-
bool source_maps;
55-
Output_Style output_style;
56-
string source_map_file;
57-
bool omit_source_map_url;
53+
bool source_comments; // for inline debug comments in css output
54+
Output_Style output_style; // output style for the generated css code
55+
string source_map_file; // path to source map file (enables feature)
56+
bool omit_source_map_url; // disable source map comment in css output
5857

5958
map<string, Color*> names_to_colors;
6059
map<int, string> colors_to_names;
@@ -70,7 +69,6 @@ namespace Sass {
7069
KWD_ARG(Data, const char**, include_paths_array);
7170
KWD_ARG(Data, vector<string>, include_paths);
7271
KWD_ARG(Data, bool, source_comments);
73-
KWD_ARG(Data, bool, source_maps);
7472
KWD_ARG(Data, Output_Style, output_style);
7573
KWD_ARG(Data, string, source_map_file);
7674
KWD_ARG(Data, bool, omit_source_map_url);

sass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ extern "C" {
4545
c_ctx->output_style)
4646

4747
.source_comments (c_ctx->source_comments)
48-
.source_maps (c_ctx->source_maps)
48+
.source_map_file (c_ctx->source_map_file)
49+
.omit_source_map_url (c_ctx->omit_source_map_url)
4950

5051
.image_path (c_ctx->image_path ?
5152
c_ctx->image_path :

sass.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ struct Sass_Context {
2323

2424
int output_style;
2525
bool source_comments;
26-
int source_maps;
26+
const char* source_map_file;
27+
bool omit_source_map_url;
2728
const char* image_path;
2829
const char* output_path;
2930
const char* include_paths_string;

sass_interface.cpp

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,16 @@ extern "C" {
8383
*n = num;
8484
}
8585

86+
// helper for safe access to c_ctx
87+
const char* safe_str (const char* str) {
88+
return str == NULL ? "" : str;
89+
}
90+
8691
int sass_compile(sass_context* c_ctx)
8792
{
8893
using namespace Sass;
8994
try {
90-
bool source_maps = false;
91-
string source_map_file = "";
92-
if (c_ctx->source_map_file && c_ctx->options.source_comments) {
93-
source_maps = true;
94-
source_map_file = c_ctx->source_map_file;
95-
}
96-
string input_path = c_ctx->input_path ? c_ctx->input_path : "";
95+
string input_path = safe_str(c_ctx->input_path);
9796
int lastindex = input_path.find_last_of(".");
9897
string output_path;
9998
if (!c_ctx->output_path) {
@@ -108,13 +107,10 @@ extern "C" {
108107
Context::Data().source_c_str(c_ctx->source_string)
109108
.output_path(output_path)
110109
.output_style((Output_Style) c_ctx->options.output_style)
111-
.source_comments(!c_ctx->options.source_comments)
112-
.source_maps(source_maps)
113-
.source_map_file(source_map_file)
110+
.source_comments(c_ctx->options.source_comments)
111+
.source_map_file(safe_str(c_ctx->options.source_map_file))
114112
.omit_source_map_url(c_ctx->options.omit_source_map_url)
115-
.image_path(c_ctx->options.image_path ?
116-
c_ctx->options.image_path :
117-
"")
113+
.image_path(safe_str(c_ctx->options.image_path))
118114
.include_paths_c_str(c_ctx->options.include_paths)
119115
.include_paths_array(0)
120116
.include_paths(vector<string>())
@@ -184,13 +180,7 @@ extern "C" {
184180
{
185181
using namespace Sass;
186182
try {
187-
bool source_maps = false;
188-
string source_map_file = "";
189-
if (c_ctx->source_map_file && c_ctx->options.source_comments) {
190-
source_maps = true;
191-
source_map_file = c_ctx->source_map_file;
192-
}
193-
string input_path = c_ctx->input_path ? c_ctx->input_path : "";
183+
string input_path = safe_str(c_ctx->input_path);
194184
int lastindex = input_path.find_last_of(".");
195185
string output_path;
196186
if (!c_ctx->output_path) {
@@ -203,13 +193,10 @@ extern "C" {
203193
Context::Data().entry_point(input_path)
204194
.output_path(output_path)
205195
.output_style((Output_Style) c_ctx->options.output_style)
206-
.source_comments(!c_ctx->options.source_comments)
207-
.source_maps(source_maps)
208-
.source_map_file(source_map_file)
196+
.source_comments(c_ctx->options.source_comments)
197+
.source_map_file(safe_str(c_ctx->options.source_map_file))
209198
.omit_source_map_url(c_ctx->options.omit_source_map_url)
210-
.image_path(c_ctx->options.image_path ?
211-
c_ctx->options.image_path :
212-
"")
199+
.image_path(safe_str(c_ctx->options.image_path))
213200
.include_paths_c_str(c_ctx->options.include_paths)
214201
.include_paths_array(0)
215202
.include_paths(vector<string>())

sass_interface.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,24 @@ extern "C" {
1616
// Please ensure there are no null values.
1717
// Thar be dragons.
1818
struct sass_options {
19-
// A value defined above in SASS_STYLE_* constants
19+
// Output style for the generated css code
20+
// A value from above SASS_STYLE_* constants
2021
int output_style;
2122
// If you want inline source comments
2223
bool source_comments;
23-
// colon-separated list of paths (semicolon-separated if you're on Windows)
24+
// Path to source map file
25+
// Enables the source map generating
26+
// Used to create sourceMappingUrl
27+
const char* source_map_file;
28+
// Disable sourceMappingUrl in css output
29+
bool omit_source_map_url;
30+
// Colon-separated list of paths
31+
// Semicolon-separated on Windows
2432
const char* include_paths;
33+
// For the image-url Sass function
2534
const char* image_path;
26-
// Positive integer
35+
// Precision for outputting fractional numbers
2736
int precision;
28-
bool omit_source_map_url;
2937
};
3038

3139
struct sass_context {
@@ -34,7 +42,6 @@ struct sass_context {
3442
const char* source_string;
3543
char* output_string;
3644
char* source_map_string;
37-
const char* source_map_file;
3845
struct sass_options options;
3946
int error_status;
4047
char* error_message;
@@ -48,7 +55,6 @@ struct sass_file_context {
4855
const char* output_path;
4956
char* output_string;
5057
char* source_map_string;
51-
const char* source_map_file;
5258
struct sass_options options;
5359
int error_status;
5460
char* error_message;

script/bootstrap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ if [ ! -d "sass-spec" ]; then
66
git clone https://github.com/sass/sass-spec.git
77
fi
88
if [ ! -d "sassc" ]; then
9-
git clone -b feature/extra-env-variables https://github.com/mgreter/sassc.git
9+
git clone https://github.com/sass/sassc.git
1010
fi

0 commit comments

Comments
 (0)