Initial commit
[yaffs-website] / node_modules / node-sass / src / libsass / docs / api-context-example.md
1 ## Example main.c
2
3 ```C
4 #include <stdio.h>
5 #include "sass/context.h"
6
7 int main( int argc, const char* argv[] )
8 {
9
10   // get the input file from first argument or use default
11   const char* input = argc > 1 ? argv[1] : "styles.scss";
12
13   // create the file context and get all related structs
14   struct Sass_File_Context* file_ctx = sass_make_file_context(input);
15   struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
16   struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
17
18   // configure some options ...
19   sass_option_set_precision(ctx_opt, 10);
20
21   // context is set up, call the compile step now
22   int status = sass_compile_file_context(file_ctx);
23
24   // print the result or the error to the stdout
25   if (status == 0) puts(sass_context_get_output_string(ctx));
26   else puts(sass_context_get_error_message(ctx));
27
28   // release allocated memory
29   sass_delete_file_context(file_ctx);
30
31   // exit status
32   return status;
33
34 }
35 ```
36
37 ### Compile main.c
38
39 ```bash
40 gcc -c main.c -o main.o
41 gcc -o sample main.o -lsass
42 echo "foo { margin: 21px * 2; }" > foo.scss
43 ./sample foo.scss => "foo { margin: 42px }"
44 ```
45