Blame docs/api-context.md

Packit bfcc33
Sass Contexts come in two flavors:
Packit bfcc33
Packit bfcc33
- `Sass_File_Context`
Packit bfcc33
- `Sass_Data_Context`
Packit bfcc33
Packit bfcc33
### Basic Usage
Packit bfcc33
Packit bfcc33
```C
Packit bfcc33
#include "sass/context.h"
Packit bfcc33
```
Packit bfcc33
Packit bfcc33
***Sass_Options***
Packit bfcc33
Packit bfcc33
```C
Packit bfcc33
// Precision for fractional numbers
Packit bfcc33
int precision;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// Output style for the generated css code
Packit bfcc33
// A value from above SASS_STYLE_* constants
Packit bfcc33
int output_style;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// Emit comments in the generated CSS indicating
Packit bfcc33
// the corresponding source line.
Packit bfcc33
bool source_comments;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// embed sourceMappingUrl as data uri
Packit bfcc33
bool source_map_embed;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// embed include contents in maps
Packit bfcc33
bool source_map_contents;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// create file urls for sources
Packit bfcc33
bool source_map_file_urls;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// Disable sourceMappingUrl in css output
Packit bfcc33
bool omit_source_map_url;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// Treat source_string as sass (as opposed to scss)
Packit bfcc33
bool is_indented_syntax_src;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// The input path is used for source map
Packit bfcc33
// generating. It can be used to define
Packit bfcc33
// something with string compilation or to
Packit bfcc33
// overload the input file path. It is
Packit bfcc33
// set to "stdin" for data contexts and
Packit bfcc33
// to the input file on file contexts.
Packit bfcc33
char* input_path;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// The output path is used for source map
Packit bfcc33
// generating. LibSass will not write to
Packit bfcc33
// this file, it is just used to create
Packit bfcc33
// information in source-maps etc.
Packit bfcc33
char* output_path;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// String to be used for indentation
Packit bfcc33
const char* indent;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// String to be used to for line feeds
Packit bfcc33
const char* linefeed;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// Colon-separated list of paths
Packit bfcc33
// Semicolon-separated on Windows
Packit bfcc33
char* include_path;
Packit bfcc33
char* plugin_path;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// Additional include paths
Packit bfcc33
// Must be null delimited
Packit bfcc33
char** include_paths;
Packit bfcc33
char** plugin_paths;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// Path to source map file
Packit bfcc33
// Enables the source map generating
Packit bfcc33
// Used to create sourceMappingUrl
Packit bfcc33
char* source_map_file;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// Directly inserted in source maps
Packit bfcc33
char* source_map_root;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// Custom functions that can be called from Sass code
Packit bfcc33
Sass_C_Function_List c_functions;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// Callback to overload imports
Packit bfcc33
Sass_C_Import_Callback importer;
Packit bfcc33
```
Packit bfcc33
Packit bfcc33
***Sass_Context***
Packit bfcc33
Packit bfcc33
```C
Packit bfcc33
// store context type info
Packit bfcc33
enum Sass_Input_Style type;
Packit bfcc33
````
Packit bfcc33
```C
Packit bfcc33
// generated output data
Packit bfcc33
char* output_string;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// generated source map json
Packit bfcc33
char* source_map_string;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// error status
Packit bfcc33
int error_status;
Packit bfcc33
char* error_json;
Packit bfcc33
char* error_text;
Packit bfcc33
char* error_message;
Packit bfcc33
// error position
Packit bfcc33
char* error_file;
Packit bfcc33
size_t error_line;
Packit bfcc33
size_t error_column;
Packit bfcc33
```
Packit bfcc33
```C
Packit bfcc33
// report imported files
Packit bfcc33
char** included_files;
Packit bfcc33
```
Packit bfcc33
Packit bfcc33
***Sass_File_Context***
Packit bfcc33
Packit bfcc33
```C
Packit bfcc33
// no additional fields required
Packit bfcc33
// input_path is already on options
Packit bfcc33
```
Packit bfcc33
Packit bfcc33
***Sass_Data_Context***
Packit bfcc33
Packit bfcc33
```C
Packit bfcc33
// provided source string
Packit bfcc33
char* source_string;
Packit bfcc33
```
Packit bfcc33
Packit bfcc33
### Sass Context API
Packit bfcc33
Packit bfcc33
```C
Packit bfcc33
// Forward declaration
Packit bfcc33
struct Sass_Compiler;
Packit bfcc33
Packit bfcc33
// Forward declaration
Packit bfcc33
struct Sass_Options;
Packit bfcc33
struct Sass_Context; // : Sass_Options
Packit bfcc33
struct Sass_File_Context; // : Sass_Context
Packit bfcc33
struct Sass_Data_Context; // : Sass_Context
Packit bfcc33
Packit bfcc33
// Create and initialize an option struct
Packit bfcc33
struct Sass_Options* sass_make_options (void);
Packit bfcc33
// Create and initialize a specific context
Packit bfcc33
struct Sass_File_Context* sass_make_file_context (const char* input_path);
Packit bfcc33
struct Sass_Data_Context* sass_make_data_context (char* source_string);
Packit bfcc33
Packit bfcc33
// Call the compilation step for the specific context
Packit bfcc33
int sass_compile_file_context (struct Sass_File_Context* ctx);
Packit bfcc33
int sass_compile_data_context (struct Sass_Data_Context* ctx);
Packit bfcc33
Packit bfcc33
// Create a sass compiler instance for more control
Packit bfcc33
struct Sass_Compiler* sass_make_file_compiler (struct Sass_File_Context* file_ctx);
Packit bfcc33
struct Sass_Compiler* sass_make_data_compiler (struct Sass_Data_Context* data_ctx);
Packit bfcc33
Packit bfcc33
// Execute the different compilation steps individually
Packit bfcc33
// Usefull if you only want to query the included files
Packit bfcc33
int sass_compiler_parse (struct Sass_Compiler* compiler);
Packit bfcc33
int sass_compiler_execute (struct Sass_Compiler* compiler);
Packit bfcc33
Packit bfcc33
// Release all memory allocated with the compiler
Packit bfcc33
// This does _not_ include any contexts or options
Packit bfcc33
void sass_delete_compiler (struct Sass_Compiler* compiler);
Packit bfcc33
void sass_delete_options(struct Sass_Options* options);
Packit bfcc33
Packit bfcc33
// Release all memory allocated and also ourself
Packit bfcc33
void sass_delete_file_context (struct Sass_File_Context* ctx);
Packit bfcc33
void sass_delete_data_context (struct Sass_Data_Context* ctx);
Packit bfcc33
Packit bfcc33
// Getters for Context from specific implementation
Packit bfcc33
struct Sass_Context* sass_file_context_get_context (struct Sass_File_Context* file_ctx);
Packit bfcc33
struct Sass_Context* sass_data_context_get_context (struct Sass_Data_Context* data_ctx);
Packit bfcc33
Packit bfcc33
// Getters for Context_Options from Sass_Context
Packit bfcc33
struct Sass_Options* sass_context_get_options (struct Sass_Context* ctx);
Packit bfcc33
struct Sass_Options* sass_file_context_get_options (struct Sass_File_Context* file_ctx);
Packit bfcc33
struct Sass_Options* sass_data_context_get_options (struct Sass_Data_Context* data_ctx);
Packit bfcc33
void sass_file_context_set_options (struct Sass_File_Context* file_ctx, struct Sass_Options* opt);
Packit bfcc33
void sass_data_context_set_options (struct Sass_Data_Context* data_ctx, struct Sass_Options* opt);
Packit bfcc33
Packit bfcc33
// Getters for Sass_Context values
Packit bfcc33
const char* sass_context_get_output_string (struct Sass_Context* ctx);
Packit bfcc33
int sass_context_get_error_status (struct Sass_Context* ctx);
Packit bfcc33
const char* sass_context_get_error_json (struct Sass_Context* ctx);
Packit bfcc33
const char* sass_context_get_error_text (struct Sass_Context* ctx);
Packit bfcc33
const char* sass_context_get_error_message (struct Sass_Context* ctx);
Packit bfcc33
const char* sass_context_get_error_file (struct Sass_Context* ctx);
Packit bfcc33
size_t sass_context_get_error_line (struct Sass_Context* ctx);
Packit bfcc33
size_t sass_context_get_error_column (struct Sass_Context* ctx);
Packit bfcc33
const char* sass_context_get_source_map_string (struct Sass_Context* ctx);
Packit bfcc33
char** sass_context_get_included_files (struct Sass_Context* ctx);
Packit bfcc33
Packit bfcc33
// Getters for Sass_Compiler options (query import stack)
Packit bfcc33
size_t sass_compiler_get_import_stack_size(struct Sass_Compiler* compiler);
Packit bfcc33
Sass_Import_Entry sass_compiler_get_last_import(struct Sass_Compiler* compiler);
Packit bfcc33
Sass_Import_Entry sass_compiler_get_import_entry(struct Sass_Compiler* compiler, size_t idx);
Packit bfcc33
// Getters for Sass_Compiler options (query function stack)
Packit bfcc33
size_t sass_compiler_get_callee_stack_size(struct Sass_Compiler* compiler);
Packit bfcc33
Sass_Callee_Entry sass_compiler_get_last_callee(struct Sass_Compiler* compiler);
Packit bfcc33
Sass_Callee_Entry sass_compiler_get_callee_entry(struct Sass_Compiler* compiler, size_t idx);
Packit bfcc33
Packit bfcc33
// Take ownership of memory (value on context is set to 0)
Packit bfcc33
char* sass_context_take_error_json (struct Sass_Context* ctx);
Packit bfcc33
char* sass_context_take_error_text (struct Sass_Context* ctx);
Packit bfcc33
char* sass_context_take_error_message (struct Sass_Context* ctx);
Packit bfcc33
char* sass_context_take_error_file (struct Sass_Context* ctx);
Packit bfcc33
char* sass_context_take_output_string (struct Sass_Context* ctx);
Packit bfcc33
char* sass_context_take_source_map_string (struct Sass_Context* ctx);
Packit bfcc33
```
Packit bfcc33
Packit bfcc33
### Sass Options API
Packit bfcc33
Packit bfcc33
```C
Packit bfcc33
// Getters for Context_Option values
Packit bfcc33
int sass_option_get_precision (struct Sass_Options* options);
Packit bfcc33
enum Sass_Output_Style sass_option_get_output_style (struct Sass_Options* options);
Packit bfcc33
bool sass_option_get_source_comments (struct Sass_Options* options);
Packit bfcc33
bool sass_option_get_source_map_embed (struct Sass_Options* options);
Packit bfcc33
bool sass_option_get_source_map_contents (struct Sass_Options* options);
Packit bfcc33
bool sass_option_get_source_map_file_urls (struct Sass_Options* options);
Packit bfcc33
bool sass_option_get_omit_source_map_url (struct Sass_Options* options);
Packit bfcc33
bool sass_option_get_is_indented_syntax_src (struct Sass_Options* options);
Packit bfcc33
const char* sass_option_get_indent (struct Sass_Options* options);
Packit bfcc33
const char* sass_option_get_linefeed (struct Sass_Options* options);
Packit bfcc33
const char* sass_option_get_input_path (struct Sass_Options* options);
Packit bfcc33
const char* sass_option_get_output_path (struct Sass_Options* options);
Packit bfcc33
const char* sass_option_get_source_map_file (struct Sass_Options* options);
Packit bfcc33
const char* sass_option_get_source_map_root (struct Sass_Options* options);
Packit bfcc33
Sass_C_Function_List sass_option_get_c_functions (struct Sass_Options* options);
Packit bfcc33
Sass_C_Import_Callback sass_option_get_importer (struct Sass_Options* options);
Packit bfcc33
Packit bfcc33
// Getters for Context_Option include path array
Packit bfcc33
size_t sass_option_get_include_path_size(struct Sass_Options* options);
Packit bfcc33
const char* sass_option_get_include_path(struct Sass_Options* options, size_t i);
Packit bfcc33
// Plugin paths to load dynamic libraries work the same
Packit bfcc33
size_t sass_option_get_plugin_path_size(struct Sass_Options* options);
Packit bfcc33
const char* sass_option_get_plugin_path(struct Sass_Options* options, size_t i);
Packit bfcc33
Packit bfcc33
// Setters for Context_Option values
Packit bfcc33
void sass_option_set_precision (struct Sass_Options* options, int precision);
Packit bfcc33
void sass_option_set_output_style (struct Sass_Options* options, enum Sass_Output_Style output_style);
Packit bfcc33
void sass_option_set_source_comments (struct Sass_Options* options, bool source_comments);
Packit bfcc33
void sass_option_set_source_map_embed (struct Sass_Options* options, bool source_map_embed);
Packit bfcc33
void sass_option_set_source_map_contents (struct Sass_Options* options, bool source_map_contents);
Packit bfcc33
void sass_option_set_source_map_file_urls (struct Sass_Options* options, bool source_map_file_urls);
Packit bfcc33
void sass_option_set_omit_source_map_url (struct Sass_Options* options, bool omit_source_map_url);
Packit bfcc33
void sass_option_set_is_indented_syntax_src (struct Sass_Options* options, bool is_indented_syntax_src);
Packit bfcc33
void sass_option_set_indent (struct Sass_Options* options, const char* indent);
Packit bfcc33
void sass_option_set_linefeed (struct Sass_Options* options, const char* linefeed);
Packit bfcc33
void sass_option_set_input_path (struct Sass_Options* options, const char* input_path);
Packit bfcc33
void sass_option_set_output_path (struct Sass_Options* options, const char* output_path);
Packit bfcc33
void sass_option_set_plugin_path (struct Sass_Options* options, const char* plugin_path);
Packit bfcc33
void sass_option_set_include_path (struct Sass_Options* options, const char* include_path);
Packit bfcc33
void sass_option_set_source_map_file (struct Sass_Options* options, const char* source_map_file);
Packit bfcc33
void sass_option_set_source_map_root (struct Sass_Options* options, const char* source_map_root);
Packit bfcc33
void sass_option_set_c_functions (struct Sass_Options* options, Sass_C_Function_List c_functions);
Packit bfcc33
void sass_option_set_importer (struct Sass_Options* options, Sass_C_Import_Callback importer);
Packit bfcc33
Packit bfcc33
// Push function for paths (no manipulation support for now)
Packit bfcc33
void sass_option_push_plugin_path (struct Sass_Options* options, const char* path);
Packit bfcc33
void sass_option_push_include_path (struct Sass_Options* options, const char* path);
Packit bfcc33
Packit bfcc33
// Resolve a file via the given include paths in the sass option struct
Packit bfcc33
// find_file looks for the exact file name while find_include does a regular sass include
Packit bfcc33
char* sass_find_file (const char* path, struct Sass_Options* opt);
Packit bfcc33
char* sass_find_include (const char* path, struct Sass_Options* opt);
Packit bfcc33
Packit bfcc33
// Resolve a file relative to last import or include paths in the sass option struct
Packit bfcc33
// find_file looks for the exact file name while find_include does a regular sass include
Packit bfcc33
char* sass_compiler_find_file (const char* path, struct Sass_Compiler* compiler);
Packit bfcc33
char* sass_compiler_find_include (const char* path, struct Sass_Compiler* compiler);
Packit bfcc33
```
Packit bfcc33
Packit bfcc33
### More links
Packit bfcc33
Packit bfcc33
- [Sass Context Example](api-context-example.md)
Packit bfcc33
- [Sass Context Internal](api-context-internal.md)
Packit bfcc33