22#include < stdlib.h>
33#include < string.h>
44#include < Python.h>
5- #include " sass_interface .h"
5+ #include " sass_context .h"
66
77#if PY_MAJOR_VERSION >= 3
88#define PySass_IF_PY3 (three, two ) (three)
@@ -37,9 +37,13 @@ static struct PySass_Pair PySass_output_style_enum[] = {
3737
3838static PyObject *
3939PySass_compile_string (PyObject *self, PyObject *args) {
40- struct sass_context *context;
40+ struct Sass_Context *ctx;
41+ struct Sass_Data_Context *context;
42+ struct Sass_Options *options;
4143 char *string, *include_paths, *image_path;
42- int output_style, source_comments, precision;
44+ const char *error_message, *output_string;
45+ Sass_Output_Style output_style;
46+ int source_comments, error_status, precision;
4347 PyObject *result;
4448
4549 if (!PyArg_ParseTuple (args,
@@ -49,30 +53,38 @@ PySass_compile_string(PyObject *self, PyObject *args) {
4953 return NULL ;
5054 }
5155
52- context = sass_new_context ( );
53- context-> source_string = string ;
54- context-> options . output_style = output_style;
55- context-> options . source_comments = source_comments;
56- context-> options . include_paths = include_paths;
57- context-> options . image_path = image_path;
58- context-> options . precision = precision;
56+ context = sass_make_data_context (string );
57+ options = sass_data_context_get_options (context) ;
58+ sass_option_set_output_style ( options, output_style) ;
59+ sass_option_set_source_comments ( options, source_comments) ;
60+ sass_option_set_include_path ( options, include_paths) ;
61+ sass_option_set_image_path ( options, image_path) ;
62+ sass_option_set_precision ( options, precision) ;
5963
60- sass_compile (context);
64+ sass_compile_data_context (context);
6165
66+ ctx = sass_data_context_get_context (context);
67+ error_status = sass_context_get_error_status (ctx);
68+ error_message = sass_context_get_error_message (ctx);
69+ output_string = sass_context_get_output_string (ctx);
6270 result = Py_BuildValue (
6371 PySass_IF_PY3 (" hy" , " hs" ),
64- (short int ) !context-> error_status ,
65- context-> error_status ? context-> error_message : context-> output_string
72+ (short int ) !error_status,
73+ error_status ? error_message : output_string
6674 );
67- sass_free_context (context);
75+ sass_delete_data_context (context);
6876 return result;
6977}
7078
7179static PyObject *
7280PySass_compile_filename (PyObject *self, PyObject *args) {
73- struct sass_file_context *context;
81+ struct Sass_Context *ctx;
82+ struct Sass_File_Context *context;
83+ struct Sass_Options *options;
7484 char *filename, *include_paths, *image_path;
75- int output_style, source_comments, error_status, precision;
85+ const char *error_message, *output_string, *source_map_string;
86+ Sass_Output_Style output_style;
87+ int source_comments, error_status, precision;
7688 PyObject *source_map_filename, *result;
7789
7890 if (!PyArg_ParseTuple (args,
@@ -82,73 +94,41 @@ PySass_compile_filename(PyObject *self, PyObject *args) {
8294 return NULL ;
8395 }
8496
85- context = sass_new_file_context ();
86- context->input_path = filename;
97+ context = sass_make_file_context (filename);
98+ options = sass_file_context_get_options (context);
99+
87100 if (source_comments && PySass_Bytes_Check (source_map_filename)) {
88101 size_t source_map_file_len = PySass_Bytes_GET_SIZE (source_map_filename);
89102 if (source_map_file_len) {
90103 char *source_map_file = (char *) malloc (source_map_file_len + 1 );
91104 strncpy (
92- source_map_file,
105+ source_map_file,
93106 PySass_Bytes_AS_STRING (source_map_filename),
94107 source_map_file_len + 1
95108 );
96- context-> options . source_map_file = source_map_file;
109+ sass_option_set_source_map_file ( options, source_map_file) ;
97110 }
98111 }
99- context->options .output_style = output_style;
100- context->options .source_comments = source_comments;
101- context->options .include_paths = include_paths;
102- context->options .image_path = image_path;
103- context->options .precision = precision;
104-
105- sass_compile_file (context);
106-
107- error_status = context->error_status ;
112+ sass_option_set_output_style (options, output_style);
113+ sass_option_set_source_comments (options, source_comments);
114+ sass_option_set_include_path (options, include_paths);
115+ sass_option_set_image_path (options, image_path);
116+ sass_option_set_precision (options, precision);
117+
118+ sass_compile_file_context (context);
119+
120+ ctx = sass_file_context_get_context (context);
121+ error_status = sass_context_get_error_status (ctx);
122+ error_message = sass_context_get_error_message (ctx);
123+ output_string = sass_context_get_output_string (ctx);
124+ source_map_string = sass_context_get_source_map_string (ctx);
108125 result = Py_BuildValue (
109126 PySass_IF_PY3 (" hyy" , " hss" ),
110- (short int ) !context->error_status ,
111- error_status ? context->error_message : context->output_string ,
112- error_status || context->source_map_string == NULL
113- ? " "
114- : context->source_map_string
115- );
116- sass_free_file_context (context);
117- return result;
118- }
119-
120- static PyObject *
121- PySass_compile_dirname (PyObject *self, PyObject *args) {
122- struct sass_folder_context *context;
123- char *search_path, *output_path, *include_paths, *image_path;
124- int output_style, source_comments, precision;
125- PyObject *result;
126-
127- if (!PyArg_ParseTuple (args,
128- PySass_IF_PY3 (" yyiiyyi" , " ssiissi" ),
129- &search_path, &output_path,
130- &output_style, &source_comments,
131- &include_paths, &image_path, precision)) {
132- return NULL ;
133- }
134-
135- context = sass_new_folder_context ();
136- context->search_path = search_path;
137- context->output_path = output_path;
138- context->options .output_style = output_style;
139- context->options .source_comments = source_comments;
140- context->options .include_paths = include_paths;
141- context->options .image_path = image_path;
142- context->options .precision = precision;
143-
144- sass_compile_folder (context);
145-
146- result = Py_BuildValue (
147- PySass_IF_PY3 (" hy" , " hs" ),
148- (short int ) !context->error_status ,
149- context->error_status ? context->error_message : NULL
127+ (short int ) !error_status,
128+ error_status ? error_message : output_string,
129+ error_status || source_map_string == NULL ? " " : source_map_string
150130 );
151- sass_free_folder_context (context);
131+ sass_delete_file_context (context);
152132 return result;
153133}
154134
@@ -157,8 +137,6 @@ static PyMethodDef PySass_methods[] = {
157137 " Compile a SASS string." },
158138 {" compile_filename" , PySass_compile_filename, METH_VARARGS,
159139 " Compile a SASS file." },
160- {" compile_dirname" , PySass_compile_dirname, METH_VARARGS,
161- " Compile several SASS files." },
162140 {NULL , NULL , 0 , NULL }
163141};
164142
0 commit comments