@@ -6,20 +6,44 @@ typedef struct {
6
6
struct sass_options options ;
7
7
} sass_OptionsObject ;
8
8
9
+ static struct {
10
+ char * label ;
11
+ int value ;
12
+ } sass_Options_output_style_enum [] = {
13
+ {"nested" , SASS_STYLE_NESTED },
14
+ {"expanded" , SASS_STYLE_EXPANDED },
15
+ {"compact" , SASS_STYLE_COMPACT },
16
+ {"compressed" , SASS_STYLE_COMPRESSED },
17
+ {NULL }
18
+ };
19
+
9
20
static int
10
21
sass_Options_init (sass_OptionsObject * self , PyObject * args , PyObject * kwds )
11
22
{
12
- static char * sig [] = {"include_paths" , "image_path" , NULL };
13
- PyObject * include_paths , * image_path , * item ;
23
+ static char * sig [] = {"output_style" , " include_paths" , "image_path" , NULL };
24
+ PyObject * output_style , * include_paths , * image_path , * item ;
14
25
char * include_paths_cstr , * item_buffer , * image_path_cstr ;
15
26
size_t include_paths_len , include_paths_size , i , offset , item_size ,
16
27
image_path_size ;
17
- if (!PyArg_ParseTupleAndKeywords (args , kwds , "OS" , sig ,
18
- & include_paths , & image_path )) {
28
+ if (!PyArg_ParseTupleAndKeywords (args , kwds , "SOS" , sig ,
29
+ & output_style , & include_paths ,
30
+ & image_path )) {
19
31
return -1 ;
20
32
}
21
33
22
- self -> options .output_style = SASS_STYLE_NESTED ;
34
+ for (i = 0 ; sass_Options_output_style_enum [i ].label ; ++ i ) {
35
+ if (0 == strncmp (PyString_AsString (output_style ),
36
+ sass_Options_output_style_enum [i ].label ,
37
+ PyString_Size (output_style ))) {
38
+ self -> options .output_style =
39
+ sass_Options_output_style_enum [i ].value ;
40
+ break ;
41
+ }
42
+ }
43
+ if (sass_Options_output_style_enum [i ].label == NULL ) {
44
+ PyErr_SetString (PyExc_ValueError , "invalid output_style option" );
45
+ return -1 ;
46
+ }
23
47
24
48
if (include_paths == Py_None ) {
25
49
PyErr_SetString (PyExc_TypeError , "include_paths must not be None" );
@@ -104,6 +128,27 @@ sass_Options_dealloc(sass_OptionsObject *self)
104
128
self -> ob_type -> tp_free ((PyObject * ) self );
105
129
}
106
130
131
+ static PyObject *
132
+ sass_Options_get_output_style (sass_OptionsObject * self , void * closure )
133
+ {
134
+ int value ;
135
+ PyObject * label ;
136
+ size_t i ;
137
+
138
+ value = self -> options .output_style ;
139
+ for (i = 0 ; sass_Options_output_style_enum [i ].label ; ++ i ) {
140
+ if (value == sass_Options_output_style_enum [i ].value ) {
141
+ label = PyString_FromString (
142
+ sass_Options_output_style_enum [i ].label );
143
+ Py_INCREF (label );
144
+ return label ;
145
+ }
146
+ }
147
+
148
+ PyErr_Format (PyExc_ValueError , "output_style is invalid (%d)" , value );
149
+ return NULL ;
150
+ }
151
+
107
152
static PyObject *
108
153
sass_Options_get_include_paths (sass_OptionsObject * self , void * closure )
109
154
{
@@ -145,6 +190,8 @@ sass_Options_get_image_path(sass_OptionsObject *self, void *closure)
145
190
}
146
191
147
192
static PyGetSetDef sass_Options_getset [] = {
193
+ {"output_style" , (getter ) sass_Options_get_output_style , NULL ,
194
+ "The string value of output style option." },
148
195
{"include_paths" , (getter ) sass_Options_get_include_paths , NULL ,
149
196
"The list of paths to include." },
150
197
{"image_path" , (getter ) sass_Options_get_image_path , NULL ,
0 commit comments