sassc 2.0.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.gitmodules +1 -1
- data/.travis.yml +9 -3
- data/CHANGELOG.md +36 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/README.md +1 -1
- data/Rakefile +43 -7
- data/ext/depend +4 -0
- data/ext/extconf.rb +92 -0
- data/ext/libsass/VERSION +1 -0
- data/ext/libsass/include/sass/base.h +9 -1
- data/ext/libsass/include/sass/context.h +5 -1
- data/ext/libsass/src/MurmurHash2.hpp +91 -0
- data/ext/libsass/src/ast.cpp +755 -2028
- data/ext/libsass/src/ast.hpp +492 -2477
- data/ext/libsass/src/{to_c.cpp → ast2c.cpp} +22 -16
- data/ext/libsass/src/ast2c.hpp +39 -0
- data/ext/libsass/src/ast_def_macros.hpp +70 -10
- data/ext/libsass/src/ast_fwd_decl.cpp +5 -3
- data/ext/libsass/src/ast_fwd_decl.hpp +107 -296
- data/ext/libsass/src/ast_helpers.hpp +292 -0
- data/ext/libsass/src/ast_sel_cmp.cpp +396 -0
- data/ext/libsass/src/ast_sel_super.cpp +539 -0
- data/ext/libsass/src/ast_sel_unify.cpp +275 -0
- data/ext/libsass/src/ast_sel_weave.cpp +616 -0
- data/ext/libsass/src/ast_selectors.cpp +1043 -0
- data/ext/libsass/src/ast_selectors.hpp +522 -0
- data/ext/libsass/src/ast_supports.cpp +114 -0
- data/ext/libsass/src/ast_supports.hpp +121 -0
- data/ext/libsass/src/ast_values.cpp +1154 -0
- data/ext/libsass/src/ast_values.hpp +498 -0
- data/ext/libsass/src/backtrace.cpp +11 -7
- data/ext/libsass/src/backtrace.hpp +5 -5
- data/ext/libsass/src/base64vlq.cpp +5 -2
- data/ext/libsass/src/base64vlq.hpp +1 -1
- data/ext/libsass/src/bind.cpp +35 -34
- data/ext/libsass/src/bind.hpp +3 -1
- data/ext/libsass/src/c2ast.cpp +64 -0
- data/ext/libsass/src/c2ast.hpp +14 -0
- data/ext/libsass/src/cencode.c +4 -6
- data/ext/libsass/src/check_nesting.cpp +83 -88
- data/ext/libsass/src/check_nesting.hpp +39 -34
- data/ext/libsass/src/color_maps.cpp +168 -164
- data/ext/libsass/src/color_maps.hpp +152 -160
- data/ext/libsass/src/constants.cpp +20 -0
- data/ext/libsass/src/constants.hpp +19 -0
- data/ext/libsass/src/context.cpp +104 -121
- data/ext/libsass/src/context.hpp +43 -55
- data/ext/libsass/src/cssize.cpp +103 -188
- data/ext/libsass/src/cssize.hpp +45 -51
- data/ext/libsass/src/dart_helpers.hpp +199 -0
- data/ext/libsass/src/debugger.hpp +524 -361
- data/ext/libsass/src/emitter.cpp +26 -26
- data/ext/libsass/src/emitter.hpp +20 -18
- data/ext/libsass/src/environment.cpp +41 -27
- data/ext/libsass/src/environment.hpp +33 -22
- data/ext/libsass/src/error_handling.cpp +92 -94
- data/ext/libsass/src/error_handling.hpp +73 -50
- data/ext/libsass/src/eval.cpp +380 -515
- data/ext/libsass/src/eval.hpp +64 -57
- data/ext/libsass/src/eval_selectors.cpp +75 -0
- data/ext/libsass/src/expand.cpp +322 -263
- data/ext/libsass/src/expand.hpp +55 -39
- data/ext/libsass/src/extender.cpp +1188 -0
- data/ext/libsass/src/extender.hpp +399 -0
- data/ext/libsass/src/extension.cpp +43 -0
- data/ext/libsass/src/extension.hpp +89 -0
- data/ext/libsass/src/file.cpp +134 -88
- data/ext/libsass/src/file.hpp +28 -37
- data/ext/libsass/src/fn_colors.cpp +596 -0
- data/ext/libsass/src/fn_colors.hpp +85 -0
- data/ext/libsass/src/fn_lists.cpp +285 -0
- data/ext/libsass/src/fn_lists.hpp +34 -0
- data/ext/libsass/src/fn_maps.cpp +94 -0
- data/ext/libsass/src/fn_maps.hpp +30 -0
- data/ext/libsass/src/fn_miscs.cpp +244 -0
- data/ext/libsass/src/fn_miscs.hpp +40 -0
- data/ext/libsass/src/fn_numbers.cpp +227 -0
- data/ext/libsass/src/fn_numbers.hpp +45 -0
- data/ext/libsass/src/fn_selectors.cpp +205 -0
- data/ext/libsass/src/fn_selectors.hpp +35 -0
- data/ext/libsass/src/fn_strings.cpp +268 -0
- data/ext/libsass/src/fn_strings.hpp +34 -0
- data/ext/libsass/src/fn_utils.cpp +158 -0
- data/ext/libsass/src/fn_utils.hpp +62 -0
- data/ext/libsass/src/inspect.cpp +253 -266
- data/ext/libsass/src/inspect.hpp +72 -74
- data/ext/libsass/src/json.cpp +2 -2
- data/ext/libsass/src/lexer.cpp +25 -84
- data/ext/libsass/src/lexer.hpp +5 -16
- data/ext/libsass/src/listize.cpp +27 -43
- data/ext/libsass/src/listize.hpp +14 -11
- data/ext/libsass/src/mapping.hpp +1 -0
- data/ext/libsass/src/memory.hpp +12 -0
- data/ext/libsass/src/memory/allocator.cpp +48 -0
- data/ext/libsass/src/memory/allocator.hpp +138 -0
- data/ext/libsass/src/memory/config.hpp +20 -0
- data/ext/libsass/src/memory/memory_pool.hpp +186 -0
- data/ext/libsass/src/memory/shared_ptr.cpp +33 -0
- data/ext/libsass/src/memory/shared_ptr.hpp +332 -0
- data/ext/libsass/src/operation.hpp +193 -143
- data/ext/libsass/src/operators.cpp +56 -29
- data/ext/libsass/src/operators.hpp +11 -11
- data/ext/libsass/src/ordered_map.hpp +112 -0
- data/ext/libsass/src/output.cpp +59 -75
- data/ext/libsass/src/output.hpp +15 -22
- data/ext/libsass/src/parser.cpp +662 -818
- data/ext/libsass/src/parser.hpp +96 -100
- data/ext/libsass/src/parser_selectors.cpp +189 -0
- data/ext/libsass/src/permutate.hpp +164 -0
- data/ext/libsass/src/plugins.cpp +12 -8
- data/ext/libsass/src/plugins.hpp +8 -8
- data/ext/libsass/src/position.cpp +10 -26
- data/ext/libsass/src/position.hpp +44 -21
- data/ext/libsass/src/prelexer.cpp +14 -8
- data/ext/libsass/src/prelexer.hpp +9 -9
- data/ext/libsass/src/remove_placeholders.cpp +59 -57
- data/ext/libsass/src/remove_placeholders.hpp +20 -18
- data/ext/libsass/src/sass.cpp +25 -18
- data/ext/libsass/src/sass.hpp +22 -14
- data/ext/libsass/src/sass2scss.cpp +49 -18
- data/ext/libsass/src/sass_context.cpp +104 -132
- data/ext/libsass/src/sass_context.hpp +2 -2
- data/ext/libsass/src/sass_functions.cpp +7 -4
- data/ext/libsass/src/sass_functions.hpp +1 -1
- data/ext/libsass/src/sass_values.cpp +26 -21
- data/ext/libsass/src/settings.hpp +19 -0
- data/ext/libsass/src/source.cpp +69 -0
- data/ext/libsass/src/source.hpp +95 -0
- data/ext/libsass/src/source_data.hpp +32 -0
- data/ext/libsass/src/source_map.cpp +27 -20
- data/ext/libsass/src/source_map.hpp +14 -11
- data/ext/libsass/src/stylesheet.cpp +22 -0
- data/ext/libsass/src/stylesheet.hpp +57 -0
- data/ext/libsass/src/to_value.cpp +24 -22
- data/ext/libsass/src/to_value.hpp +18 -22
- data/ext/libsass/src/units.cpp +28 -22
- data/ext/libsass/src/units.hpp +9 -8
- data/ext/libsass/src/utf8/checked.h +12 -10
- data/ext/libsass/src/utf8/core.h +3 -0
- data/ext/libsass/src/utf8_string.cpp +12 -10
- data/ext/libsass/src/utf8_string.hpp +7 -6
- data/ext/libsass/src/util.cpp +97 -107
- data/ext/libsass/src/util.hpp +74 -30
- data/ext/libsass/src/util_string.cpp +125 -0
- data/ext/libsass/src/util_string.hpp +73 -0
- data/ext/libsass/src/values.cpp +33 -24
- data/ext/libsass/src/values.hpp +2 -2
- data/lib/sassc.rb +24 -0
- data/lib/sassc/engine.rb +7 -5
- data/lib/sassc/functions_handler.rb +11 -13
- data/lib/sassc/native.rb +10 -9
- data/lib/sassc/native/native_functions_api.rb +0 -5
- data/lib/sassc/script.rb +4 -6
- data/lib/sassc/version.rb +1 -1
- data/sassc.gemspec +32 -12
- data/test/engine_test.rb +32 -2
- data/test/functions_test.rb +38 -1
- data/test/native_test.rb +4 -4
- metadata +95 -109
- data/ext/Rakefile +0 -3
- data/ext/libsass/.editorconfig +0 -15
- data/ext/libsass/.gitattributes +0 -2
- data/ext/libsass/.github/CONTRIBUTING.md +0 -65
- data/ext/libsass/.github/ISSUE_TEMPLATE.md +0 -54
- data/ext/libsass/.gitignore +0 -85
- data/ext/libsass/.travis.yml +0 -64
- data/ext/libsass/COPYING +0 -25
- data/ext/libsass/GNUmakefile.am +0 -88
- data/ext/libsass/INSTALL +0 -1
- data/ext/libsass/LICENSE +0 -25
- data/ext/libsass/Makefile +0 -351
- data/ext/libsass/Makefile.conf +0 -55
- data/ext/libsass/Readme.md +0 -104
- data/ext/libsass/SECURITY.md +0 -10
- data/ext/libsass/appveyor.yml +0 -91
- data/ext/libsass/configure.ac +0 -138
- data/ext/libsass/contrib/libsass.spec +0 -66
- data/ext/libsass/docs/README.md +0 -20
- data/ext/libsass/docs/api-context-example.md +0 -45
- data/ext/libsass/docs/api-context-internal.md +0 -163
- data/ext/libsass/docs/api-context.md +0 -295
- data/ext/libsass/docs/api-doc.md +0 -215
- data/ext/libsass/docs/api-function-example.md +0 -67
- data/ext/libsass/docs/api-function-internal.md +0 -8
- data/ext/libsass/docs/api-function.md +0 -74
- data/ext/libsass/docs/api-importer-example.md +0 -112
- data/ext/libsass/docs/api-importer-internal.md +0 -20
- data/ext/libsass/docs/api-importer.md +0 -86
- data/ext/libsass/docs/api-value-example.md +0 -55
- data/ext/libsass/docs/api-value-internal.md +0 -76
- data/ext/libsass/docs/api-value.md +0 -154
- data/ext/libsass/docs/build-on-darwin.md +0 -27
- data/ext/libsass/docs/build-on-gentoo.md +0 -55
- data/ext/libsass/docs/build-on-windows.md +0 -139
- data/ext/libsass/docs/build-shared-library.md +0 -35
- data/ext/libsass/docs/build-with-autotools.md +0 -78
- data/ext/libsass/docs/build-with-makefiles.md +0 -68
- data/ext/libsass/docs/build-with-mingw.md +0 -107
- data/ext/libsass/docs/build-with-visual-studio.md +0 -90
- data/ext/libsass/docs/build.md +0 -97
- data/ext/libsass/docs/compatibility-plan.md +0 -48
- data/ext/libsass/docs/contributing.md +0 -17
- data/ext/libsass/docs/custom-functions-internal.md +0 -122
- data/ext/libsass/docs/dev-ast-memory.md +0 -223
- data/ext/libsass/docs/implementations.md +0 -56
- data/ext/libsass/docs/plugins.md +0 -47
- data/ext/libsass/docs/setup-environment.md +0 -68
- data/ext/libsass/docs/source-map-internals.md +0 -51
- data/ext/libsass/docs/trace.md +0 -26
- data/ext/libsass/docs/triage.md +0 -17
- data/ext/libsass/docs/unicode.md +0 -39
- data/ext/libsass/extconf.rb +0 -6
- data/ext/libsass/include/sass/version.h.in +0 -12
- data/ext/libsass/m4/.gitkeep +0 -0
- data/ext/libsass/m4/m4-ax_cxx_compile_stdcxx_11.m4 +0 -167
- data/ext/libsass/res/resource.rc +0 -35
- data/ext/libsass/script/bootstrap +0 -13
- data/ext/libsass/script/branding +0 -10
- data/ext/libsass/script/ci-build-libsass +0 -134
- data/ext/libsass/script/ci-build-plugin +0 -62
- data/ext/libsass/script/ci-install-compiler +0 -6
- data/ext/libsass/script/ci-install-deps +0 -20
- data/ext/libsass/script/ci-report-coverage +0 -42
- data/ext/libsass/script/spec +0 -5
- data/ext/libsass/script/tap-driver +0 -652
- data/ext/libsass/script/tap-runner +0 -1
- data/ext/libsass/script/test-leaks.pl +0 -103
- data/ext/libsass/src/GNUmakefile.am +0 -54
- data/ext/libsass/src/extend.cpp +0 -2130
- data/ext/libsass/src/extend.hpp +0 -86
- data/ext/libsass/src/functions.cpp +0 -2234
- data/ext/libsass/src/functions.hpp +0 -198
- data/ext/libsass/src/memory/SharedPtr.cpp +0 -114
- data/ext/libsass/src/memory/SharedPtr.hpp +0 -206
- data/ext/libsass/src/node.cpp +0 -319
- data/ext/libsass/src/node.hpp +0 -118
- data/ext/libsass/src/paths.hpp +0 -71
- data/ext/libsass/src/sass_util.cpp +0 -149
- data/ext/libsass/src/sass_util.hpp +0 -256
- data/ext/libsass/src/subset_map.cpp +0 -55
- data/ext/libsass/src/subset_map.hpp +0 -76
- data/ext/libsass/src/support/libsass.pc.in +0 -11
- data/ext/libsass/src/to_c.hpp +0 -39
- data/ext/libsass/test/test_node.cpp +0 -94
- data/ext/libsass/test/test_paths.cpp +0 -28
- data/ext/libsass/test/test_selector_difference.cpp +0 -25
- data/ext/libsass/test/test_specificity.cpp +0 -25
- data/ext/libsass/test/test_subset_map.cpp +0 -472
- data/ext/libsass/test/test_superselector.cpp +0 -69
- data/ext/libsass/test/test_unification.cpp +0 -31
- data/ext/libsass/version.sh +0 -10
- data/ext/libsass/win/libsass.sln +0 -39
- data/ext/libsass/win/libsass.sln.DotSettings +0 -9
- data/ext/libsass/win/libsass.targets +0 -118
- data/ext/libsass/win/libsass.vcxproj +0 -188
- data/ext/libsass/win/libsass.vcxproj.filters +0 -357
- data/lib/sassc/native/lib_c.rb +0 -21
- data/lib/tasks/libsass.rb +0 -33
data/ext/libsass/docs/api-doc.md
DELETED
@@ -1,215 +0,0 @@
|
|
1
|
-
## Introduction
|
2
|
-
|
3
|
-
LibSass wouldn't be much good without a way to interface with it. These
|
4
|
-
interface documentations describe the various functions and data structures
|
5
|
-
available to implementers. They are split up over three major components, which
|
6
|
-
have all their own source files (plus some common functionality).
|
7
|
-
|
8
|
-
- [Sass Context](api-context.md) - Trigger and handle the main Sass compilation
|
9
|
-
- [Sass Value](api-value.md) - Exchange values and its format with LibSass
|
10
|
-
- [Sass Function](api-function.md) - Get invoked by LibSass for function statments
|
11
|
-
- [Sass Importer](api-importer.md) - Get invoked by LibSass for @import statments
|
12
|
-
|
13
|
-
### Basic usage
|
14
|
-
|
15
|
-
First you will need to include the header file!
|
16
|
-
This will automatically load all other headers too!
|
17
|
-
|
18
|
-
```C
|
19
|
-
#include "sass/context.h"
|
20
|
-
```
|
21
|
-
|
22
|
-
## Basic C Example
|
23
|
-
|
24
|
-
```C
|
25
|
-
#include <stdio.h>
|
26
|
-
#include "sass/context.h"
|
27
|
-
|
28
|
-
int main() {
|
29
|
-
puts(libsass_version());
|
30
|
-
return 0;
|
31
|
-
}
|
32
|
-
```
|
33
|
-
|
34
|
-
```bash
|
35
|
-
gcc -Wall version.c -lsass -o version && ./version
|
36
|
-
```
|
37
|
-
|
38
|
-
## More C Examples
|
39
|
-
|
40
|
-
- [Sample code for Sass Context](api-context-example.md)
|
41
|
-
- [Sample code for Sass Value](api-value-example.md)
|
42
|
-
- [Sample code for Sass Function](api-function-example.md)
|
43
|
-
- [Sample code for Sass Importer](api-importer-example.md)
|
44
|
-
|
45
|
-
## Compiling your code
|
46
|
-
|
47
|
-
The most important is your sass file (or string of sass code). With this, you
|
48
|
-
will want to start a LibSass compiler. Here is some pseudocode describing the
|
49
|
-
process. The compiler has two different modes: direct input as a string with
|
50
|
-
`Sass_Data_Context` or LibSass will do file reading for you by using
|
51
|
-
`Sass_File_Context`. See the code for a list of options available
|
52
|
-
[Sass_Options](https://github.com/sass/libsass/blob/36feef0/include/sass/interface.h#L18)
|
53
|
-
|
54
|
-
**Building a file compiler**
|
55
|
-
|
56
|
-
context = sass_make_file_context("file.scss")
|
57
|
-
options = sass_file_context_get_options(context)
|
58
|
-
sass_option_set_precision(options, 1)
|
59
|
-
sass_option_set_source_comments(options, true)
|
60
|
-
|
61
|
-
sass_file_context_set_options(context, options)
|
62
|
-
|
63
|
-
compiler = sass_make_file_compiler(sass_context)
|
64
|
-
sass_compiler_parse(compiler)
|
65
|
-
sass_compiler_execute(compiler)
|
66
|
-
|
67
|
-
output = sass_context_get_output_string(context)
|
68
|
-
// Retrieve errors during compilation
|
69
|
-
error_status = sass_context_get_error_status(context)
|
70
|
-
json_error = sass_context_get_error_json(context)
|
71
|
-
// Release memory dedicated to the C compiler
|
72
|
-
sass_delete_compiler(compiler)
|
73
|
-
|
74
|
-
**Building a data compiler**
|
75
|
-
|
76
|
-
context = sass_make_data_context("div { a { color: blue; } }")
|
77
|
-
options = sass_data_context_get_options(context)
|
78
|
-
sass_option_set_precision(options, 1)
|
79
|
-
sass_option_set_source_comments(options, true)
|
80
|
-
|
81
|
-
sass_data_context_set_options(context, options)
|
82
|
-
|
83
|
-
compiler = sass_make_data_compiler(context)
|
84
|
-
sass_compiler_parse(compiler)
|
85
|
-
sass_compiler_execute(compiler)
|
86
|
-
|
87
|
-
output = sass_context_get_output_string(context)
|
88
|
-
// div a { color: blue; }
|
89
|
-
// Retrieve errors during compilation
|
90
|
-
error_status = sass_context_get_error_status(context)
|
91
|
-
json_error = sass_context_get_error_json(context)
|
92
|
-
// Release memory dedicated to the C compiler
|
93
|
-
sass_delete_compiler(compiler)
|
94
|
-
|
95
|
-
## Sass Context Internals
|
96
|
-
|
97
|
-
Everything is stored in structs:
|
98
|
-
|
99
|
-
```C
|
100
|
-
struct Sass_Options;
|
101
|
-
struct Sass_Context : Sass_Options;
|
102
|
-
struct Sass_File_context : Sass_Context;
|
103
|
-
struct Sass_Data_context : Sass_Context;
|
104
|
-
```
|
105
|
-
|
106
|
-
This mirrors very well how `libsass` uses these structures.
|
107
|
-
|
108
|
-
- `Sass_Options` holds everything you feed in before the compilation. It also hosts
|
109
|
-
`input_path` and `output_path` options, because they are used to generate/calculate
|
110
|
-
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
|
-
## Memory handling and life-cycles
|
118
|
-
|
119
|
-
We keep memory around for as long as the main [context](api-context.md) object
|
120
|
-
is not destroyed (`sass_delete_context`). LibSass will create copies of most
|
121
|
-
inputs/options beside the main sass code. You need to allocate and fill that
|
122
|
-
buffer before passing it to LibSass. You may also overtake memory management
|
123
|
-
from libsass for certain return values (i.e. `sass_context_take_output_string`).
|
124
|
-
|
125
|
-
```C
|
126
|
-
// to allocate buffer to be filled
|
127
|
-
void* sass_alloc_memory(size_t size);
|
128
|
-
// to allocate a buffer from existing string
|
129
|
-
char* sass_copy_c_string(const char* str);
|
130
|
-
// to free overtaken memory when done
|
131
|
-
void sass_free_memory(void* ptr);
|
132
|
-
```
|
133
|
-
|
134
|
-
## Miscellaneous API functions
|
135
|
-
|
136
|
-
```C
|
137
|
-
// Some convenient string helper function
|
138
|
-
char* sass_string_unquote (const char* str);
|
139
|
-
char* sass_string_quote (const char* str, const char quote_mark);
|
140
|
-
|
141
|
-
// Get compiled libsass version
|
142
|
-
const char* libsass_version(void);
|
143
|
-
|
144
|
-
// Implemented sass language version
|
145
|
-
// Hardcoded version 3.4 for time being
|
146
|
-
const char* libsass_language_version(void);
|
147
|
-
```
|
148
|
-
|
149
|
-
## Common Pitfalls
|
150
|
-
|
151
|
-
**input_path**
|
152
|
-
|
153
|
-
The `input_path` is part of `Sass_Options`, but it also is the main option for
|
154
|
-
`Sass_File_Context`. It is also used to generate relative file links in source-
|
155
|
-
maps. Therefore it is pretty usefull to pass this information if you have a
|
156
|
-
`Sass_Data_Context` and know the original path.
|
157
|
-
|
158
|
-
**output_path**
|
159
|
-
|
160
|
-
Be aware that `libsass` does not write the output file itself. This option
|
161
|
-
merely exists to give `libsass` the proper information to generate links in
|
162
|
-
source-maps. The file has to be written to the disk by the
|
163
|
-
binding/implementation. If the `output_path` is omitted, `libsass` tries to
|
164
|
-
extrapolate one from the `input_path` by replacing (or adding) the file ending
|
165
|
-
with `.css`.
|
166
|
-
|
167
|
-
## Error Codes
|
168
|
-
|
169
|
-
The `error_code` is integer value which indicates the type of error that
|
170
|
-
occurred inside the LibSass process. Following is the list of error codes along
|
171
|
-
with the short description:
|
172
|
-
|
173
|
-
* 1: normal errors like parsing or `eval` errors
|
174
|
-
* 2: bad allocation error (memory error)
|
175
|
-
* 3: "untranslated" C++ exception (`throw std::exception`)
|
176
|
-
* 4: legacy string exceptions ( `throw const char*` or `std::string` )
|
177
|
-
* 5: Some other unknown exception
|
178
|
-
|
179
|
-
Although for the API consumer, error codes do not offer much value except
|
180
|
-
indicating whether *any* error occurred during the compilation, it helps
|
181
|
-
debugging the LibSass internal code paths.
|
182
|
-
|
183
|
-
## Real-World Implementations
|
184
|
-
|
185
|
-
The proof is in the pudding, so we have highlighted a few implementations that
|
186
|
-
should be on par with the latest LibSass interface version. Some of them may not
|
187
|
-
have all features implemented!
|
188
|
-
|
189
|
-
1. [Perl Example](https://github.com/sass/perl-libsass/blob/master/lib/CSS/Sass.xs)
|
190
|
-
2. [Go Example](https://godoc.org/github.com/wellington/go-libsass#example-Compiler--Stdin)
|
191
|
-
3. [Node Example](https://github.com/sass/node-sass/blob/master/src/binding.cpp)
|
192
|
-
|
193
|
-
## ABI forward compatibility
|
194
|
-
|
195
|
-
We use a functional API to make dynamic linking more robust and future
|
196
|
-
compatible. The API is not yet 100% stable, so we do not yet guarantee
|
197
|
-
[ABI](https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html) forward
|
198
|
-
compatibility.
|
199
|
-
|
200
|
-
## Plugins (experimental)
|
201
|
-
|
202
|
-
LibSass can load plugins from directories. Just define `plugin_path` on context
|
203
|
-
options to load all plugins from the directories. To implement plugins, please
|
204
|
-
consult the following example implementations.
|
205
|
-
|
206
|
-
- https://github.com/mgreter/libsass-glob
|
207
|
-
- https://github.com/mgreter/libsass-math
|
208
|
-
- https://github.com/mgreter/libsass-digest
|
209
|
-
|
210
|
-
## Internal Structs
|
211
|
-
|
212
|
-
- [Sass Context Internals](api-context-internal.md)
|
213
|
-
- [Sass Value Internals](api-value-internal.md)
|
214
|
-
- [Sass Function Internals](api-function-internal.md)
|
215
|
-
- [Sass Importer Internals](api-importer-internal.md)
|
@@ -1,67 +0,0 @@
|
|
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, Sass_Function_Entry cb, struct Sass_Compiler* comp)
|
9
|
-
{
|
10
|
-
// get context/option struct associated with this compiler
|
11
|
-
struct Sass_Context* ctx = sass_compiler_get_context(comp);
|
12
|
-
struct Sass_Options* opts = sass_compiler_get_options(comp);
|
13
|
-
// get information about previous importer entry from the stack
|
14
|
-
Sass_Import_Entry import = sass_compiler_get_last_import(comp);
|
15
|
-
const char* prev_abs_path = sass_import_get_abs_path(import);
|
16
|
-
const char* prev_imp_path = sass_import_get_imp_path(import);
|
17
|
-
// get the cookie from function descriptor
|
18
|
-
void* cookie = sass_function_get_cookie(cb);
|
19
|
-
// we actually abuse the void* to store an "int"
|
20
|
-
return sass_make_number((intptr_t)cookie, "px");
|
21
|
-
}
|
22
|
-
|
23
|
-
int main( int argc, const char* argv[] )
|
24
|
-
{
|
25
|
-
|
26
|
-
// get the input file from first argument or use default
|
27
|
-
const char* input = argc > 1 ? argv[1] : "styles.scss";
|
28
|
-
|
29
|
-
// create the file context and get all related structs
|
30
|
-
struct Sass_File_Context* file_ctx = sass_make_file_context(input);
|
31
|
-
struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
|
32
|
-
struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
|
33
|
-
|
34
|
-
// allocate a custom function caller
|
35
|
-
Sass_Function_Entry fn_foo =
|
36
|
-
sass_make_function("foo()", call_fn_foo, (void*)42);
|
37
|
-
|
38
|
-
// create list of all custom functions
|
39
|
-
Sass_Function_List fn_list = sass_make_function_list(1);
|
40
|
-
sass_function_set_list_entry(fn_list, 0, fn_foo);
|
41
|
-
sass_option_set_c_functions(ctx_opt, fn_list);
|
42
|
-
|
43
|
-
// context is set up, call the compile step now
|
44
|
-
int status = sass_compile_file_context(file_ctx);
|
45
|
-
|
46
|
-
// print the result or the error to the stdout
|
47
|
-
if (status == 0) puts(sass_context_get_output_string(ctx));
|
48
|
-
else puts(sass_context_get_error_message(ctx));
|
49
|
-
|
50
|
-
// release allocated memory
|
51
|
-
sass_delete_file_context(file_ctx);
|
52
|
-
|
53
|
-
// exit status
|
54
|
-
return status;
|
55
|
-
|
56
|
-
}
|
57
|
-
```
|
58
|
-
|
59
|
-
### Compile main.c
|
60
|
-
|
61
|
-
```bash
|
62
|
-
gcc -c main.c -o main.o
|
63
|
-
gcc -o sample main.o -lsass
|
64
|
-
echo "foo { margin: foo(); }" > foo.scss
|
65
|
-
./sample foo.scss => "foo { margin: 42px }"
|
66
|
-
```
|
67
|
-
|
@@ -1,74 +0,0 @@
|
|
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_Compiler;
|
23
|
-
struct Sass_Function;
|
24
|
-
|
25
|
-
// Typedef helpers for custom functions lists
|
26
|
-
typedef struct Sass_Function (*Sass_Function_Entry);
|
27
|
-
typedef struct Sass_Function* (*Sass_Function_List);
|
28
|
-
// Typedef defining function signature and return type
|
29
|
-
typedef union Sass_Value* (*Sass_Function_Fn)
|
30
|
-
(const union Sass_Value*, Sass_Function_Entry cb, struct Sass_Compiler* compiler);
|
31
|
-
|
32
|
-
// Creators for sass function list and function descriptors
|
33
|
-
Sass_Function_List sass_make_function_list (size_t length);
|
34
|
-
Sass_Function_Entry sass_make_function (const char* signature, Sass_Function_Fn cb, void* cookie);
|
35
|
-
// In case you need to free them yourself
|
36
|
-
void sass_delete_function (Sass_Function_Entry entry);
|
37
|
-
void sass_delete_function_list (Sass_Function_List list);
|
38
|
-
|
39
|
-
// Setters and getters for callbacks on function lists
|
40
|
-
Sass_Function_Entry sass_function_get_list_entry(Sass_Function_List list, size_t pos);
|
41
|
-
void sass_function_set_list_entry(Sass_Function_List list, size_t pos, Sass_Function_Entry cb);
|
42
|
-
|
43
|
-
// Setters to insert an entry into the import list (you may also use [] access directly)
|
44
|
-
// Since we are dealing with pointers they should have a guaranteed and fixed size
|
45
|
-
void sass_import_set_list_entry (Sass_Import_List list, size_t idx, Sass_Import_Entry entry);
|
46
|
-
Sass_Import_Entry sass_import_get_list_entry (Sass_Import_List list, size_t idx);
|
47
|
-
|
48
|
-
// Getters for custom function descriptors
|
49
|
-
const char* sass_function_get_signature (Sass_Function_Entry cb);
|
50
|
-
Sass_Function_Fn sass_function_get_function (Sass_Function_Entry cb);
|
51
|
-
void* sass_function_get_cookie (Sass_Function_Entry cb);
|
52
|
-
|
53
|
-
// Getters for callee entry
|
54
|
-
const char* sass_callee_get_name (Sass_Callee_Entry);
|
55
|
-
const char* sass_callee_get_path (Sass_Callee_Entry);
|
56
|
-
size_t sass_callee_get_line (Sass_Callee_Entry);
|
57
|
-
size_t sass_callee_get_column (Sass_Callee_Entry);
|
58
|
-
enum Sass_Callee_Type sass_callee_get_type (Sass_Callee_Entry);
|
59
|
-
Sass_Env_Frame sass_callee_get_env (Sass_Callee_Entry);
|
60
|
-
|
61
|
-
// Getters and Setters for environments (lexical, local and global)
|
62
|
-
union Sass_Value* sass_env_get_lexical (Sass_Env_Frame, const char*);
|
63
|
-
void sass_env_set_lexical (Sass_Env_Frame, const char*, union Sass_Value*);
|
64
|
-
union Sass_Value* sass_env_get_local (Sass_Env_Frame, const char*);
|
65
|
-
void sass_env_set_local (Sass_Env_Frame, const char*, union Sass_Value*);
|
66
|
-
union Sass_Value* sass_env_get_global (Sass_Env_Frame, const char*);
|
67
|
-
void sass_env_set_global (Sass_Env_Frame, const char*, union Sass_Value*);
|
68
|
-
```
|
69
|
-
|
70
|
-
### More links
|
71
|
-
|
72
|
-
- [Sass Function Example](api-function-example.md)
|
73
|
-
- [Sass Function Internal](api-function-internal.md)
|
74
|
-
|
@@ -1,112 +0,0 @@
|
|
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
|
-
char* local = sass_copy_c_string("local { color: green; }");
|
14
|
-
char* remote = sass_copy_c_string("remote { color: red; }");
|
15
|
-
list[0] = sass_make_import_entry("/tmp/styles.scss", local, 0);
|
16
|
-
list[1] = sass_make_import_entry("http://www.example.com", 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(path, 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(path, 0, 0);
|
87
|
-
sass_import_set_error(list[0], sass_copy_c_string(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
|
-
```
|