int compile_file(struct Sass_Options* options, char* input_path, char* outfile) { int ret; char* source_map_file = 0; struct Sass_File_Context* ctx = sass_make_file_context(input_path); struct Sass_Context* ctx_out = sass_file_context_get_context(ctx); if (outfile) sass_option_set_output_path(options, outfile); sass_file_context_set_options(ctx, options); sass_compile_file_context(ctx); ret = output( sass_context_get_error_status(ctx_out), sass_context_get_error_message(ctx_out), sass_context_get_output_string(ctx_out), outfile ); if (sass_option_get_source_map_file(options)) { ret = output( sass_context_get_error_status(ctx_out), sass_context_get_error_message(ctx_out), sass_context_get_source_map_string(ctx_out), sass_option_get_source_map_file(options) ); } free(source_map_file); sass_delete_file_context(ctx); return ret; }
int GetResult(sass_context_wrapper* ctx_w, Sass_Context* ctx, bool is_sync = false) { Nan::HandleScope scope; v8::Local<v8::Object> result; int status = sass_context_get_error_status(ctx); result = Nan::New(ctx_w->result); assert(result->IsObject()); if (status == 0) { const char* css = sass_context_get_output_string(ctx); const char* map = sass_context_get_source_map_string(ctx); Nan::Set(result, Nan::New("css").ToLocalChecked(), Nan::CopyBuffer(css, static_cast<uint32_t>(strlen(css))).ToLocalChecked()); GetStats(ctx_w, ctx); if (map) { Nan::Set(result, Nan::New("map").ToLocalChecked(), Nan::CopyBuffer(map, static_cast<uint32_t>(strlen(map))).ToLocalChecked()); } } else if (is_sync) { Nan::Set(result, Nan::New("error").ToLocalChecked(), Nan::New<v8::String>(sass_context_get_error_json(ctx)).ToLocalChecked()); } return status; }
int GetResult(Handle<Object> result, Sass_Context* ctx) { int status = sass_context_get_error_status(ctx); if (status == 0) { (*result)->Set(NanNew("css"), NanNew<String>(sass_context_get_output_string(ctx))); GetStats(result, ctx); GetSourceMap(result, ctx); } return status; }
int GetResult(sass_context_wrapper* ctx_w, Sass_Context* ctx) { NanScope(); int status = sass_context_get_error_status(ctx); if (status == 0) { NanNew(ctx_w->result)->Set(NanNew("css"), NanNew<String>(sass_context_get_output_string(ctx))); GetStats(ctx_w, ctx); GetSourceMap(ctx_w, ctx); } return status; }
int compile_stdin(struct Sass_Options* options, char* outfile) { int ret; struct Sass_Data_Context* ctx; char buffer[BUFSIZE]; size_t size = 1; char *source_string = malloc(sizeof(char) * BUFSIZE); if(source_string == NULL) { perror("Allocation failed"); exit(1); } source_string[0] = '\0'; while(fgets(buffer, BUFSIZE, stdin)) { char *old = source_string; size += strlen(buffer); source_string = realloc(source_string, size); if(source_string == NULL) { perror("Reallocation failed"); free(old); exit(2); } #ifdef _MSC_VER strcat_s(source_string, size, buffer); #else strcat(source_string, buffer); #endif } if(ferror(stdin)) { free(source_string); perror("Error reading standard input"); exit(2); } ctx = sass_make_data_context(source_string); struct Sass_Context* ctx_out = sass_data_context_get_context(ctx); sass_data_context_set_options(ctx, options); sass_compile_data_context(ctx); ret = output( sass_context_get_error_status(ctx_out), sass_context_get_error_message(ctx_out), sass_context_get_output_string(ctx_out), outfile ); sass_delete_data_context(ctx); return ret; }
int get_result(sass_context_wrapper* ctx_w, Sass_Context* ctx, bool is_sync = false) { NanScope(); int status = sass_context_get_error_status(ctx); if (status == 0) { NanNew(ctx_w->result)->Set(NanNew("css"), NanNew<String>(sass_context_get_output_string(ctx))); get_stats(ctx_w, ctx); get_source_map(ctx_w, ctx); } else if (is_sync) { NanNew(ctx_w->result)->Set(NanNew("error"), NanNew<String>(sass_context_get_error_json(ctx))); } return status; }