sassc 1.8.0.pre2 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -2
  3. data/ext/libsass/contrib/plugin.cpp +4 -1
  4. data/ext/libsass/docs/README.md +20 -0
  5. data/ext/libsass/docs/api-context-example.md +45 -0
  6. data/ext/libsass/docs/api-context-internal.md +152 -0
  7. data/ext/libsass/docs/api-context.md +268 -0
  8. data/ext/libsass/docs/api-doc.md +160 -0
  9. data/ext/libsass/docs/api-function-example.md +58 -0
  10. data/ext/libsass/docs/api-function-internal.md +8 -0
  11. data/ext/libsass/docs/api-function.md +48 -0
  12. data/ext/libsass/docs/api-importer-example.md +1345 -0
  13. data/ext/libsass/docs/api-importer-internal.md +15 -0
  14. data/ext/libsass/docs/api-importer.md +84 -0
  15. data/ext/libsass/docs/api-value-example.md +0 -0
  16. data/ext/libsass/docs/api-value-internal.md +76 -0
  17. data/ext/libsass/docs/api-value.md +125 -0
  18. data/ext/libsass/docs/build-on-darwin.md +27 -0
  19. data/ext/libsass/docs/build-on-gentoo.md +55 -0
  20. data/ext/libsass/docs/build-on-windows.md +139 -0
  21. data/ext/libsass/docs/build-shared-library.md +35 -0
  22. data/ext/libsass/docs/build-with-autotools.md +68 -0
  23. data/ext/libsass/docs/build-with-makefiles.md +50 -0
  24. data/ext/libsass/docs/build-with-mingw.md +107 -0
  25. data/ext/libsass/docs/build-with-visual-studio.md +90 -0
  26. data/ext/libsass/docs/build.md +97 -0
  27. data/ext/libsass/docs/compatibility-plan.md +48 -0
  28. data/ext/libsass/docs/contributing.md +17 -0
  29. data/ext/libsass/docs/custom-functions-internal.md +120 -0
  30. data/ext/libsass/docs/implementations.md +49 -0
  31. data/ext/libsass/docs/plugins.go +47 -0
  32. data/ext/libsass/docs/setup-environment.md +68 -0
  33. data/ext/libsass/docs/source-map-internals.md +51 -0
  34. data/ext/libsass/docs/trace.md +26 -0
  35. data/ext/libsass/docs/triage.md +17 -0
  36. data/ext/libsass/docs/unicode.md +39 -0
  37. data/ext/libsass/include/sass/context.h +1 -0
  38. data/ext/libsass/include/sass/functions.h +1 -1
  39. data/ext/libsass/src/ast.cpp +12 -2
  40. data/ext/libsass/src/ast.hpp +10 -2
  41. data/ext/libsass/src/bind.cpp +0 -2
  42. data/ext/libsass/src/debug.hpp +4 -0
  43. data/ext/libsass/src/debugger.hpp +2 -1
  44. data/ext/libsass/src/emitter.cpp +2 -0
  45. data/ext/libsass/src/eval.cpp +5 -7
  46. data/ext/libsass/src/expand.cpp +8 -1
  47. data/ext/libsass/src/functions.cpp +19 -4
  48. data/ext/libsass/src/inspect.cpp +17 -0
  49. data/ext/libsass/src/json.cpp +1 -1
  50. data/ext/libsass/src/parser.cpp +10 -1
  51. data/ext/libsass/src/prelexer.cpp +1 -1
  52. data/ext/libsass/src/sass_context.cpp +1 -0
  53. data/ext/libsass/src/sass_values.cpp +1 -1
  54. data/lib/sassc/version.rb +1 -1
  55. data/test/native_test.rb +1 -1
  56. metadata +37 -4
@@ -0,0 +1,160 @@
1
+ ## Introduction
2
+
3
+ LibSass wouldn't be much good without a way to interface with it. These interface documentations describe the various functions and data structures available to implementers. They are split up over three major components, which have all their own source files (plus some common functionality).
4
+
5
+ - [Sass Context](api-context.md) - Trigger and handle the main Sass compilation
6
+ - [Sass Value](api-value.md) - Exchange values and its format with LibSass
7
+ - [Sass Function](api-function.md) - Get invoked by LibSass for function statments
8
+ - [Sass Importer](api-importer.md) - Get invoked by LibSass for @import statments
9
+
10
+ ### Basic usage
11
+
12
+ First you will need to include the header file!
13
+ This will automatically load all other headers too!
14
+
15
+ ```C
16
+ #include "sass/context.h"
17
+ ```
18
+
19
+ ### Deprecated usage
20
+
21
+ The old API is kept in the source for backward compatibility.
22
+ It's deprecated and incompatible with this documentation, use `sass/context.h`!
23
+
24
+ ```C
25
+ // deprecated interface
26
+ #include "sass_interface.h"
27
+ ```
28
+
29
+ ## Basic C Example
30
+
31
+ ```C
32
+ #include <stdio.h>
33
+ #include "sass/context.h"
34
+
35
+ int main() {
36
+ puts(libsass_VERSION());
37
+ return 0;
38
+ }
39
+ ```
40
+
41
+ ```bash
42
+ gcc -Wall version.c -lsass -o version && ./version
43
+ ```
44
+
45
+ ## More C Examples
46
+
47
+ - [Sample code for Sass Context](api-context-example.md)
48
+ - [Sample code for Sass Value](api-value-example.md)
49
+ - [Sample code for Sass Function](api-function-example.md)
50
+ - [Sample code for Sass Importer](api-importer-example.md)
51
+
52
+ ## Compiling your code
53
+
54
+ The most important is your sass file (or string of sass code). With this, you will want to start a LibSass compiler. Here is some pseudocode describing the process. The compiler has two different modes: direct input as a string with `Sass_Data_Context` or LibSass will do file reading for you by using `Sass_File_Context`. See the code for a list of options available [Sass_Options](https://github.com/sass/libsass/blob/36feef0/include/sass/interface.h#L18)
55
+
56
+ **Building a file compiler**
57
+
58
+ context = sass_make_file_context("file.scss")
59
+ options = sass_file_context_get_options(context)
60
+ sass_option_set_precision(options, 1)
61
+ sass_option_set_source_comments(options, true)
62
+
63
+ sass_file_context_set_options(context, options)
64
+
65
+ compiler = sass_make_file_compiler(sass_context)
66
+ sass_compiler_parse(compiler)
67
+ sass_compiler_execute(compiler)
68
+
69
+ output = sass_context_get_output_string(context)
70
+ // Retrieve errors during compilation
71
+ error_status = sass_context_get_error_status(context)
72
+ json_error = sass_context_get_error_json(context)
73
+ // Release memory dedicated to the C compiler
74
+ sass_delete_compiler(compiler)
75
+
76
+ **Building a data compiler**
77
+
78
+ context = sass_make_data_context("div { a { color: blue; } }")
79
+ options = sass_data_context_get_options(context)
80
+ sass_option_set_precision(options, 1)
81
+ sass_option_set_source_comments(options, true)
82
+
83
+ sass_data_context_set_options(context, options)
84
+
85
+ compiler = sass_make_data_compiler(context)
86
+ sass_compiler_parse(compiler)
87
+ sass_compiler_execute(compiler)
88
+
89
+ output = sass_context_get_output_string(context)
90
+ // div a { color: blue; }
91
+ // Retrieve errors during compilation
92
+ error_status = sass_context_get_error_status(context)
93
+ json_error = sass_context_get_error_json(context)
94
+ // Release memory dedicated to the C compiler
95
+ sass_delete_compiler(compiler)
96
+
97
+ ## Sass Context Internals
98
+
99
+ Everything is stored in structs:
100
+
101
+ ```C
102
+ struct Sass_Options;
103
+ struct Sass_Context : Sass_Options;
104
+ struct Sass_File_context : Sass_Context;
105
+ struct Sass_Data_context : Sass_Context;
106
+ ```
107
+
108
+ This mirrors very well how `libsass` uses these structures.
109
+
110
+ - `Sass_Options` holds everything you feed in before the compilation. It also hosts `input_path` and `output_path` options, because they are used to generate/calculate relative links in source-maps. The `input_path` is shared with `Sass_File_Context`.
111
+ - `Sass_Context` holds all the data returned by the compilation step.
112
+ - `Sass_File_Context` is a specific implementation that requires no additional fields
113
+ - `Sass_Data_Context` is a specific implementation that adds the `input_source` field
114
+
115
+ Structs can be down-casted to access `context` or `options`!
116
+
117
+ ## Common Pitfalls
118
+
119
+ **input_path**
120
+
121
+ The `input_path` is part of `Sass_Options`, but it also is the main option for `Sass_File_Context`. It is also used to generate relative file links in source-maps. Therefore it is pretty usefull to pass this information if you have a `Sass_Data_Context` and know the original path.
122
+
123
+ **output_path**
124
+
125
+ Be aware that `libsass` does not write the output file itself. This option merely exists to give `libsass` the proper information to generate links in source-maps. The file has to be written to the disk by the binding/implementation. If the `output_path` is omitted, `libsass` tries to extrapolate one from the `input_path` by replacing (or adding) the file ending with `.css`.
126
+
127
+ ## Error Codes
128
+
129
+ The `error_code` is integer value which indicates the type of error that occurred inside the LibSass process. Following is the list of error codes along with the short description:
130
+
131
+ * 1: normal errors like parsing or `eval` errors
132
+ * 2: bad allocation error (memory error)
133
+ * 3: "untranslated" C++ exception (`throw std::exception`)
134
+ * 4: legacy string exceptions ( `throw const char*` or `std::string` )
135
+ * 5: Some other unknown exception
136
+
137
+ Although for the API consumer, error codes do not offer much value except indicating whether *any* error occurred during the compilation, it helps debugging the LibSass internal code paths.
138
+
139
+ ## Real-World Implementations
140
+
141
+ The proof is in the pudding, so we have highlighted a few implementations that should be on par with the latest LibSass interface version. Some of them may not have all features implemented!
142
+
143
+ 1. [Perl Example](https://github.com/sass/perl-libsass/blob/master/lib/CSS/Sass.xs)
144
+ 2. [Go Example](http://godoc.org/github.com/wellington/go-libsass#example-Context-Compile)
145
+ 3. [Node Example](https://github.com/sass/node-sass/blob/master/src/binding.cpp)
146
+
147
+ ## ABI forward compatibility
148
+
149
+ We use a functional API to make dynamic linking more robust and future compatible. The API is not yet 100% stable, so we do not yet guarantee [ABI](https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html) forward compatibility. We will do so, once we increase the shared library version above 1.0.
150
+
151
+ ## Plugins (experimental)
152
+
153
+ LibSass can load plugins from directories. Just define `plugin_path` on context options to load all plugins from the given directories. To implement plugins, please consult the [[Wiki-Page for plugins|API-Plugins]].
154
+
155
+ ## Internal Structs
156
+
157
+ - [Sass Context Internals](api-context-internal.md)
158
+ - [Sass Value Internals](api-value-internal.md)
159
+ - [Sass Function Internals](api-function-internal.md)
160
+ - [Sass Importer Internals](api-importer-internal.md)
@@ -0,0 +1,58 @@
1
+ ## Example main.c
2
+
3
+ ```C
4
+ #include <stdio.h>
5
+ #include <stdint.h>
6
+ #include "sass/context.h"
7
+
8
+ union Sass_Value* call_fn_foo(const union Sass_Value* s_args, void* cookie)
9
+ {
10
+ // we actually abuse the void* to store an "int"
11
+ return sass_make_number((intptr_t)cookie, "px");
12
+ }
13
+
14
+ int main( int argc, const char* argv[] )
15
+ {
16
+
17
+ // get the input file from first argument or use default
18
+ const char* input = argc > 1 ? argv[1] : "styles.scss";
19
+
20
+ // create the file context and get all related structs
21
+ struct Sass_File_Context* file_ctx = sass_make_file_context(input);
22
+ struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
23
+ struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
24
+
25
+ // allocate a custom function caller
26
+ Sass_C_Function_Callback fn_foo =
27
+ sass_make_function("foo()", call_fn_foo, (void*)42);
28
+
29
+ // create list of all custom functions
30
+ Sass_C_Function_List fn_list = sass_make_function_list(1);
31
+ sass_function_set_list_entry(fn_list, 0, fn_foo);
32
+ sass_option_set_c_functions(ctx_opt, fn_list);
33
+
34
+ // context is set up, call the compile step now
35
+ int status = sass_compile_file_context(file_ctx);
36
+
37
+ // print the result or the error to the stdout
38
+ if (status == 0) puts(sass_context_get_output_string(ctx));
39
+ else puts(sass_context_get_error_message(ctx));
40
+
41
+ // release allocated memory
42
+ sass_delete_file_context(file_ctx);
43
+
44
+ // exit status
45
+ return status;
46
+
47
+ }
48
+ ```
49
+
50
+ ### Compile main.c
51
+
52
+ ```bash
53
+ gcc -c main.c -o main.o
54
+ gcc -o sample main.o -lsass
55
+ echo "foo { margin: foo(); }" > foo.scss
56
+ ./sample foo.scss => "foo { margin: 42px }"
57
+ ```
58
+
@@ -0,0 +1,8 @@
1
+ ```C
2
+ // Struct to hold custom function callback
3
+ struct Sass_C_Function_Descriptor {
4
+ const char* signature;
5
+ Sass_C_Function function;
6
+ void* cookie;
7
+ };
8
+ ```
@@ -0,0 +1,48 @@
1
+ Sass functions are used to define new custom functions callable by Sass code. They are also used to overload debug or error statements. You can also define a fallback function, which is called for every unknown function found in the Sass code. Functions get passed zero or more `Sass_Values` (a `Sass_List` value) and they must also return a `Sass_Value`. Return a `Sass_Error` if you want to signal an error.
2
+
3
+ ## Special signatures
4
+
5
+ - `*` - Fallback implementation
6
+ - `@warn` - Overload warn statements
7
+ - `@error` - Overload error statements
8
+ - `@debug` - Overload debug statements
9
+
10
+ Note: The fallback implementation will be given the name of the called function as the first argument, before all the original function arguments. These features are pretty new and should be considered experimental.
11
+
12
+ ### Basic Usage
13
+
14
+ ```C
15
+ #include "sass/functions.h"
16
+ ```
17
+
18
+ ## Sass Function API
19
+
20
+ ```C
21
+ // Forward declaration
22
+ struct Sass_C_Function_Descriptor;
23
+
24
+ // Typedef defining null terminated list of custom callbacks
25
+ typedef struct Sass_C_Function_Descriptor* (*Sass_C_Function_List);
26
+ typedef struct Sass_C_Function_Descriptor (*Sass_C_Function_Callback);
27
+ // Typedef defining custom function prototype and its return value type
28
+ typedef union Sass_Value*(*Sass_C_Function) (const union Sass_Value*, void* cookie);
29
+
30
+ // Creators for sass function list and function descriptors
31
+ Sass_C_Function_List sass_make_function_list (size_t length);
32
+ Sass_C_Function_Callback sass_make_function (const char* signature, Sass_C_Function fn, void* cookie);
33
+
34
+ // Setters and getters for callbacks on function lists
35
+ Sass_C_Function_Callback sass_function_get_list_entry(Sass_C_Function_List list, size_t pos);
36
+ void sass_function_set_list_entry(Sass_C_Function_List list, size_t pos, Sass_C_Function_Callback cb);
37
+
38
+ // Getters for custom function descriptors
39
+ const char* sass_function_get_signature (Sass_C_Function_Callback fn);
40
+ Sass_C_Function sass_function_get_function (Sass_C_Function_Callback fn);
41
+ void* sass_function_get_cookie (Sass_C_Function_Callback fn);
42
+ ```
43
+
44
+ ### More links
45
+
46
+ - [Sass Function Example](api-function-example.md)
47
+ - [Sass Function Internal](api-function-internal.md)
48
+
@@ -0,0 +1,1345 @@
1
+ ## Example importer.c
2
+
3
+ ```C
4
+ #include <stdio.h>
5
+ #include <string.h>
6
+ #include "sass/context.h"
7
+
8
+ Sass_Import_List sass_importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp)
9
+ {
10
+ // get the cookie from importer descriptor
11
+ void* cookie = sass_importer_get_cookie(cb);
12
+ Sass_Import_List list = sass_make_import_list(2);
13
+ const char* local = "local { color: green; }";
14
+ const char* remote = "remote { color: red; }";
15
+ list[0] = sass_make_import_entry("/tmp/styles.scss", strdup(local), 0);
16
+ list[1] = sass_make_import_entry("http://www.example.com", strdup(remote), 0);
17
+ return list;
18
+ }
19
+
20
+ int main( int argc, const char* argv[] )
21
+ {
22
+
23
+ // get the input file from first argument or use default
24
+ const char* input = argc > 1 ? argv[1] : "styles.scss";
25
+
26
+ // create the file context and get all related structs
27
+ struct Sass_File_Context* file_ctx = sass_make_file_context(input);
28
+ struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
29
+ struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
30
+
31
+ // allocate custom importer
32
+ Sass_Importer_Entry c_imp =
33
+ sass_make_importer(sass_importer, 0, 0);
34
+ // create list for all custom importers
35
+ Sass_Importer_List imp_list = sass_make_importer_list(1);
36
+ // put only the importer on to the list
37
+ sass_importer_set_list_entry(imp_list, 0, c_imp);
38
+ // register list on to the context options
39
+ sass_option_set_c_importers(ctx_opt, imp_list);
40
+ // context is set up, call the compile step now
41
+ int status = sass_compile_file_context(file_ctx);
42
+
43
+ // print the result or the error to the stdout
44
+ if (status == 0) puts(sass_context_get_output_string(ctx));
45
+ else puts(sass_context_get_error_message(ctx));
46
+
47
+ // release allocated memory
48
+ sass_delete_file_context(file_ctx);
49
+
50
+ // exit status
51
+ return status;
52
+
53
+ }
54
+ ```
55
+
56
+ Compile importer.c
57
+
58
+ ```bash
59
+ gcc -c importer.c -o importer.o
60
+ gcc -o importer importer.o -lsass
61
+ echo "@import 'foobar';" > importer.scss
62
+ ./importer importer.scss
63
+ ```
64
+
65
+ ## Importer Behavior Examples
66
+
67
+ ```C
68
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
69
+ // let LibSass handle the import request
70
+ return NULL;
71
+ }
72
+
73
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
74
+ // let LibSass handle the request
75
+ // swallows »@import "http://…"« pass-through
76
+ // (arguably a bug)
77
+ Sass_Import_List list = sass_make_import_list(1);
78
+ list[0] = sass_make_import_entry(url, 0, 0);
79
+ return list;
80
+ }
81
+
82
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
83
+ // return an error to halt execution
84
+ Sass_Import_List list = sass_make_import_list(1);
85
+ const char* message = "some error message";
86
+ list[0] = sass_make_import_entry(url, 0, 0);
87
+ sass_import_set_error(list[0], strdup(message), 0, 0);
88
+ return list;
89
+ }
90
+
91
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
92
+ // let LibSass load the file identifed by the importer
93
+ Sass_Import_List list = sass_make_import_list(1);
94
+ list[0] = sass_make_import_entry("/tmp/file.scss", 0, 0);
95
+ return list;
96
+ }
97
+
98
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
99
+ // completely hide the import
100
+ // (arguably a bug)
101
+ Sass_Import_List list = sass_make_import_list(0);
102
+ return list;
103
+ }
104
+
105
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
106
+ // completely hide the import
107
+ // (arguably a bug)
108
+ Sass_Import_List list = sass_make_import_list(1);
109
+ list[0] = sass_make_import_entry(0, 0, 0);
110
+ return list;
111
+ }
112
+ ```
113
+ ## Example importer.c
114
+
115
+ ```C
116
+ #include <stdio.h>
117
+ #include <string.h>
118
+ #include "sass/context.h"
119
+
120
+ Sass_Import_List sass_importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp)
121
+ {
122
+ // get the cookie from importer descriptor
123
+ void* cookie = sass_importer_get_cookie(cb);
124
+ Sass_Import_List list = sass_make_import_list(2);
125
+ const char* local = "local { color: green; }";
126
+ const char* remote = "remote { color: red; }";
127
+ list[0] = sass_make_import_entry("/tmp/styles.scss", strdup(local), 0);
128
+ list[1] = sass_make_import_entry("http://www.example.com", strdup(remote), 0);
129
+ return list;
130
+ }
131
+
132
+ int main( int argc, const char* argv[] )
133
+ {
134
+
135
+ // get the input file from first argument or use default
136
+ const char* input = argc > 1 ? argv[1] : "styles.scss";
137
+
138
+ // create the file context and get all related structs
139
+ struct Sass_File_Context* file_ctx = sass_make_file_context(input);
140
+ struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
141
+ struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
142
+
143
+ // allocate custom importer
144
+ Sass_Importer_Entry c_imp =
145
+ sass_make_importer(sass_importer, 0, 0);
146
+ // create list for all custom importers
147
+ Sass_Importer_List imp_list = sass_make_importer_list(1);
148
+ // put the only importer on to the list
149
+ sass_importer_set_list_entry(imp_list, 0, c_imp);
150
+ // register list on to the context options
151
+ sass_option_set_c_importers(ctx_opt, imp_list);
152
+ // context is set up, call the compile step now
153
+ int status = sass_compile_file_context(file_ctx);
154
+
155
+ // print the result or the error to the stdout
156
+ if (status == 0) puts(sass_context_get_output_string(ctx));
157
+ else puts(sass_context_get_error_message(ctx));
158
+
159
+ // release allocated memory
160
+ sass_delete_file_context(file_ctx);
161
+
162
+ // exit status
163
+ return status;
164
+
165
+ }
166
+ ```
167
+
168
+ Compile importer.c
169
+
170
+ ```bash
171
+ gcc -c importer.c -o importer.o
172
+ gcc -o importer importer.o -lsass
173
+ echo "@import 'foobar';" > importer.scss
174
+ ./importer importer.scss
175
+ ```
176
+
177
+ ## Importer Behavior Examples
178
+
179
+ ```C
180
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
181
+ // let LibSass handle the import request
182
+ return NULL;
183
+ }
184
+
185
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
186
+ // let LibSass handle the request
187
+ // swallows »@import "http://…"« pass-through
188
+ // (arguably a bug)
189
+ Sass_Import_List list = sass_make_import_list(1);
190
+ list[0] = sass_make_import_entry(url, 0, 0);
191
+ return list;
192
+ }
193
+
194
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
195
+ // return an error to halt execution
196
+ Sass_Import_List list = sass_make_import_list(1);
197
+ const char* message = "some error message";
198
+ list[0] = sass_make_import_entry(url, 0, 0);
199
+ sass_import_set_error(list[0], strdup(message), 0, 0);
200
+ return list;
201
+ }
202
+
203
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
204
+ // let LibSass load the file identifed by the importer
205
+ Sass_Import_List list = sass_make_import_list(1);
206
+ list[0] = sass_make_import_entry("/tmp/file.scss", 0, 0);
207
+ return list;
208
+ }
209
+
210
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
211
+ // completely hide the import
212
+ // (arguably a bug)
213
+ Sass_Import_List list = sass_make_import_list(0);
214
+ return list;
215
+ }
216
+
217
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
218
+ // completely hide the import
219
+ // (arguably a bug)
220
+ Sass_Import_List list = sass_make_import_list(1);
221
+ list[0] = sass_make_import_entry(0, 0, 0);
222
+ return list;
223
+ }
224
+ ```
225
+ ## Example importer.c
226
+
227
+ ```C
228
+ #include <stdio.h>
229
+ #include <string.h>
230
+ #include "sass/context.h"
231
+
232
+ Sass_Import_List sass_importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp)
233
+ {
234
+ // get the cookie from importer descriptor
235
+ void* cookie = sass_importer_get_cookie(cb);
236
+ Sass_Import_List list = sass_make_import_list(2);
237
+ const char* local = "local { color: green; }";
238
+ const char* remote = "remote { color: red; }";
239
+ list[0] = sass_make_import_entry("/tmp/styles.scss", strdup(local), 0);
240
+ list[1] = sass_make_import_entry("http://www.example.com", strdup(remote), 0);
241
+ return list;
242
+ }
243
+
244
+ int main( int argc, const char* argv[] )
245
+ {
246
+
247
+ // get the input file from first argument or use default
248
+ const char* input = argc > 1 ? argv[1] : "styles.scss";
249
+
250
+ // create the file context and get all related structs
251
+ struct Sass_File_Context* file_ctx = sass_make_file_context(input);
252
+ struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
253
+ struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
254
+
255
+ // allocate custom importer
256
+ Sass_Importer_Entry c_imp =
257
+ sass_make_importer(sass_importer, 0, 0);
258
+ // create list for all custom importers
259
+ Sass_Importer_List imp_list = sass_make_importer_list(1);
260
+ // put the only importer on to the list
261
+ sass_importer_set_list_entry(imp_list, 0, c_imp);
262
+ // register list on to the context options
263
+ sass_option_set_c_importers(ctx_opt, imp_list);
264
+ // context is set up, call the compile step now
265
+ int status = sass_compile_file_context(file_ctx);
266
+
267
+ // print the result or the error to the stdout
268
+ if (status == 0) puts(sass_context_get_output_string(ctx));
269
+ else puts(sass_context_get_error_message(ctx));
270
+
271
+ // release allocated memory
272
+ sass_delete_file_context(file_ctx);
273
+
274
+ // exit status
275
+ return status;
276
+
277
+ }
278
+ ```
279
+
280
+ Compile importer.c
281
+
282
+ ```bash
283
+ gcc -c importer.c -o importer.o
284
+ gcc -o importer importer.o -lsass
285
+ echo "@import 'foobar';" > importer.scss
286
+ ./importer importer.scss
287
+ ```
288
+
289
+ ## Importer Behavior Examples
290
+
291
+ ```C
292
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
293
+ // let LibSass handle the import request
294
+ return NULL;
295
+ }
296
+
297
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
298
+ // let LibSass handle the request
299
+ // swallows »@import "http://…"« pass-through
300
+ // (arguably a bug)
301
+ Sass_Import_List list = sass_make_import_list(1);
302
+ list[0] = sass_make_import_entry(url, 0, 0);
303
+ return list;
304
+ }
305
+
306
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
307
+ // return an error to halt execution
308
+ Sass_Import_List list = sass_make_import_list(1);
309
+ const char* message = "some error message";
310
+ list[0] = sass_make_import_entry(url, 0, 0);
311
+ sass_import_set_error(list[0], strdup(message), 0, 0);
312
+ return list;
313
+ }
314
+
315
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
316
+ // let LibSass load the file identifed by the importer
317
+ Sass_Import_List list = sass_make_import_list(1);
318
+ list[0] = sass_make_import_entry("/tmp/file.scss", 0, 0);
319
+ return list;
320
+ }
321
+
322
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
323
+ // completely hide the import
324
+ // (arguably a bug)
325
+ Sass_Import_List list = sass_make_import_list(0);
326
+ return list;
327
+ }
328
+
329
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
330
+ // completely hide the import
331
+ // (arguably a bug)
332
+ Sass_Import_List list = sass_make_import_list(1);
333
+ list[0] = sass_make_import_entry(0, 0, 0);
334
+ return list;
335
+ }
336
+ ```
337
+ ## Example importer.c
338
+
339
+ ```C
340
+ #include <stdio.h>
341
+ #include <string.h>
342
+ #include "sass/context.h"
343
+
344
+ Sass_Import_List sass_importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp)
345
+ {
346
+ // get the cookie from importer descriptor
347
+ void* cookie = sass_importer_get_cookie(cb);
348
+ Sass_Import_List list = sass_make_import_list(2);
349
+ const char* local = "local { color: green; }";
350
+ const char* remote = "remote { color: red; }";
351
+ list[0] = sass_make_import_entry("/tmp/styles.scss", strdup(local), 0);
352
+ list[1] = sass_make_import_entry("http://www.example.com", strdup(remote), 0);
353
+ return list;
354
+ }
355
+
356
+ int main( int argc, const char* argv[] )
357
+ {
358
+
359
+ // get the input file from first argument or use default
360
+ const char* input = argc > 1 ? argv[1] : "styles.scss";
361
+
362
+ // create the file context and get all related structs
363
+ struct Sass_File_Context* file_ctx = sass_make_file_context(input);
364
+ struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
365
+ struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
366
+
367
+ // allocate custom importer
368
+ Sass_Importer_Entry c_imp =
369
+ sass_make_importer(sass_importer, 0, 0);
370
+ // create list for all custom importers
371
+ Sass_Importer_List imp_list = sass_make_importer_list(1);
372
+ // put the only importer on to the list
373
+ sass_importer_set_list_entry(imp_list, 0, c_imp);
374
+ // register list on to the context options
375
+ sass_option_set_c_importers(ctx_opt, imp_list);
376
+ // context is set up, call the compile step now
377
+ int status = sass_compile_file_context(file_ctx);
378
+
379
+ // print the result or the error to the stdout
380
+ if (status == 0) puts(sass_context_get_output_string(ctx));
381
+ else puts(sass_context_get_error_message(ctx));
382
+
383
+ // release allocated memory
384
+ sass_delete_file_context(file_ctx);
385
+
386
+ // exit status
387
+ return status;
388
+
389
+ }
390
+ ```
391
+
392
+ Compile importer.c
393
+
394
+ ```bash
395
+ gcc -c importer.c -o importer.o
396
+ gcc -o importer importer.o -lsass
397
+ echo "@import 'foobar';" > importer.scss
398
+ ./importer importer.scss
399
+ ```
400
+
401
+ ## Importer Behavior Examples
402
+
403
+ ```C
404
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
405
+ // let LibSass handle the import request
406
+ return NULL;
407
+ }
408
+
409
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
410
+ // let LibSass handle the request
411
+ // swallows »@import "http://…"« pass-through
412
+ // (arguably a bug)
413
+ Sass_Import_List list = sass_make_import_list(1);
414
+ list[0] = sass_make_import_entry(url, 0, 0);
415
+ return list;
416
+ }
417
+
418
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
419
+ // return an error to halt execution
420
+ Sass_Import_List list = sass_make_import_list(1);
421
+ const char* message = "some error message";
422
+ list[0] = sass_make_import_entry(url, 0, 0);
423
+ sass_import_set_error(list[0], strdup(message), 0, 0);
424
+ return list;
425
+ }
426
+
427
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
428
+ // let LibSass load the file identifed by the importer
429
+ Sass_Import_List list = sass_make_import_list(1);
430
+ list[0] = sass_make_import_entry("/tmp/file.scss", 0, 0);
431
+ return list;
432
+ }
433
+
434
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
435
+ // completely hide the import
436
+ // (arguably a bug)
437
+ Sass_Import_List list = sass_make_import_list(0);
438
+ return list;
439
+ }
440
+
441
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
442
+ // completely hide the import
443
+ // (arguably a bug)
444
+ Sass_Import_List list = sass_make_import_list(1);
445
+ list[0] = sass_make_import_entry(0, 0, 0);
446
+ return list;
447
+ }
448
+ ```
449
+ ## Example importer.c
450
+
451
+ ```C
452
+ #include <stdio.h>
453
+ #include <string.h>
454
+ #include "sass/context.h"
455
+
456
+ Sass_Import_List sass_importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp)
457
+ {
458
+ // get the cookie from importer descriptor
459
+ void* cookie = sass_importer_get_cookie(cb);
460
+ Sass_Import_List list = sass_make_import_list(2);
461
+ const char* local = "local { color: green; }";
462
+ const char* remote = "remote { color: red; }";
463
+ list[0] = sass_make_import_entry("/tmp/styles.scss", strdup(local), 0);
464
+ list[1] = sass_make_import_entry("http://www.example.com", strdup(remote), 0);
465
+ return list;
466
+ }
467
+
468
+ int main( int argc, const char* argv[] )
469
+ {
470
+
471
+ // get the input file from first argument or use default
472
+ const char* input = argc > 1 ? argv[1] : "styles.scss";
473
+
474
+ // create the file context and get all related structs
475
+ struct Sass_File_Context* file_ctx = sass_make_file_context(input);
476
+ struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
477
+ struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
478
+
479
+ // allocate custom importer
480
+ Sass_Importer_Entry c_imp =
481
+ sass_make_importer(sass_importer, 0, 0);
482
+ // create list for all custom importers
483
+ Sass_Importer_List imp_list = sass_make_importer_list(1);
484
+ // put the only importer on to the list
485
+ sass_importer_set_list_entry(imp_list, 0, c_imp);
486
+ // register list on to the context options
487
+ sass_option_set_c_importers(ctx_opt, imp_list);
488
+ // context is set up, call the compile step now
489
+ int status = sass_compile_file_context(file_ctx);
490
+
491
+ // print the result or the error to the stdout
492
+ if (status == 0) puts(sass_context_get_output_string(ctx));
493
+ else puts(sass_context_get_error_message(ctx));
494
+
495
+ // release allocated memory
496
+ sass_delete_file_context(file_ctx);
497
+
498
+ // exit status
499
+ return status;
500
+
501
+ }
502
+ ```
503
+
504
+ Compile importer.c
505
+
506
+ ```bash
507
+ gcc -c importer.c -o importer.o
508
+ gcc -o importer importer.o -lsass
509
+ echo "@import 'foobar';" > importer.scss
510
+ ./importer importer.scss
511
+ ```
512
+
513
+ ## Importer Behavior Examples
514
+
515
+ ```C
516
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
517
+ // let LibSass handle the import request
518
+ return NULL;
519
+ }
520
+
521
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
522
+ // let LibSass handle the request
523
+ // swallows »@import "http://…"« pass-through
524
+ // (arguably a bug)
525
+ Sass_Import_List list = sass_make_import_list(1);
526
+ list[0] = sass_make_import_entry(url, 0, 0);
527
+ return list;
528
+ }
529
+
530
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
531
+ // return an error to halt execution
532
+ Sass_Import_List list = sass_make_import_list(1);
533
+ const char* message = "some error message";
534
+ list[0] = sass_make_import_entry(url, 0, 0);
535
+ sass_import_set_error(list[0], strdup(message), 0, 0);
536
+ return list;
537
+ }
538
+
539
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
540
+ // let LibSass load the file identifed by the importer
541
+ Sass_Import_List list = sass_make_import_list(1);
542
+ list[0] = sass_make_import_entry("/tmp/file.scss", 0, 0);
543
+ return list;
544
+ }
545
+
546
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
547
+ // completely hide the import
548
+ // (arguably a bug)
549
+ Sass_Import_List list = sass_make_import_list(0);
550
+ return list;
551
+ }
552
+
553
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
554
+ // completely hide the import
555
+ // (arguably a bug)
556
+ Sass_Import_List list = sass_make_import_list(1);
557
+ list[0] = sass_make_import_entry(0, 0, 0);
558
+ return list;
559
+ }
560
+ ```
561
+ ## Example importer.c
562
+
563
+ ```C
564
+ #include <stdio.h>
565
+ #include <string.h>
566
+ #include "sass/context.h"
567
+
568
+ Sass_Import_List sass_importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp)
569
+ {
570
+ // get the cookie from importer descriptor
571
+ void* cookie = sass_importer_get_cookie(cb);
572
+ Sass_Import_List list = sass_make_import_list(2);
573
+ const char* local = "local { color: green; }";
574
+ const char* remote = "remote { color: red; }";
575
+ list[0] = sass_make_import_entry("/tmp/styles.scss", strdup(local), 0);
576
+ list[1] = sass_make_import_entry("http://www.example.com", strdup(remote), 0);
577
+ return list;
578
+ }
579
+
580
+ int main( int argc, const char* argv[] )
581
+ {
582
+
583
+ // get the input file from first argument or use default
584
+ const char* input = argc > 1 ? argv[1] : "styles.scss";
585
+
586
+ // create the file context and get all related structs
587
+ struct Sass_File_Context* file_ctx = sass_make_file_context(input);
588
+ struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
589
+ struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
590
+
591
+ // allocate custom importer
592
+ Sass_Importer_Entry c_imp =
593
+ sass_make_importer(sass_importer, 0, 0);
594
+ // create list for all custom importers
595
+ Sass_Importer_List imp_list = sass_make_importer_list(1);
596
+ // put the only importer on to the list
597
+ sass_importer_set_list_entry(imp_list, 0, c_imp);
598
+ // register list on to the context options
599
+ sass_option_set_c_importers(ctx_opt, imp_list);
600
+ // context is set up, call the compile step now
601
+ int status = sass_compile_file_context(file_ctx);
602
+
603
+ // print the result or the error to the stdout
604
+ if (status == 0) puts(sass_context_get_output_string(ctx));
605
+ else puts(sass_context_get_error_message(ctx));
606
+
607
+ // release allocated memory
608
+ sass_delete_file_context(file_ctx);
609
+
610
+ // exit status
611
+ return status;
612
+
613
+ }
614
+ ```
615
+
616
+ Compile importer.c
617
+
618
+ ```bash
619
+ gcc -c importer.c -o importer.o
620
+ gcc -o importer importer.o -lsass
621
+ echo "@import 'foobar';" > importer.scss
622
+ ./importer importer.scss
623
+ ```
624
+
625
+ ## Importer Behavior Examples
626
+
627
+ ```C
628
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
629
+ // let LibSass handle the import request
630
+ return NULL;
631
+ }
632
+
633
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
634
+ // let LibSass handle the request
635
+ // swallows »@import "http://…"« pass-through
636
+ // (arguably a bug)
637
+ Sass_Import_List list = sass_make_import_list(1);
638
+ list[0] = sass_make_import_entry(url, 0, 0);
639
+ return list;
640
+ }
641
+
642
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
643
+ // return an error to halt execution
644
+ Sass_Import_List list = sass_make_import_list(1);
645
+ const char* message = "some error message";
646
+ list[0] = sass_make_import_entry(url, 0, 0);
647
+ sass_import_set_error(list[0], strdup(message), 0, 0);
648
+ return list;
649
+ }
650
+
651
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
652
+ // let LibSass load the file identifed by the importer
653
+ Sass_Import_List list = sass_make_import_list(1);
654
+ list[0] = sass_make_import_entry("/tmp/file.scss", 0, 0);
655
+ return list;
656
+ }
657
+
658
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
659
+ // completely hide the import
660
+ // (arguably a bug)
661
+ Sass_Import_List list = sass_make_import_list(0);
662
+ return list;
663
+ }
664
+
665
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
666
+ // completely hide the import
667
+ // (arguably a bug)
668
+ Sass_Import_List list = sass_make_import_list(1);
669
+ list[0] = sass_make_import_entry(0, 0, 0);
670
+ return list;
671
+ }
672
+ ```
673
+ ## Example importer.c
674
+
675
+ ```C
676
+ #include <stdio.h>
677
+ #include <string.h>
678
+ #include "sass/context.h"
679
+
680
+ Sass_Import_List sass_importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp)
681
+ {
682
+ // get the cookie from importer descriptor
683
+ void* cookie = sass_importer_get_cookie(cb);
684
+ Sass_Import_List list = sass_make_import_list(2);
685
+ const char* local = "local { color: green; }";
686
+ const char* remote = "remote { color: red; }";
687
+ list[0] = sass_make_import_entry("/tmp/styles.scss", strdup(local), 0);
688
+ list[1] = sass_make_import_entry("http://www.example.com", strdup(remote), 0);
689
+ return list;
690
+ }
691
+
692
+ int main( int argc, const char* argv[] )
693
+ {
694
+
695
+ // get the input file from first argument or use default
696
+ const char* input = argc > 1 ? argv[1] : "styles.scss";
697
+
698
+ // create the file context and get all related structs
699
+ struct Sass_File_Context* file_ctx = sass_make_file_context(input);
700
+ struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
701
+ struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
702
+
703
+ // allocate custom importer
704
+ Sass_Importer_Entry c_imp =
705
+ sass_make_importer(sass_importer, 0, 0);
706
+ // create list for all custom importers
707
+ Sass_Importer_List imp_list = sass_make_importer_list(1);
708
+ // put the only importer on to the list
709
+ sass_importer_set_list_entry(imp_list, 0, c_imp);
710
+ // register list on to the context options
711
+ sass_option_set_c_importers(ctx_opt, imp_list);
712
+ // context is set up, call the compile step now
713
+ int status = sass_compile_file_context(file_ctx);
714
+
715
+ // print the result or the error to the stdout
716
+ if (status == 0) puts(sass_context_get_output_string(ctx));
717
+ else puts(sass_context_get_error_message(ctx));
718
+
719
+ // release allocated memory
720
+ sass_delete_file_context(file_ctx);
721
+
722
+ // exit status
723
+ return status;
724
+
725
+ }
726
+ ```
727
+
728
+ Compile importer.c
729
+
730
+ ```bash
731
+ gcc -c importer.c -o importer.o
732
+ gcc -o importer importer.o -lsass
733
+ echo "@import 'foobar';" > importer.scss
734
+ ./importer importer.scss
735
+ ```
736
+
737
+ ## Importer Behavior Examples
738
+
739
+ ```C
740
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
741
+ // let LibSass handle the import request
742
+ return NULL;
743
+ }
744
+
745
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
746
+ // let LibSass handle the request
747
+ // swallows »@import "http://…"« pass-through
748
+ // (arguably a bug)
749
+ Sass_Import_List list = sass_make_import_list(1);
750
+ list[0] = sass_make_import_entry(url, 0, 0);
751
+ return list;
752
+ }
753
+
754
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
755
+ // return an error to halt execution
756
+ Sass_Import_List list = sass_make_import_list(1);
757
+ const char* message = "some error message";
758
+ list[0] = sass_make_import_entry(url, 0, 0);
759
+ sass_import_set_error(list[0], strdup(message), 0, 0);
760
+ return list;
761
+ }
762
+
763
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
764
+ // let LibSass load the file identifed by the importer
765
+ Sass_Import_List list = sass_make_import_list(1);
766
+ list[0] = sass_make_import_entry("/tmp/file.scss", 0, 0);
767
+ return list;
768
+ }
769
+
770
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
771
+ // completely hide the import
772
+ // (arguably a bug)
773
+ Sass_Import_List list = sass_make_import_list(0);
774
+ return list;
775
+ }
776
+
777
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
778
+ // completely hide the import
779
+ // (arguably a bug)
780
+ Sass_Import_List list = sass_make_import_list(1);
781
+ list[0] = sass_make_import_entry(0, 0, 0);
782
+ return list;
783
+ }
784
+ ```
785
+ ## Example importer.c
786
+
787
+ ```C
788
+ #include <stdio.h>
789
+ #include <string.h>
790
+ #include "sass/context.h"
791
+
792
+ Sass_Import_List sass_importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp)
793
+ {
794
+ // get the cookie from importer descriptor
795
+ void* cookie = sass_importer_get_cookie(cb);
796
+ Sass_Import_List list = sass_make_import_list(2);
797
+ const char* local = "local { color: green; }";
798
+ const char* remote = "remote { color: red; }";
799
+ list[0] = sass_make_import_entry("/tmp/styles.scss", strdup(local), 0);
800
+ list[1] = sass_make_import_entry("http://www.example.com", strdup(remote), 0);
801
+ return list;
802
+ }
803
+
804
+ int main( int argc, const char* argv[] )
805
+ {
806
+
807
+ // get the input file from first argument or use default
808
+ const char* input = argc > 1 ? argv[1] : "styles.scss";
809
+
810
+ // create the file context and get all related structs
811
+ struct Sass_File_Context* file_ctx = sass_make_file_context(input);
812
+ struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
813
+ struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
814
+
815
+ // allocate custom importer
816
+ Sass_Importer_Entry c_imp =
817
+ sass_make_importer(sass_importer, 0, 0);
818
+ // create list for all custom importers
819
+ Sass_Importer_List imp_list = sass_make_importer_list(1);
820
+ // put the only importer on to the list
821
+ sass_importer_set_list_entry(imp_list, 0, c_imp);
822
+ // register list on to the context options
823
+ sass_option_set_c_importers(ctx_opt, imp_list);
824
+ // context is set up, call the compile step now
825
+ int status = sass_compile_file_context(file_ctx);
826
+
827
+ // print the result or the error to the stdout
828
+ if (status == 0) puts(sass_context_get_output_string(ctx));
829
+ else puts(sass_context_get_error_message(ctx));
830
+
831
+ // release allocated memory
832
+ sass_delete_file_context(file_ctx);
833
+
834
+ // exit status
835
+ return status;
836
+
837
+ }
838
+ ```
839
+
840
+ Compile importer.c
841
+
842
+ ```bash
843
+ gcc -c importer.c -o importer.o
844
+ gcc -o importer importer.o -lsass
845
+ echo "@import 'foobar';" > importer.scss
846
+ ./importer importer.scss
847
+ ```
848
+
849
+ ## Importer Behavior Examples
850
+
851
+ ```C
852
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
853
+ // let LibSass handle the import request
854
+ return NULL;
855
+ }
856
+
857
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
858
+ // let LibSass handle the request
859
+ // swallows »@import "http://…"« pass-through
860
+ // (arguably a bug)
861
+ Sass_Import_List list = sass_make_import_list(1);
862
+ list[0] = sass_make_import_entry(url, 0, 0);
863
+ return list;
864
+ }
865
+
866
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
867
+ // return an error to halt execution
868
+ Sass_Import_List list = sass_make_import_list(1);
869
+ const char* message = "some error message";
870
+ list[0] = sass_make_import_entry(url, 0, 0);
871
+ sass_import_set_error(list[0], strdup(message), 0, 0);
872
+ return list;
873
+ }
874
+
875
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
876
+ // let LibSass load the file identifed by the importer
877
+ Sass_Import_List list = sass_make_import_list(1);
878
+ list[0] = sass_make_import_entry("/tmp/file.scss", 0, 0);
879
+ return list;
880
+ }
881
+
882
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
883
+ // completely hide the import
884
+ // (arguably a bug)
885
+ Sass_Import_List list = sass_make_import_list(0);
886
+ return list;
887
+ }
888
+
889
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
890
+ // completely hide the import
891
+ // (arguably a bug)
892
+ Sass_Import_List list = sass_make_import_list(1);
893
+ list[0] = sass_make_import_entry(0, 0, 0);
894
+ return list;
895
+ }
896
+ ```
897
+ ## Example importer.c
898
+
899
+ ```C
900
+ #include <stdio.h>
901
+ #include <string.h>
902
+ #include "sass/context.h"
903
+
904
+ Sass_Import_List sass_importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp)
905
+ {
906
+ // get the cookie from importer descriptor
907
+ void* cookie = sass_importer_get_cookie(cb);
908
+ Sass_Import_List list = sass_make_import_list(2);
909
+ const char* local = "local { color: green; }";
910
+ const char* remote = "remote { color: red; }";
911
+ list[0] = sass_make_import_entry("/tmp/styles.scss", strdup(local), 0);
912
+ list[1] = sass_make_import_entry("http://www.example.com", strdup(remote), 0);
913
+ return list;
914
+ }
915
+
916
+ int main( int argc, const char* argv[] )
917
+ {
918
+
919
+ // get the input file from first argument or use default
920
+ const char* input = argc > 1 ? argv[1] : "styles.scss";
921
+
922
+ // create the file context and get all related structs
923
+ struct Sass_File_Context* file_ctx = sass_make_file_context(input);
924
+ struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
925
+ struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
926
+
927
+ // allocate custom importer
928
+ Sass_Importer_Entry c_imp =
929
+ sass_make_importer(sass_importer, 0, 0);
930
+ // create list for all custom importers
931
+ Sass_Importer_List imp_list = sass_make_importer_list(1);
932
+ // put the only importer on to the list
933
+ sass_importer_set_list_entry(imp_list, 0, c_imp);
934
+ // register list on to the context options
935
+ sass_option_set_c_importers(ctx_opt, imp_list);
936
+ // context is set up, call the compile step now
937
+ int status = sass_compile_file_context(file_ctx);
938
+
939
+ // print the result or the error to the stdout
940
+ if (status == 0) puts(sass_context_get_output_string(ctx));
941
+ else puts(sass_context_get_error_message(ctx));
942
+
943
+ // release allocated memory
944
+ sass_delete_file_context(file_ctx);
945
+
946
+ // exit status
947
+ return status;
948
+
949
+ }
950
+ ```
951
+
952
+ Compile importer.c
953
+
954
+ ```bash
955
+ gcc -c importer.c -o importer.o
956
+ gcc -o importer importer.o -lsass
957
+ echo "@import 'foobar';" > importer.scss
958
+ ./importer importer.scss
959
+ ```
960
+
961
+ ## Importer Behavior Examples
962
+
963
+ ```C
964
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
965
+ // let LibSass handle the import request
966
+ return NULL;
967
+ }
968
+
969
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
970
+ // let LibSass handle the request
971
+ // swallows »@import "http://…"« pass-through
972
+ // (arguably a bug)
973
+ Sass_Import_List list = sass_make_import_list(1);
974
+ list[0] = sass_make_import_entry(url, 0, 0);
975
+ return list;
976
+ }
977
+
978
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
979
+ // return an error to halt execution
980
+ Sass_Import_List list = sass_make_import_list(1);
981
+ const char* message = "some error message";
982
+ list[0] = sass_make_import_entry(url, 0, 0);
983
+ sass_import_set_error(list[0], strdup(message), 0, 0);
984
+ return list;
985
+ }
986
+
987
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
988
+ // let LibSass load the file identifed by the importer
989
+ Sass_Import_List list = sass_make_import_list(1);
990
+ list[0] = sass_make_import_entry("/tmp/file.scss", 0, 0);
991
+ return list;
992
+ }
993
+
994
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
995
+ // completely hide the import
996
+ // (arguably a bug)
997
+ Sass_Import_List list = sass_make_import_list(0);
998
+ return list;
999
+ }
1000
+
1001
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1002
+ // completely hide the import
1003
+ // (arguably a bug)
1004
+ Sass_Import_List list = sass_make_import_list(1);
1005
+ list[0] = sass_make_import_entry(0, 0, 0);
1006
+ return list;
1007
+ }
1008
+ ```
1009
+ ## Example importer.c
1010
+
1011
+ ```C
1012
+ #include <stdio.h>
1013
+ #include <string.h>
1014
+ #include "sass/context.h"
1015
+
1016
+ Sass_Import_List sass_importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp)
1017
+ {
1018
+ // get the cookie from importer descriptor
1019
+ void* cookie = sass_importer_get_cookie(cb);
1020
+ Sass_Import_List list = sass_make_import_list(2);
1021
+ const char* local = "local { color: green; }";
1022
+ const char* remote = "remote { color: red; }";
1023
+ list[0] = sass_make_import_entry("/tmp/styles.scss", strdup(local), 0);
1024
+ list[1] = sass_make_import_entry("http://www.example.com", strdup(remote), 0);
1025
+ return list;
1026
+ }
1027
+
1028
+ int main( int argc, const char* argv[] )
1029
+ {
1030
+
1031
+ // get the input file from first argument or use default
1032
+ const char* input = argc > 1 ? argv[1] : "styles.scss";
1033
+
1034
+ // create the file context and get all related structs
1035
+ struct Sass_File_Context* file_ctx = sass_make_file_context(input);
1036
+ struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
1037
+ struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
1038
+
1039
+ // allocate custom importer
1040
+ Sass_Importer_Entry c_imp =
1041
+ sass_make_importer(sass_importer, 0, 0);
1042
+ // create list for all custom importers
1043
+ Sass_Importer_List imp_list = sass_make_importer_list(1);
1044
+ // put the only importer on to the list
1045
+ sass_importer_set_list_entry(imp_list, 0, c_imp);
1046
+ // register list on to the context options
1047
+ sass_option_set_c_importers(ctx_opt, imp_list);
1048
+ // context is set up, call the compile step now
1049
+ int status = sass_compile_file_context(file_ctx);
1050
+
1051
+ // print the result or the error to the stdout
1052
+ if (status == 0) puts(sass_context_get_output_string(ctx));
1053
+ else puts(sass_context_get_error_message(ctx));
1054
+
1055
+ // release allocated memory
1056
+ sass_delete_file_context(file_ctx);
1057
+
1058
+ // exit status
1059
+ return status;
1060
+
1061
+ }
1062
+ ```
1063
+
1064
+ Compile importer.c
1065
+
1066
+ ```bash
1067
+ gcc -c importer.c -o importer.o
1068
+ gcc -o importer importer.o -lsass
1069
+ echo "@import 'foobar';" > importer.scss
1070
+ ./importer importer.scss
1071
+ ```
1072
+
1073
+ ## Importer Behavior Examples
1074
+
1075
+ ```C
1076
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1077
+ // let LibSass handle the import request
1078
+ return NULL;
1079
+ }
1080
+
1081
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1082
+ // let LibSass handle the request
1083
+ // swallows »@import "http://…"« pass-through
1084
+ // (arguably a bug)
1085
+ Sass_Import_List list = sass_make_import_list(1);
1086
+ list[0] = sass_make_import_entry(url, 0, 0);
1087
+ return list;
1088
+ }
1089
+
1090
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1091
+ // return an error to halt execution
1092
+ Sass_Import_List list = sass_make_import_list(1);
1093
+ const char* message = "some error message";
1094
+ list[0] = sass_make_import_entry(url, 0, 0);
1095
+ sass_import_set_error(list[0], strdup(message), 0, 0);
1096
+ return list;
1097
+ }
1098
+
1099
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1100
+ // let LibSass load the file identifed by the importer
1101
+ Sass_Import_List list = sass_make_import_list(1);
1102
+ list[0] = sass_make_import_entry("/tmp/file.scss", 0, 0);
1103
+ return list;
1104
+ }
1105
+
1106
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1107
+ // completely hide the import
1108
+ // (arguably a bug)
1109
+ Sass_Import_List list = sass_make_import_list(0);
1110
+ return list;
1111
+ }
1112
+
1113
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1114
+ // completely hide the import
1115
+ // (arguably a bug)
1116
+ Sass_Import_List list = sass_make_import_list(1);
1117
+ list[0] = sass_make_import_entry(0, 0, 0);
1118
+ return list;
1119
+ }
1120
+ ```
1121
+ ## Example importer.c
1122
+
1123
+ ```C
1124
+ #include <stdio.h>
1125
+ #include <string.h>
1126
+ #include "sass/context.h"
1127
+
1128
+ Sass_Import_List sass_importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp)
1129
+ {
1130
+ // get the cookie from importer descriptor
1131
+ void* cookie = sass_importer_get_cookie(cb);
1132
+ Sass_Import_List list = sass_make_import_list(2);
1133
+ const char* local = "local { color: green; }";
1134
+ const char* remote = "remote { color: red; }";
1135
+ list[0] = sass_make_import_entry("/tmp/styles.scss", strdup(local), 0);
1136
+ list[1] = sass_make_import_entry("http://www.example.com", strdup(remote), 0);
1137
+ return list;
1138
+ }
1139
+
1140
+ int main( int argc, const char* argv[] )
1141
+ {
1142
+
1143
+ // get the input file from first argument or use default
1144
+ const char* input = argc > 1 ? argv[1] : "styles.scss";
1145
+
1146
+ // create the file context and get all related structs
1147
+ struct Sass_File_Context* file_ctx = sass_make_file_context(input);
1148
+ struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
1149
+ struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
1150
+
1151
+ // allocate custom importer
1152
+ Sass_Importer_Entry c_imp =
1153
+ sass_make_importer(sass_importer, 0, 0);
1154
+ // create list for all custom importers
1155
+ Sass_Importer_List imp_list = sass_make_importer_list(1);
1156
+ // put the only importer on to the list
1157
+ sass_importer_set_list_entry(imp_list, 0, c_imp);
1158
+ // register list on to the context options
1159
+ sass_option_set_c_importers(ctx_opt, imp_list);
1160
+ // context is set up, call the compile step now
1161
+ int status = sass_compile_file_context(file_ctx);
1162
+
1163
+ // print the result or the error to the stdout
1164
+ if (status == 0) puts(sass_context_get_output_string(ctx));
1165
+ else puts(sass_context_get_error_message(ctx));
1166
+
1167
+ // release allocated memory
1168
+ sass_delete_file_context(file_ctx);
1169
+
1170
+ // exit status
1171
+ return status;
1172
+
1173
+ }
1174
+ ```
1175
+
1176
+ Compile importer.c
1177
+
1178
+ ```bash
1179
+ gcc -c importer.c -o importer.o
1180
+ gcc -o importer importer.o -lsass
1181
+ echo "@import 'foobar';" > importer.scss
1182
+ ./importer importer.scss
1183
+ ```
1184
+
1185
+ ## Importer Behavior Examples
1186
+
1187
+ ```C
1188
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1189
+ // let LibSass handle the import request
1190
+ return NULL;
1191
+ }
1192
+
1193
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1194
+ // let LibSass handle the request
1195
+ // swallows »@import "http://…"« pass-through
1196
+ // (arguably a bug)
1197
+ Sass_Import_List list = sass_make_import_list(1);
1198
+ list[0] = sass_make_import_entry(url, 0, 0);
1199
+ return list;
1200
+ }
1201
+
1202
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1203
+ // return an error to halt execution
1204
+ Sass_Import_List list = sass_make_import_list(1);
1205
+ const char* message = "some error message";
1206
+ list[0] = sass_make_import_entry(url, 0, 0);
1207
+ sass_import_set_error(list[0], strdup(message), 0, 0);
1208
+ return list;
1209
+ }
1210
+
1211
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1212
+ // let LibSass load the file identifed by the importer
1213
+ Sass_Import_List list = sass_make_import_list(1);
1214
+ list[0] = sass_make_import_entry("/tmp/file.scss", 0, 0);
1215
+ return list;
1216
+ }
1217
+
1218
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1219
+ // completely hide the import
1220
+ // (arguably a bug)
1221
+ Sass_Import_List list = sass_make_import_list(0);
1222
+ return list;
1223
+ }
1224
+
1225
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1226
+ // completely hide the import
1227
+ // (arguably a bug)
1228
+ Sass_Import_List list = sass_make_import_list(1);
1229
+ list[0] = sass_make_import_entry(0, 0, 0);
1230
+ return list;
1231
+ }
1232
+ ```
1233
+ ## Example importer.c
1234
+
1235
+ ```C
1236
+ #include <stdio.h>
1237
+ #include <string.h>
1238
+ #include "sass/context.h"
1239
+
1240
+ Sass_Import_List sass_importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp)
1241
+ {
1242
+ // get the cookie from importer descriptor
1243
+ void* cookie = sass_importer_get_cookie(cb);
1244
+ Sass_Import_List list = sass_make_import_list(2);
1245
+ const char* local = "local { color: green; }";
1246
+ const char* remote = "remote { color: red; }";
1247
+ list[0] = sass_make_import_entry("/tmp/styles.scss", strdup(local), 0);
1248
+ list[1] = sass_make_import_entry("http://www.example.com", strdup(remote), 0);
1249
+ return list;
1250
+ }
1251
+
1252
+ int main( int argc, const char* argv[] )
1253
+ {
1254
+
1255
+ // get the input file from first argument or use default
1256
+ const char* input = argc > 1 ? argv[1] : "styles.scss";
1257
+
1258
+ // create the file context and get all related structs
1259
+ struct Sass_File_Context* file_ctx = sass_make_file_context(input);
1260
+ struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
1261
+ struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
1262
+
1263
+ // allocate custom importer
1264
+ Sass_Importer_Entry c_imp =
1265
+ sass_make_importer(sass_importer, 0, 0);
1266
+ // create list for all custom importers
1267
+ Sass_Importer_List imp_list = sass_make_importer_list(1);
1268
+ // put the only importer on to the list
1269
+ sass_importer_set_list_entry(imp_list, 0, c_imp);
1270
+ // register list on to the context options
1271
+ sass_option_set_c_importers(ctx_opt, imp_list);
1272
+ // context is set up, call the compile step now
1273
+ int status = sass_compile_file_context(file_ctx);
1274
+
1275
+ // print the result or the error to the stdout
1276
+ if (status == 0) puts(sass_context_get_output_string(ctx));
1277
+ else puts(sass_context_get_error_message(ctx));
1278
+
1279
+ // release allocated memory
1280
+ sass_delete_file_context(file_ctx);
1281
+
1282
+ // exit status
1283
+ return status;
1284
+
1285
+ }
1286
+ ```
1287
+
1288
+ Compile importer.c
1289
+
1290
+ ```bash
1291
+ gcc -c importer.c -o importer.o
1292
+ gcc -o importer importer.o -lsass
1293
+ echo "@import 'foobar';" > importer.scss
1294
+ ./importer importer.scss
1295
+ ```
1296
+
1297
+ ## Importer Behavior Examples
1298
+
1299
+ ```C
1300
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1301
+ // let LibSass handle the import request
1302
+ return NULL;
1303
+ }
1304
+
1305
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1306
+ // let LibSass handle the request
1307
+ // swallows »@import "http://…"« pass-through
1308
+ // (arguably a bug)
1309
+ Sass_Import_List list = sass_make_import_list(1);
1310
+ list[0] = sass_make_import_entry(url, 0, 0);
1311
+ return list;
1312
+ }
1313
+
1314
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1315
+ // return an error to halt execution
1316
+ Sass_Import_List list = sass_make_import_list(1);
1317
+ const char* message = "some error message";
1318
+ list[0] = sass_make_import_entry(url, 0, 0);
1319
+ sass_import_set_error(list[0], strdup(message), 0, 0);
1320
+ return list;
1321
+ }
1322
+
1323
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1324
+ // let LibSass load the file identifed by the importer
1325
+ Sass_Import_List list = sass_make_import_list(1);
1326
+ list[0] = sass_make_import_entry("/tmp/file.scss", 0, 0);
1327
+ return list;
1328
+ }
1329
+
1330
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1331
+ // completely hide the import
1332
+ // (arguably a bug)
1333
+ Sass_Import_List list = sass_make_import_list(0);
1334
+ return list;
1335
+ }
1336
+
1337
+ Sass_Import_List importer(const char* path, Sass_Importer_Entry cb, struct Sass_Compiler* comp) {
1338
+ // completely hide the import
1339
+ // (arguably a bug)
1340
+ Sass_Import_List list = sass_make_import_list(1);
1341
+ list[0] = sass_make_import_entry(0, 0, 0);
1342
+ return list;
1343
+ }
1344
+ ```
1345
+