int main(int argc, char** argv) { if (argc < 3) { printf("Usage: sassloop [INPUT FILE] [ITERATIONS]\n"); return 0; } int i; for (i = 0; i < atoi(argv[2]); ++i) { printf("\n***\n*** PASS %d ***\n***\n\n", i); struct sass_file_context* ctx = sass_new_file_context(); printf("*** ALLOCATED A NEW CONTEXT\n"); ctx->options.include_paths = ""; ctx->options.image_path = "images"; ctx->options.output_style = SASS_STYLE_NESTED; ctx->input_path = argv[1]; printf("*** POPULATED THE CONTEXT\n"); sass_compile_file(ctx); printf("*** COMPILED THE FILE\n"); if (ctx->error_status) { if (ctx->error_message) printf("%s", ctx->error_message); else printf("An error occured; no error message available.\n"); } else if (ctx->output_string) { printf("%s", ctx->output_string); } else { printf("Unknown internal error.\n"); } sass_free_file_context(ctx); printf("*** DEALLOCATED THE CONTEXT\n"); sleep(1); } return 0; }
int main(int argc, char** argv) { if (argc < 2) { printf("Usage: sassc [INPUT FILE]\n"); return 0; } struct sass_file_context* ctx = sass_new_file_context(); ctx->options.include_paths = ""; ctx->options.output_style = SASS_STYLE_NESTED; ctx->input_path = argv[1]; sass_compile_file(ctx); if (ctx->error_status) { if (ctx->error_message) printf("%s", ctx->error_message); else printf("An error occured; no error message available.\n"); } else if (ctx->output_string) { printf("%s", ctx->output_string); } else { printf("Unknown internal error.\n"); } sass_free_file_context(ctx); return 0; }
int compile_file(struct sass_options options, char* input_path, char* outfile) { int ret; char* source_map_file = 0; struct sass_file_context* ctx = sass_new_file_context(); ctx->options = options; ctx->input_path = input_path; ctx->output_path = outfile; if (outfile && (ctx->options.source_comments == SASS_SOURCE_COMMENTS_MAP)) { const char* extension = ".map"; source_map_file = calloc(strlen(outfile) + strlen(extension) + 1, sizeof(char)); strcpy(source_map_file, outfile); strcat(source_map_file, extension); ctx->source_map_file = source_map_file; } sass_compile_file(ctx); ret = output(ctx->error_status, ctx->error_message, ctx->output_string, outfile); if (outfile && (ctx->options.source_comments == SASS_SOURCE_COMMENTS_MAP)) { ret = output(ctx->error_status, ctx->error_message, ctx->source_map_string, ctx->source_map_file); } free(source_map_file); sass_free_file_context(ctx); return ret; }
int compile_file(struct sass_options options, char* input_path, char* outfile) { int ret; char* source_map_file = 0; struct sass_file_context* ctx = sass_new_file_context(); ctx->options = options; ctx->input_path = input_path; ctx->output_path = outfile; sass_compile_file(ctx); ret = output(ctx->error_status, ctx->error_message, ctx->output_string, outfile); if (ctx->options.source_map_file) { ret = output(ctx->error_status, ctx->error_message, ctx->source_map_string, ctx->options.source_map_file); } free(source_map_file); sass_free_file_context(ctx); return ret; }
/* content handler */ static int sass_handler(request_rec *r) { int retval = OK; sass_dir_config_t *config; struct sass_file_context *context; char *css_name, *map_name, *sass_name, *scss_name; int is_css = 0; int is_map = 0; int is_sass = 0; const char *ext = get_filename_ext(r->filename); const char *fbase = apr_pstrndup(r->pool, r->filename, ext - r->filename); if (apr_strnatcasecmp(r->handler, "sass-script") != 0) { return DECLINED; } if (apr_strnatcasecmp(ext, ".css") == 0) { is_css = 1; } else if (apr_strnatcasecmp(ext, ".map") == 0) { is_map = 1; } if (!is_css && !is_map) { return DECLINED; } css_name = apr_psprintf(r->pool, "%s.css", fbase); map_name = apr_psprintf(r->pool, "%s.map", fbase); sass_name = apr_psprintf(r->pool, "%s.sass", fbase); scss_name = apr_psprintf(r->pool, "%s.scss", fbase); if (exists(sass_name)) { is_sass = 1; } if (!is_sass && !exists(scss_name)) { return DECLINED; } if (M_GET != r->method_number) { return HTTP_METHOD_NOT_ALLOWED; } config = ap_get_module_config(r->per_dir_config, &sass_module); if (config->source_map < 1 && is_map) { return DECLINED; } context = sass_new_file_context(); if (!context) { return HTTP_INTERNAL_SERVER_ERROR; } if (apr_strnatcasecmp(config->output_style, "expanded") == 0) { context->options.output_style = SASS_STYLE_EXPANDED; } else if (apr_strnatcasecmp(config->output_style, "compact") == 0) { context->options.output_style = SASS_STYLE_COMPACT; } else if (apr_strnatcasecmp(config->output_style, "compressed") == 0) { context->options.output_style = SASS_STYLE_COMPRESSED; } else { context->options.output_style = SASS_STYLE_NESTED; } context->options.source_comments = (config->source_comments > 0); context->options.omit_source_map_url = (config->omit_source_map_url > 0); context->options.source_map_embed = (config->source_map_embed > 0); context->options.source_map_contents = (config->source_map_contents > 0); context->options.source_map_root = config->source_map_root; context->options.include_paths = config->include_paths; context->options.plugin_paths = config->plugin_paths; if (config->precision > 0) { context->options.precision = config->precision; } context->options.is_indented_syntax_src = is_sass; if (is_sass) { context->input_path = sass_name; } else { context->input_path = scss_name; } if (config->source_map > 0) { context->options.source_map_file = map_name; } context->output_path = css_name; sass_compile_file(context); if (context->error_status) { r->content_type = SASS_CONTENT_TYPE_ERROR; if (context->error_message) { ap_rprintf(r, "%s", context->error_message); } else { ap_rputs("An error occured; no error message available.", r); } if (config->display_error < 1) { retval = HTTP_INTERNAL_SERVER_ERROR; } } else if (is_map && context->source_map_string) { r->content_type = SASS_CONTENT_TYPE_SOURCE_MAP; ap_rprintf(r, "%s", context->source_map_string); if (config->save_output > 0) { sass_output_file(r, map_name, context->source_map_string); if (context->output_string) { sass_output_file(r, css_name, context->output_string); } } } else if (context->output_string) { r->content_type = SASS_CONTENT_TYPE_CSS; ap_rprintf(r, "%s", context->output_string); if (config->save_output > 0) { if ((config->source_map > 0) && context->source_map_string) { sass_output_file(r, map_name, context->source_map_string); } sass_output_file(r, css_name, context->output_string); } } else { r->content_type = SASS_CONTENT_TYPE_ERROR; ap_rputs("Unknown internal error.", r); if (config->display_error < 1) { retval = HTTP_INTERNAL_SERVER_ERROR; } } sass_free_file_context(context); return retval; }