| 1 |
|
| #ifdef __cplusplus |
| 2 |
|
| extern "C" { |
| 3 |
|
| #endif |
| 4 |
|
| |
| 5 |
|
| #define PERL_NO_GET_CONTEXT /* we want efficiency */ |
| 6 |
|
| #include <EXTERN.h> |
| 7 |
|
| #include <perl.h> |
| 8 |
|
| #include <XSUB.h> |
| 9 |
|
| |
| 10 |
|
| #ifdef __cplusplus |
| 11 |
|
| } /* extern "C" */ |
| 12 |
|
| #endif |
| 13 |
|
| |
| 14 |
|
| #define NEED_newCONSTSUB |
| 15 |
|
| #define NEED_sv_2pv_flags |
| 16 |
|
| #define NEED_newSVpvn_flags |
| 17 |
|
| #include "ppport.h" |
| 18 |
|
| #include "sass_interface.h" |
| 19 |
|
| |
| 20 |
|
| #define _CONST(name) \ |
| 21 |
|
| newCONSTSUB(stash, #name, newSViv(name)) |
| 22 |
|
| |
| 23 |
|
| #define hv_store_text_string(hv, key, val) \ |
| 24 |
|
| hv_store((hv), (key), strlen((key)), \ |
| 25 |
|
| (val) \ |
| 26 |
|
| ? newSVpvn_utf8((val), strlen((val)), 1) \ |
| 27 |
|
| : &PL_sv_undef, \ |
| 28 |
|
| 0 ); |
| 29 |
|
| |
| 30 |
16 |
| static int hv_fetch_iv(pTHX_ HV* dict, const char* key) { |
| 31 |
16 |
▶ | if (!hv_exists(dict, key, strlen(key))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_exists(dict, key, strlen(key))) { |
0 |
16 |
16 |
|
| 32 |
0 |
| return 0; |
| 33 |
|
| } |
| 34 |
|
| |
| 35 |
16 |
| SV** svv = hv_fetch(dict, key, strlen(key), 0); |
| 36 |
16 |
▶ | if (!SvIOKp(*svv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvIOKp(*svv)) { |
0 |
16 |
16 |
|
| 37 |
0 |
| Perl_croak(aTHX_ "Error %s is not integer.", key); |
| 38 |
|
| } |
| 39 |
16 |
| return SvIV(*svv); |
| 40 |
|
| } |
| 41 |
|
| |
| 42 |
16 |
| static char* hv_fetch_pv(pTHX_ HV* dict, const char* key) { |
| 43 |
16 |
▶ | if (!hv_exists(dict, key, strlen(key))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_exists(dict, key, strlen(key))) { |
0 |
16 |
16 |
|
| 44 |
0 |
| return NULL; |
| 45 |
|
| } |
| 46 |
|
| |
| 47 |
16 |
| SV** svv = hv_fetch(dict, key, strlen(key), 0); |
| 48 |
16 |
▶ | if (!SvOK(*svv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(*svv)) { |
0 |
16 |
16 |
|
| 49 |
0 |
| return NULL; |
| 50 |
|
| } |
| 51 |
16 |
▶ | if (!SvPOK(*svv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvPOK(*svv)) { |
0 |
16 |
16 |
|
| 52 |
0 |
| Perl_croak(aTHX_ "Error %s is not string.", key); |
| 53 |
|
| } |
| 54 |
32 |
| return SvPV_nolen(*svv); |
| 55 |
|
| } |
| 56 |
|
| |
| 57 |
10 |
| static void set_options(pTHX_ void* context, HV* options) { |
| 58 |
10 |
| struct sass_context* ctx = (struct sass_context*) context; |
| 59 |
10 |
▶ | if ( options == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( options == NULL ) { |
2 |
8 |
10 |
|
| 60 |
2 |
| const char* empty_string = ""; |
| 61 |
2 |
| struct sass_options default_options = { |
| 62 |
|
| SASS_STYLE_COMPRESSED, |
| 63 |
|
| SASS_SOURCE_COMMENTS_NONE, |
| 64 |
|
| (char*) empty_string, |
| 65 |
|
| (char*) empty_string, |
| 66 |
2 |
| }; |
| 67 |
2 |
| ctx->options = default_options; |
| 68 |
|
| } |
| 69 |
|
| else { |
| 70 |
8 |
| ctx->options.output_style = hv_fetch_iv(aTHX_ options, "output_style"); |
| 71 |
8 |
| ctx->options.source_comments = hv_fetch_iv(aTHX_ options, "source_comments"); |
| 72 |
8 |
| ctx->options.include_paths = hv_fetch_pv(aTHX_ options, "include_paths"); |
| 73 |
8 |
| ctx->options.image_path = hv_fetch_pv(aTHX_ options, "image_path"); |
| 74 |
|
| } |
| 75 |
10 |
| } |
| 76 |
|
| |
| 77 |
|
| MODULE = Text::Sass::XS PACKAGE = Text::Sass::XS |
| 78 |
|
| |
| 79 |
|
| PROTOTYPES: DISABLE |
| 80 |
|
| |
| 81 |
|
| BOOT: |
| 82 |
|
| { |
| 83 |
7 |
| HV* stash = gv_stashpv("Text::Sass::XS", 1); |
| 84 |
|
| |
| 85 |
7 |
| _CONST(SASS_STYLE_NESTED); |
| 86 |
7 |
| _CONST(SASS_STYLE_EXPANDED); |
| 87 |
|
| // _CONST(SASS_STYLE_COMPACT); Not implemented yet. |
| 88 |
7 |
| _CONST(SASS_STYLE_COMPRESSED); |
| 89 |
7 |
| _CONST(SASS_SOURCE_COMMENTS_NONE); |
| 90 |
7 |
| _CONST(SASS_SOURCE_COMMENTS_DEFAULT); |
| 91 |
7 |
| _CONST(SASS_SOURCE_COMMENTS_MAP); |
| 92 |
|
| } |
| 93 |
|
| |
| 94 |
|
| HV* |
| 95 |
|
| _compile(source_string, options=NULL) |
| 96 |
|
| const char* source_string; |
| 97 |
|
| HV* options; |
| 98 |
|
| PREINIT: |
| 99 |
|
| char* output_string; |
| 100 |
|
| char* error_message; |
| 101 |
6 |
▶ | struct sass_context* context = sass_new_context(); |
Branch: 1 branch
| Branch | True | False | Total |
| struct sass_context* context = sass_new_context(); |
1 |
5 |
6 |
|
| 102 |
|
| INIT: |
| 103 |
6 |
| context->source_string = source_string; |
| 104 |
6 |
| context->output_string = output_string; |
| 105 |
6 |
| set_options(aTHX_ context, options); |
| 106 |
|
| CODE: |
| 107 |
6 |
| RETVAL = (HV*)sv_2mortal((SV*)newHV()); |
| 108 |
6 |
| sass_compile(context); |
| 109 |
6 |
▶ | hv_store_text_string(RETVAL, "output_string", context->output_string); |
Branch: 1 branch
| Branch | True | False | Total |
| hv_store_text_string(RETVAL, "output_string", context->output_string); |
6 |
0 |
6 |
|
| 110 |
6 |
▶ | hv_store_text_string(RETVAL, "error_message", context->error_message); |
Branch: 1 branch
| Branch | True | False | Total |
| hv_store_text_string(RETVAL, "error_message", context->error_message); |
0 |
6 |
6 |
|
| 111 |
6 |
| hv_store(RETVAL, "error_status", strlen("error_status"), newSViv(context->error_status), 0); |
| 112 |
|
| OUTPUT: |
| 113 |
|
| RETVAL |
| 114 |
|
| CLEANUP: |
| 115 |
6 |
| sass_free_context(context); |
| 116 |
|
| |
| 117 |
|
| |
| 118 |
|
| HV* |
| 119 |
|
| _compile_file(input_path, options=NULL) |
| 120 |
|
| char* input_path; |
| 121 |
|
| HV* options; |
| 122 |
|
| PREINIT: |
| 123 |
|
| char* output_string; |
| 124 |
|
| char* error_message; |
| 125 |
4 |
▶ | struct sass_file_context* context = sass_new_file_context(); |
Branch: 1 branch
| Branch | True | False | Total |
| struct sass_file_context* context = sass_new_file_context(); |
1 |
3 |
4 |
|
| 126 |
|
| INIT: |
| 127 |
4 |
| context->input_path = input_path; |
| 128 |
4 |
| context->output_string = output_string; |
| 129 |
4 |
| set_options(aTHX_ context, options); |
| 130 |
|
| CODE: |
| 131 |
4 |
| RETVAL = (HV*)sv_2mortal((SV*)newHV()); |
| 132 |
4 |
| sass_compile_file(context); |
| 133 |
4 |
▶ | hv_store_text_string(RETVAL, "output_string", context->output_string); |
Branch: 1 branch
| Branch | True | False | Total |
| hv_store_text_string(RETVAL, "output_string", context->output_string); |
4 |
0 |
4 |
|
| 134 |
4 |
▶ | hv_store_text_string(RETVAL, "error_message", context->error_message); |
Branch: 1 branch
| Branch | True | False | Total |
| hv_store_text_string(RETVAL, "error_message", context->error_message); |
0 |
4 |
4 |
|
| 135 |
4 |
| hv_store(RETVAL, "error_status", strlen("error_status"), newSViv(context->error_status), 0); |
| 136 |
|
| OUTPUT: |
| 137 |
|
| RETVAL |
| 138 |
|
| CLEANUP: |
| 139 |
4 |
| sass_free_file_context(context); |