Initial commit
[yaffs-website] / node_modules / node-sass / src / sass_context_wrapper.cpp
1 #include "sass_context_wrapper.h"
2
3 extern "C" {
4   using namespace std;
5
6   void compile_it(uv_work_t* req) {
7     sass_context_wrapper* ctx_w = (sass_context_wrapper*)req->data;
8
9     if (ctx_w->dctx) {
10       compile_data(ctx_w->dctx);
11     }
12     else if (ctx_w->fctx) {
13       compile_file(ctx_w->fctx);
14     }
15   }
16
17   void compile_data(struct Sass_Data_Context* dctx) {
18     sass_compile_data_context(dctx);
19   }
20
21   void compile_file(struct Sass_File_Context* fctx) {
22     sass_compile_file_context(fctx);
23   }
24
25   sass_context_wrapper* sass_make_context_wrapper() {
26     return (sass_context_wrapper*)calloc(1, sizeof(sass_context_wrapper));
27   }
28
29   void sass_free_context_wrapper(sass_context_wrapper* ctx_w) {
30     if (ctx_w->dctx) {
31       sass_delete_data_context(ctx_w->dctx);
32     }
33     else if (ctx_w->fctx) {
34       sass_delete_file_context(ctx_w->fctx);
35     }
36
37     delete ctx_w->error_callback;
38     delete ctx_w->success_callback;
39
40     ctx_w->result.Reset();
41
42     free(ctx_w->include_path);
43     free(ctx_w->linefeed);
44     free(ctx_w->out_file);
45     free(ctx_w->source_map);
46     free(ctx_w->source_map_root);
47     free(ctx_w->indent);
48
49     std::vector<CustomImporterBridge *>::iterator imp_it = ctx_w->importer_bridges.begin();
50     while (imp_it != ctx_w->importer_bridges.end()) {
51       CustomImporterBridge* p = *imp_it;
52       imp_it = ctx_w->importer_bridges.erase(imp_it);
53       delete p;
54     }
55     std::vector<CustomFunctionBridge *>::iterator func_it = ctx_w->function_bridges.begin();
56     while (func_it != ctx_w->function_bridges.end()) {
57       CustomFunctionBridge* p = *func_it;
58       func_it = ctx_w->function_bridges.erase(func_it);
59       delete p;
60     }
61
62     free(ctx_w);
63   }
64 }