Skip to content

Commit

Permalink
Merge pull request sass#505 from mgreter/fix/sass_interface_api
Browse files Browse the repository at this point in the history
Straightens out some sass_interface api issues
  • Loading branch information
HamptonMakes committed Oct 5, 2014
2 parents 3e9e074 + 0dbcec4 commit b1ce9a8
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 43 deletions.
3 changes: 1 addition & 2 deletions context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ namespace Sass {
image_path (initializers.image_path()),
output_path (make_canonical_path(initializers.output_path())),
source_comments (initializers.source_comments()),
source_maps (initializers.source_maps()),
output_style (initializers.output_style()),
source_map_file (make_canonical_path(initializers.source_map_file())),
omit_source_map_url (initializers.omit_source_map_url()),
Expand Down Expand Up @@ -270,7 +269,7 @@ namespace Sass {

char* Context::generate_source_map()
{
if (!source_maps) return 0;
if (source_map_file == "") return 0;
char* result = 0;
string map = source_map.generate_source_map();
result = copy_c_str(map.c_str());
Expand Down
10 changes: 4 additions & 6 deletions context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ namespace Sass {

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

map<string, Color*> names_to_colors;
map<int, string> colors_to_names;
Expand All @@ -70,7 +69,6 @@ namespace Sass {
KWD_ARG(Data, const char**, include_paths_array);
KWD_ARG(Data, vector<string>, include_paths);
KWD_ARG(Data, bool, source_comments);
KWD_ARG(Data, bool, source_maps);
KWD_ARG(Data, Output_Style, output_style);
KWD_ARG(Data, string, source_map_file);
KWD_ARG(Data, bool, omit_source_map_url);
Expand Down
3 changes: 2 additions & 1 deletion sass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ extern "C" {
c_ctx->output_style)

.source_comments (c_ctx->source_comments)
.source_maps (c_ctx->source_maps)
.source_map_file (c_ctx->source_map_file)
.omit_source_map_url (c_ctx->omit_source_map_url)

.image_path (c_ctx->image_path ?
c_ctx->image_path :
Expand Down
3 changes: 2 additions & 1 deletion sass.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ struct Sass_Context {

int output_style;
bool source_comments;
int source_maps;
const char* source_map_file;
bool omit_source_map_url;
const char* image_path;
const char* output_path;
const char* include_paths_string;
Expand Down
39 changes: 13 additions & 26 deletions sass_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,16 @@ extern "C" {
*n = num;
}

// helper for safe access to c_ctx
const char* safe_str (const char* str) {
return str == NULL ? "" : str;
}

int sass_compile(sass_context* c_ctx)
{
using namespace Sass;
try {
bool source_maps = false;
string source_map_file = "";
if (c_ctx->source_map_file && c_ctx->options.source_comments) {
source_maps = true;
source_map_file = c_ctx->source_map_file;
}
string input_path = c_ctx->input_path ? c_ctx->input_path : "";
string input_path = safe_str(c_ctx->input_path);
int lastindex = input_path.find_last_of(".");
string output_path;
if (!c_ctx->output_path) {
Expand All @@ -108,13 +107,10 @@ extern "C" {
Context::Data().source_c_str(c_ctx->source_string)
.output_path(output_path)
.output_style((Output_Style) c_ctx->options.output_style)
.source_comments(!c_ctx->options.source_comments)
.source_maps(source_maps)
.source_map_file(source_map_file)
.source_comments(c_ctx->options.source_comments)
.source_map_file(safe_str(c_ctx->options.source_map_file))
.omit_source_map_url(c_ctx->options.omit_source_map_url)
.image_path(c_ctx->options.image_path ?
c_ctx->options.image_path :
"")
.image_path(safe_str(c_ctx->options.image_path))
.include_paths_c_str(c_ctx->options.include_paths)
.include_paths_array(0)
.include_paths(vector<string>())
Expand Down Expand Up @@ -184,13 +180,7 @@ extern "C" {
{
using namespace Sass;
try {
bool source_maps = false;
string source_map_file = "";
if (c_ctx->source_map_file && c_ctx->options.source_comments) {
source_maps = true;
source_map_file = c_ctx->source_map_file;
}
string input_path = c_ctx->input_path ? c_ctx->input_path : "";
string input_path = safe_str(c_ctx->input_path);
int lastindex = input_path.find_last_of(".");
string output_path;
if (!c_ctx->output_path) {
Expand All @@ -203,13 +193,10 @@ extern "C" {
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)
.source_maps(source_maps)
.source_map_file(source_map_file)
.source_comments(c_ctx->options.source_comments)
.source_map_file(safe_str(c_ctx->options.source_map_file))
.omit_source_map_url(c_ctx->options.omit_source_map_url)
.image_path(c_ctx->options.image_path ?
c_ctx->options.image_path :
"")
.image_path(safe_str(c_ctx->options.image_path))
.include_paths_c_str(c_ctx->options.include_paths)
.include_paths_array(0)
.include_paths(vector<string>())
Expand Down
18 changes: 12 additions & 6 deletions sass_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@ extern "C" {
// Please ensure there are no null values.
// Thar be dragons.
struct sass_options {
// A value defined above in SASS_STYLE_* constants
// Output style for the generated css code
// A value from above SASS_STYLE_* constants
int output_style;
// If you want inline source comments
bool source_comments;
// colon-separated list of paths (semicolon-separated if you're on Windows)
// Path to source map file
// Enables the source map generating
// Used to create sourceMappingUrl
const char* source_map_file;
// Disable sourceMappingUrl in css output
bool omit_source_map_url;
// Colon-separated list of paths
// Semicolon-separated on Windows
const char* include_paths;
// For the image-url Sass function
const char* image_path;
// Positive integer
// Precision for outputting fractional numbers
int precision;
bool omit_source_map_url;
};

struct sass_context {
Expand All @@ -34,7 +42,6 @@ struct sass_context {
const char* source_string;
char* output_string;
char* source_map_string;
const char* source_map_file;
struct sass_options options;
int error_status;
char* error_message;
Expand All @@ -48,7 +55,6 @@ struct sass_file_context {
const char* output_path;
char* output_string;
char* source_map_string;
const char* source_map_file;
struct sass_options options;
int error_status;
char* error_message;
Expand Down
2 changes: 1 addition & 1 deletion script/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ if [ ! -d "sass-spec" ]; then
git clone https://github.com/sass/sass-spec.git
fi
if [ ! -d "sassc" ]; then
git clone -b feature/extra-env-variables https://github.com/mgreter/sassc.git
git clone https://github.com/sass/sassc.git
fi

0 comments on commit b1ce9a8

Please sign in to comment.