@@ -6,20 +6,44 @@ typedef struct {
66 struct sass_options options ;
77} sass_OptionsObject ;
88
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+
920static int
1021sass_Options_init (sass_OptionsObject * self , PyObject * args , PyObject * kwds )
1122{
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 ;
1425 char * include_paths_cstr , * item_buffer , * image_path_cstr ;
1526 size_t include_paths_len , include_paths_size , i , offset , item_size ,
1627 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 )) {
1931 return -1 ;
2032 }
2133
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+ }
2347
2448 if (include_paths == Py_None ) {
2549 PyErr_SetString (PyExc_TypeError , "include_paths must not be None" );
@@ -104,6 +128,27 @@ sass_Options_dealloc(sass_OptionsObject *self)
104128 self -> ob_type -> tp_free ((PyObject * ) self );
105129}
106130
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+
107152static PyObject *
108153sass_Options_get_include_paths (sass_OptionsObject * self , void * closure )
109154{
@@ -145,6 +190,8 @@ sass_Options_get_image_path(sass_OptionsObject *self, void *closure)
145190}
146191
147192static PyGetSetDef sass_Options_getset [] = {
193+ {"output_style" , (getter ) sass_Options_get_output_style , NULL ,
194+ "The string value of output style option." },
148195 {"include_paths" , (getter ) sass_Options_get_include_paths , NULL ,
149196 "The list of paths to include." },
150197 {"image_path" , (getter ) sass_Options_get_image_path , NULL ,
0 commit comments