|
| 1 | +/*****************************************************************************/ |
| 2 | +/* Part of LibSass, released under the MIT license (See LICENSE.txt). */ |
| 3 | +/*****************************************************************************/ |
1 | 4 | #ifndef SASS_C_COMPILER_H
|
2 | 5 | #define SASS_C_COMPILER_H
|
3 | 6 |
|
4 | 7 | #include <sass/base.h>
|
| 8 | +#include <sass/function.h> |
| 9 | + |
5 | 10 | #ifdef __cplusplus
|
6 | 11 | extern "C" {
|
7 | 12 | #endif
|
8 | 13 |
|
9 |
| - // Create a new compiler from the libsass context and the given entry point |
| 14 | + ///////////////////////////////////////////////////////////////////////// |
| 15 | + ///////////////////////////////////////////////////////////////////////// |
| 16 | + |
| 17 | + // Create a new LibSass compiler context |
10 | 18 | ADDAPI struct SassCompiler* ADDCALL sass_make_compiler();
|
11 | 19 |
|
12 |
| - // Release all memory allocated with the structures |
| 20 | + // Release all memory allocated with the compiler |
13 | 21 | ADDAPI void ADDCALL sass_delete_compiler(struct SassCompiler* compiler);
|
14 | 22 |
|
15 |
| - // Parse the entry point and potentially all imports within |
| 23 | + ///////////////////////////////////////////////////////////////////////// |
| 24 | + ///////////////////////////////////////////////////////////////////////// |
| 25 | + |
| 26 | + // Parse the entry point and potentially all imports within. |
16 | 27 | ADDAPI void ADDCALL sass_compiler_parse(struct SassCompiler* compiler);
|
17 | 28 |
|
18 |
| - // Evaluate the parsed entry point and store resulting ast-tree |
| 29 | + // Evaluate the parsed entry point and store resulting ast-tree. |
19 | 30 | ADDAPI void ADDCALL sass_compiler_compile(struct SassCompiler* compiler);
|
20 | 31 |
|
21 |
| - // Render the evaluated ast-tree to get the final output string |
| 32 | + // Render the evaluated ast-tree to get the final output string. |
22 | 33 | ADDAPI void ADDCALL sass_compiler_render(struct SassCompiler* compiler);
|
23 | 34 |
|
24 |
| - // Push function for paths (no manipulation support for now) |
25 |
| - ADDAPI void ADDCALL sass_compiler_load_plugins(struct SassCompiler* compiler, const char* paths); |
| 35 | + ///////////////////////////////////////////////////////////////////////// |
| 36 | + ///////////////////////////////////////////////////////////////////////// |
| 37 | + |
| 38 | + // Add additional include paths where LibSass will look for includes. |
| 39 | + // Note: the passed in `paths` can be path separated (`;` on windows, `:` otherwise). |
26 | 40 | ADDAPI void ADDCALL sass_compiler_add_include_paths(struct SassCompiler* compiler, const char* paths);
|
| 41 | + |
| 42 | + // Load dynamic loadable plugins from `paths`. Plugins are only supported on certain OSs and |
| 43 | + // are still in experimental state. This will look for `*.dll`, `*.so` or `*.dynlib` files. |
| 44 | + // It then tries to load the found libraries and does a few checks to see if the library |
| 45 | + // is actually a LibSass plugin. We then call its init hook if the library is compatible. |
| 46 | + // Note: the passed in `paths` can be path separated (`;` on windows, `:` otherwise). |
| 47 | + ADDAPI void ADDCALL sass_compiler_load_plugins(struct SassCompiler* compiler, const char* paths); |
| 48 | + |
| 49 | + // Add a custom header importer that will always be executed before any other |
| 50 | + // compilations takes place. Useful to prepend a shared copyright header or to |
| 51 | + // provide global variables or functions. This feature is still in experimental state. |
| 52 | + // Note: With the adaption of Sass Modules this might be completely replaced in the future. |
27 | 53 | ADDAPI void ADDCALL sass_compiler_add_custom_header(struct SassCompiler* compiler, struct SassImporter* header);
|
| 54 | + |
| 55 | + // Add a custom importer that will be executed when a sass `@import` rule is found. |
| 56 | + // This is useful to e.g. rewrite import locations or to load content from remote. |
| 57 | + // For more please check https://github.com/sass/libsass/blob/master/docs/api-importer.md |
| 58 | + // Note: The importer will not be called for regular css `@import url()` rules. |
28 | 59 | ADDAPI void ADDCALL sass_compiler_add_custom_importer(struct SassCompiler* compiler, struct SassImporter* importer);
|
| 60 | + |
| 61 | + // Add a custom function that will be executed when the corresponding function call is |
| 62 | + // requested from any sass code. This is useful to provide custom functions in your code. |
| 63 | + // For more please check https://github.com/sass/libsass/blob/master/docs/api-function.md |
29 | 64 | ADDAPI void ADDCALL sass_compiler_add_custom_function(struct SassCompiler* compiler, struct SassFunction* function);
|
30 | 65 |
|
31 |
| - // Setters for output and console logging styles |
| 66 | + ///////////////////////////////////////////////////////////////////////// |
| 67 | + ///////////////////////////////////////////////////////////////////////// |
| 68 | + |
| 69 | + // Setter for output style (see `enum SassOutputStyle` for possible options). |
32 | 70 | ADDAPI void ADDCALL sass_compiler_set_output_style(struct SassCompiler* compiler, enum SassOutputStyle output_style);
|
| 71 | + |
| 72 | + // Setter for logging style (see `enum SassLoggerStyle` for possible options). |
33 | 73 | ADDAPI void ADDCALL sass_compiler_set_logger_style(struct SassCompiler* compiler, enum SassLoggerStyle log_style);
|
34 | 74 |
|
35 |
| - // Getters for compiler option values |
| 75 | + // Getter for compiler precision (how floating point numbers are truncated). |
36 | 76 | ADDAPI int ADDCALL sass_compiler_get_precision(struct SassCompiler* compiler);
|
37 |
| - ADDAPI const char* ADDCALL sass_compiler_get_output_path(struct SassCompiler* compiler); |
38 |
| - ADDAPI struct SassImport* ADDCALL sass_compiler_get_entry_point(struct SassCompiler* compiler); |
39 | 77 |
|
40 |
| - // Setters for compiler option values |
| 78 | + // Setter for compiler precision (how floating point numbers are truncated). |
41 | 79 | ADDAPI void ADDCALL sass_compiler_set_precision(struct SassCompiler* compiler, int precision);
|
42 |
| - ADDAPI void ADDCALL sass_compiler_set_output_path(struct SassCompiler* compiler, const char* output_path); |
| 80 | + |
| 81 | + // Getter for compiler entry point (which file or data to parse first). |
| 82 | + ADDAPI struct SassImport* ADDCALL sass_compiler_get_entry_point(struct SassCompiler* compiler); |
| 83 | + |
| 84 | + // Setter for compiler entry point (which file or data to parse first). |
43 | 85 | ADDAPI void ADDCALL sass_compiler_set_entry_point(struct SassCompiler* compiler, struct SassImport* import);
|
44 | 86 |
|
45 |
| - // Getter for sass compiler results |
| 87 | + // Getter for compiler output path (where to store the result) |
| 88 | + // Note: LibSass does not write the file, implementers should write to this path. |
| 89 | + ADDAPI const char* ADDCALL sass_compiler_get_output_path(struct SassCompiler* compiler); |
| 90 | + |
| 91 | + // Setter for compiler output path (where to store the result) |
| 92 | + // Note: LibSass does not write the file, implementers should write to this path. |
| 93 | + ADDAPI void ADDCALL sass_compiler_set_output_path(struct SassCompiler* compiler, const char* output_path); |
| 94 | + |
| 95 | + ///////////////////////////////////////////////////////////////////////// |
| 96 | + ///////////////////////////////////////////////////////////////////////// |
| 97 | + |
| 98 | + // Getter for warnings that occurred during any step. |
46 | 99 | ADDAPI const char* ADDCALL sass_compiler_get_warn_string(struct SassCompiler* compiler);
|
| 100 | + |
| 101 | + // Getter for output after parsing, compilation and rendering. |
47 | 102 | ADDAPI const char* ADDCALL sass_compiler_get_output_string(struct SassCompiler* compiler);
|
| 103 | + |
| 104 | + // Getter for footer string containing optional source-map (embedded or link). |
48 | 105 | ADDAPI const char* ADDCALL sass_compiler_get_footer_string(struct SassCompiler* compiler);
|
| 106 | + |
| 107 | + // Getter for string containing the optional source-mapping. |
49 | 108 | ADDAPI const char* ADDCALL sass_compiler_get_srcmap_string(struct SassCompiler* compiler);
|
50 | 109 |
|
51 |
| - // Setters for source-map options |
| 110 | + ///////////////////////////////////////////////////////////////////////// |
| 111 | + ///////////////////////////////////////////////////////////////////////// |
| 112 | + |
| 113 | + // Setter for source-map mode (how to embed or not embed the source-map). |
| 114 | + ADDAPI void ADDCALL sass_compiler_set_srcmap_mode(struct SassCompiler* compiler, enum SassSrcMapMode mode); |
| 115 | + |
| 116 | + // Setter for source-map path (where to store the source-mapping). |
| 117 | + // Note: if path is not explicitly given, we will deduct one from input path. |
| 118 | + // Note: LibSass does not write the file, implementers should write to this path. |
52 | 119 | ADDAPI void ADDCALL sass_compiler_set_srcmap_path(struct SassCompiler* compiler, const char* path);
|
| 120 | + |
| 121 | + // Setter for source-map root (simply passed to the resulting srcmap info). |
| 122 | + // Note: if not given, no root attribute will be added to the srcmap info object. |
53 | 123 | ADDAPI void ADDCALL sass_compiler_set_srcmap_root(struct SassCompiler* compiler, const char* root);
|
54 |
| - ADDAPI void ADDCALL sass_compiler_set_srcmap_mode(struct SassCompiler* compiler, enum SassSrcMapMode mode); |
| 124 | + |
| 125 | + // Setter for source-map file-url option (renders urls in srcmap as `file://` urls) |
55 | 126 | ADDAPI void ADDCALL sass_compiler_set_srcmap_file_urls(struct SassCompiler* compiler, bool enable);
|
| 127 | + |
| 128 | + // Setter for source-map embed-contents option (includes full sources in the srcmap info) |
56 | 129 | ADDAPI void ADDCALL sass_compiler_set_srcmap_embed_contents(struct SassCompiler* compiler, bool enable);
|
57 | 130 |
|
| 131 | + ///////////////////////////////////////////////////////////////////////// |
| 132 | + ///////////////////////////////////////////////////////////////////////// |
| 133 | + |
| 134 | + // Getter to return the number of all included files. |
58 | 135 | ADDAPI size_t ADDCALL sass_compiler_get_included_files_count(struct SassCompiler* compiler);
|
| 136 | + |
| 137 | + // Getter to return path to the included file at position `n`. |
59 | 138 | ADDAPI const char* ADDCALL sass_compiler_get_included_file_path(struct SassCompiler* compiler, size_t n);
|
60 | 139 |
|
61 |
| - ADDAPI struct SassImport* ADDCALL sass_compiler_get_last_import(struct SassCompiler* compiler); |
| 140 | + ///////////////////////////////////////////////////////////////////////// |
| 141 | + ///////////////////////////////////////////////////////////////////////// |
62 | 142 |
|
63 |
| -#ifdef __cplusplus |
64 |
| -} // EO extern "C". |
65 |
| -#endif |
66 |
| - |
67 |
| -#ifdef __cplusplus |
68 |
| -namespace Sass { |
69 |
| -extern "C" { |
70 |
| -#endif |
| 143 | + // Getter for current import context. Use `SassImport` functions to query the state. |
| 144 | + ADDAPI const struct SassImport* ADDCALL sass_compiler_get_last_import(struct SassCompiler* compiler); |
71 | 145 |
|
72 | 146 | // Returns pointer to error object associated with compiler.
|
73 | 147 | // Will be valid until the associated compiler is destroyed.
|
74 | 148 | ADDAPI const struct SassError* ADDCALL sass_compiler_get_error(struct SassCompiler* compiler);
|
75 |
| - ADDAPI const char* ADDCALL sass_compiler_get_stderr(struct SassCompiler* compiler); |
76 |
| - |
77 |
| - |
78 | 149 |
|
| 150 | + ///////////////////////////////////////////////////////////////////////// |
| 151 | + ///////////////////////////////////////////////////////////////////////// |
79 | 152 |
|
80 |
| - // ADDAPI void ADDCALL sass_compiler_set_input_path(struct SassCompiler* compiler, const char* input_path); |
81 |
| - // ADDAPI void ADDCALL sass_compiler_set_source_map_file(struct SassCompiler* compiler, const char* source_map_file); |
82 |
| - // ADDAPI void ADDCALL sass_compiler_set_source_map_root(struct SassCompiler* compiler, const char* source_map_root); |
| 153 | + // Resolve a file relative to last import or include paths in the sass option struct. |
| 154 | + ADDAPI char* ADDCALL sass_compiler_find_file(const char* path, struct SassCompiler* compiler); |
83 | 155 |
|
| 156 | + // Resolve an include relative to last import or include paths in the sass option struct. |
| 157 | + // This will do a lookup as LibSass would do internally (partials, different extensions). |
| 158 | + // ToDo: Check if we should add `includeIndex` option to check for directory index files!? |
| 159 | + ADDAPI char* ADDCALL sass_compiler_find_include(const char* path, struct SassCompiler* compiler); |
84 | 160 |
|
| 161 | + ///////////////////////////////////////////////////////////////////////// |
| 162 | + ///////////////////////////////////////////////////////////////////////// |
85 | 163 |
|
86 | 164 | #ifdef __cplusplus
|
87 | 165 | } // EO extern "C".
|
88 |
| -} // EO namespace Sass |
89 | 166 | #endif
|
90 | 167 |
|
91 | 168 | #endif
|
0 commit comments