2
2
#include < stdlib.h>
3
3
#include < string.h>
4
4
#include < Python.h>
5
- #include " sass_interface .h"
5
+ #include " sass_context .h"
6
6
7
7
#if PY_MAJOR_VERSION >= 3
8
8
#define PySass_IF_PY3 (three, two ) (three)
@@ -37,9 +37,13 @@ static struct PySass_Pair PySass_output_style_enum[] = {
37
37
38
38
static PyObject *
39
39
PySass_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;
41
43
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;
43
47
PyObject *result;
44
48
45
49
if (!PyArg_ParseTuple (args,
@@ -49,30 +53,38 @@ PySass_compile_string(PyObject *self, PyObject *args) {
49
53
return NULL ;
50
54
}
51
55
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) ;
59
63
60
- sass_compile (context);
64
+ sass_compile_data_context (context);
61
65
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);
62
70
result = Py_BuildValue (
63
71
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
66
74
);
67
- sass_free_context (context);
75
+ sass_delete_data_context (context);
68
76
return result;
69
77
}
70
78
71
79
static PyObject *
72
80
PySass_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;
74
84
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;
76
88
PyObject *source_map_filename, *result;
77
89
78
90
if (!PyArg_ParseTuple (args,
@@ -82,73 +94,41 @@ PySass_compile_filename(PyObject *self, PyObject *args) {
82
94
return NULL ;
83
95
}
84
96
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
+
87
100
if (source_comments && PySass_Bytes_Check (source_map_filename)) {
88
101
size_t source_map_file_len = PySass_Bytes_GET_SIZE (source_map_filename);
89
102
if (source_map_file_len) {
90
103
char *source_map_file = (char *) malloc (source_map_file_len + 1 );
91
104
strncpy (
92
- source_map_file,
105
+ source_map_file,
93
106
PySass_Bytes_AS_STRING (source_map_filename),
94
107
source_map_file_len + 1
95
108
);
96
- context-> options . source_map_file = source_map_file;
109
+ sass_option_set_source_map_file ( options, source_map_file) ;
97
110
}
98
111
}
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);
108
125
result = Py_BuildValue (
109
126
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
150
130
);
151
- sass_free_folder_context (context);
131
+ sass_delete_file_context (context);
152
132
return result;
153
133
}
154
134
@@ -157,8 +137,6 @@ static PyMethodDef PySass_methods[] = {
157
137
" Compile a SASS string." },
158
138
{" compile_filename" , PySass_compile_filename, METH_VARARGS,
159
139
" Compile a SASS file." },
160
- {" compile_dirname" , PySass_compile_dirname, METH_VARARGS,
161
- " Compile several SASS files." },
162
140
{NULL , NULL , 0 , NULL }
163
141
};
164
142
0 commit comments