Skip to content

Instantly share code, notes, and snippets.

@andybp85
Last active February 17, 2019 22:53
Show Gist options
  • Save andybp85/2075671e6403e7c85f19ae2cf3f35fdb to your computer and use it in GitHub Desktop.
Save andybp85/2075671e6403e7c85f19ae2cf3f35fdb to your computer and use it in GitHub Desktop.
Sass_Data_Context example
#include <stdio.h>
#include <string.h>
#include "sass/context.h"
int main( int argc, char* argv[] )
{
// get the input file from first argument or use default
char* input = argc > 1 ? argv[1] : "div { a { color: blue; } }";
// create the context and get all related structs
struct Sass_Data_Context* data_ctx = sass_make_data_context(strdup(input));
struct Sass_Context* ctx = sass_data_context_get_context(data_ctx);
struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
// configure some options ...
sass_option_set_precision(ctx_opt, 10);
// context is set up, call the compile step now
int status = sass_compile_data_context(data_ctx);
// print the result or the error to the stdout
if (status == 0) puts(sass_context_get_output_string(ctx));
else puts(sass_context_get_error_message(ctx));
// release allocated memory
sass_delete_data_context(data_ctx);
// exit status
return status;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment