Blame docs/api-context.md

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