Debian Codegraph @

src/libsass/docs/api-context.md

raw symbols SCIP
1 Sass Contexts come in two flavors:
2
3 - `Sass_File_Context`
4 - `Sass_Data_Context`
5
6 ### Basic Usage
7
8 ```C
9 #include "sass/context.h"
10 ```
11
12 ***Sass_Options***
13
14 ```C
15 // Precision for fractional numbers
16 int precision;
17 ```
18 ```C
19 // Output style for the generated css code
20 // A value from above SASS_STYLE_* constants
21 int output_style;
22 ```
23 ```C
24 // Emit comments in the generated CSS indicating
25 // the corresponding source line.
26 bool source_comments;
27 ```
28 ```C
29 // embed sourceMappingUrl as data uri
30 bool source_map_embed;
31 ```
32 ```C
33 // embed include contents in maps
34 bool source_map_contents;
35 ```
36 ```C
37 // create file urls for sources
38 bool source_map_file_urls;
39 ```
40 ```C
41 // Disable sourceMappingUrl in css output
42 bool omit_source_map_url;
43 ```
44 ```C
45 // Treat source_string as sass (as opposed to scss)
46 bool is_indented_syntax_src;
47 ```
48 ```C
49 // The input path is used for source map
50 // generating. It can be used to define
51 // something with string compilation or to
52 // overload the input file path. It is
53 // set to "stdin" for data contexts and
54 // to the input file on file contexts.
55 char* input_path;
56 ```
57 ```C
58 // The output path is used for source map
59 // generating. LibSass will not write to
60 // this file, it is just used to create
61 // information in source-maps etc.
62 char* output_path;
63 ```
64 ```C
65 // String to be used for indentation
66 const char* indent;
67 ```
68 ```C
69 // String to be used to for line feeds
70 const char* linefeed;
71 ```
72 ```C
73 // Colon-separated list of paths
74 // Semicolon-separated on Windows
75 char* include_path;
76 char* plugin_path;
77 ```
78 ```C
79 // Additional include paths
80 // Must be null delimited
81 char** include_paths;
82 char** plugin_paths;
83 ```
84 ```C
85 // Path to source map file
86 // Enables the source map generating
87 // Used to create sourceMappingUrl
88 char* source_map_file;
89 ```
90 ```C
91 // Directly inserted in source maps
92 char* source_map_root;
93 ```
94 ```C
95 // Custom functions that can be called from Sass code
96 Sass_C_Function_List c_functions;
97 ```
98 ```C
99 // Callback to overload imports
100 Sass_C_Import_Callback importer;
101 ```
102
103 ***Sass_Context***
104
105 ```C
106 // store context type info
107 enum Sass_Input_Style type;
108 ````
109 ```C
110 // generated output data
111 char* output_string;
112 ```
113 ```C
114 // generated source map json
115 char* source_map_string;
116 ```
117 ```C
118 // error status
119 int error_status;
120 char* error_json;
121 char* error_text;
122 char* error_message;
123 // error position
124 char* error_file;
125 size_t error_line;
126 size_t error_column;
127 char* error_src;
128 ```
129 ```C
130 // report imported files
131 char** included_files;
132 ```
133
134 ***Sass_File_Context***
135
136 ```C
137 // no additional fields required
138 // input_path is already on options
139 ```
140
141 ***Sass_Data_Context***
142
143 ```C
144 // provided source string
145 char* source_string;
146 ```
147
148 ### Sass Context API
149
150 ```C
151 // Forward declaration
152 struct Sass_Compiler;
153
154 // Forward declaration
155 struct Sass_Options;
156 struct Sass_Context; // : Sass_Options
157 struct Sass_File_Context; // : Sass_Context
158 struct Sass_Data_Context; // : Sass_Context
159
160 // Create and initialize an option struct
161 struct Sass_Options* sass_make_options (void);
162 // Create and initialize a specific context
163 struct Sass_File_Context* sass_make_file_context (const char* input_path);
164 struct Sass_Data_Context* sass_make_data_context (char* source_string);
165
166 // Call the compilation step for the specific context
167 int sass_compile_file_context (struct Sass_File_Context* ctx);
168 int sass_compile_data_context (struct Sass_Data_Context* ctx);
169
170 // Create a sass compiler instance for more control
171 struct Sass_Compiler* sass_make_file_compiler (struct Sass_File_Context* file_ctx);
172 struct Sass_Compiler* sass_make_data_compiler (struct Sass_Data_Context* data_ctx);
173
174 // Execute the different compilation steps individually
175 // Useful if you only want to query the included files
176 int sass_compiler_parse (struct Sass_Compiler* compiler);
177 int sass_compiler_execute (struct Sass_Compiler* compiler);
178
179 // Release all memory allocated with the compiler
180 // This does _not_ include any contexts or options
181 void sass_delete_compiler (struct Sass_Compiler* compiler);
182 void sass_delete_options(struct Sass_Options* options);
183
184 // Release all memory allocated and also ourself
185 void sass_delete_file_context (struct Sass_File_Context* ctx);
186 void sass_delete_data_context (struct Sass_Data_Context* ctx);
187
188 // Getters for Context from specific implementation
189 struct Sass_Context* sass_file_context_get_context (struct Sass_File_Context* file_ctx);
190 struct Sass_Context* sass_data_context_get_context (struct Sass_Data_Context* data_ctx);
191
192 // Getters for Context_Options from Sass_Context
193 struct Sass_Options* sass_context_get_options (struct Sass_Context* ctx);
194 struct Sass_Options* sass_file_context_get_options (struct Sass_File_Context* file_ctx);
195 struct Sass_Options* sass_data_context_get_options (struct Sass_Data_Context* data_ctx);
196 void sass_file_context_set_options (struct Sass_File_Context* file_ctx, struct Sass_Options* opt);
197 void sass_data_context_set_options (struct Sass_Data_Context* data_ctx, struct Sass_Options* opt);
198
199 // Getters for Sass_Context values
200 const char* sass_context_get_output_string (struct Sass_Context* ctx);
201 int sass_context_get_error_status (struct Sass_Context* ctx);
202 const char* sass_context_get_error_json (struct Sass_Context* ctx);
203 const char* sass_context_get_error_text (struct Sass_Context* ctx);
204 const char* sass_context_get_error_message (struct Sass_Context* ctx);
205 const char* sass_context_get_error_file (struct Sass_Context* ctx);
206 const char* sass_context_get_error_src (struct Sass_Context* ctx);
207 size_t sass_context_get_error_line (struct Sass_Context* ctx);
208 size_t sass_context_get_error_column (struct Sass_Context* ctx);
209 const char* sass_context_get_source_map_string (struct Sass_Context* ctx);
210 char** sass_context_get_included_files (struct Sass_Context* ctx);
211
212 // Getters for Sass_Compiler options (query import stack)
213 size_t sass_compiler_get_import_stack_size(struct Sass_Compiler* compiler);
214 Sass_Import_Entry sass_compiler_get_last_import(struct Sass_Compiler* compiler);
215 Sass_Import_Entry sass_compiler_get_import_entry(struct Sass_Compiler* compiler, size_t idx);
216 // Getters for Sass_Compiler options (query function stack)
217 size_t sass_compiler_get_callee_stack_size(struct Sass_Compiler* compiler);
218 Sass_Callee_Entry sass_compiler_get_last_callee(struct Sass_Compiler* compiler);
219 Sass_Callee_Entry sass_compiler_get_callee_entry(struct Sass_Compiler* compiler, size_t idx);
220
221 // Take ownership of memory (value on context is set to 0)
222 char* sass_context_take_error_json (struct Sass_Context* ctx);
223 char* sass_context_take_error_text (struct Sass_Context* ctx);
224 char* sass_context_take_error_message (struct Sass_Context* ctx);
225 char* sass_context_take_error_file (struct Sass_Context* ctx);
226 char* sass_context_take_error_src (struct Sass_Context* ctx);
227 char* sass_context_take_output_string (struct Sass_Context* ctx);
228 char* sass_context_take_source_map_string (struct Sass_Context* ctx);
229 ```
230
231 ### Sass Options API
232
233 ```C
234 // Getters for Context_Option values
235 int sass_option_get_precision (struct Sass_Options* options);
236 enum Sass_Output_Style sass_option_get_output_style (struct Sass_Options* options);
237 bool sass_option_get_source_comments (struct Sass_Options* options);
238 bool sass_option_get_source_map_embed (struct Sass_Options* options);
239 bool sass_option_get_source_map_contents (struct Sass_Options* options);
240 bool sass_option_get_source_map_file_urls (struct Sass_Options* options);
241 bool sass_option_get_omit_source_map_url (struct Sass_Options* options);
242 bool sass_option_get_is_indented_syntax_src (struct Sass_Options* options);
243 const char* sass_option_get_indent (struct Sass_Options* options);
244 const char* sass_option_get_linefeed (struct Sass_Options* options);
245 const char* sass_option_get_input_path (struct Sass_Options* options);
246 const char* sass_option_get_output_path (struct Sass_Options* options);
247 const char* sass_option_get_source_map_file (struct Sass_Options* options);
248 const char* sass_option_get_source_map_root (struct Sass_Options* options);
249 Sass_C_Function_List sass_option_get_c_functions (struct Sass_Options* options);
250 Sass_C_Import_Callback sass_option_get_importer (struct Sass_Options* options);
251
252 // Getters for Context_Option include path array
253 size_t sass_option_get_include_path_size(struct Sass_Options* options);
254 const char* sass_option_get_include_path(struct Sass_Options* options, size_t i);
255 // Plugin paths to load dynamic libraries work the same
256 size_t sass_option_get_plugin_path_size(struct Sass_Options* options);
257 const char* sass_option_get_plugin_path(struct Sass_Options* options, size_t i);
258
259 // Setters for Context_Option values
260 void sass_option_set_precision (struct Sass_Options* options, int precision);
261 void sass_option_set_output_style (struct Sass_Options* options, enum Sass_Output_Style output_style);
262 void sass_option_set_source_comments (struct Sass_Options* options, bool source_comments);
263 void sass_option_set_source_map_embed (struct Sass_Options* options, bool source_map_embed);
264 void sass_option_set_source_map_contents (struct Sass_Options* options, bool source_map_contents);
265 void sass_option_set_source_map_file_urls (struct Sass_Options* options, bool source_map_file_urls);
266 void sass_option_set_omit_source_map_url (struct Sass_Options* options, bool omit_source_map_url);
267 void sass_option_set_is_indented_syntax_src (struct Sass_Options* options, bool is_indented_syntax_src);
268 void sass_option_set_indent (struct Sass_Options* options, const char* indent);
269 void sass_option_set_linefeed (struct Sass_Options* options, const char* linefeed);
270 void sass_option_set_input_path (struct Sass_Options* options, const char* input_path);
271 void sass_option_set_output_path (struct Sass_Options* options, const char* output_path);
272 void sass_option_set_plugin_path (struct Sass_Options* options, const char* plugin_path);
273 void sass_option_set_include_path (struct Sass_Options* options, const char* include_path);
274 void sass_option_set_source_map_file (struct Sass_Options* options, const char* source_map_file);
275 void sass_option_set_source_map_root (struct Sass_Options* options, const char* source_map_root);
276 void sass_option_set_c_functions (struct Sass_Options* options, Sass_C_Function_List c_functions);
277 void sass_option_set_importer (struct Sass_Options* options, Sass_C_Import_Callback importer);
278
279 // Push function for paths (no manipulation support for now)
280 void sass_option_push_plugin_path (struct Sass_Options* options, const char* path);
281 void sass_option_push_include_path (struct Sass_Options* options, const char* path);
282
283 // Resolve a file via the given include paths in the sass option struct
284 // find_file looks for the exact file name while find_include does a regular sass include
285 char* sass_find_file (const char* path, struct Sass_Options* opt);
286 char* sass_find_include (const char* path, struct Sass_Options* opt);
287
288 // Resolve a file relative to last import or include paths in the sass option struct
289 // find_file looks for the exact file name while find_include does a regular sass include
290 char* sass_compiler_find_file (const char* path, struct Sass_Compiler* compiler);
291 char* sass_compiler_find_include (const char* path, struct Sass_Compiler* compiler);
292 ```
293
294 ### More links
295
296 - [Sass Context Example](api-context-example.md)
297 - [Sass Context Internal](api-context-internal.md)
298