sassc 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.gitmodules +3 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +24 -0
- data/Rakefile +21 -0
- data/ext/libsass/.editorconfig +15 -0
- data/ext/libsass/.gitattributes +2 -0
- data/ext/libsass/.gitignore +61 -0
- data/ext/libsass/.travis.yml +38 -0
- data/ext/libsass/COPYING +25 -0
- data/ext/libsass/INSTALL +1 -0
- data/ext/libsass/LICENSE +25 -0
- data/ext/libsass/Makefile +223 -0
- data/ext/libsass/Makefile.am +145 -0
- data/ext/libsass/Readme.md +93 -0
- data/ext/libsass/appveyor.yml +76 -0
- data/ext/libsass/ast.cpp +581 -0
- data/ext/libsass/ast.hpp +1949 -0
- data/ext/libsass/ast_def_macros.hpp +16 -0
- data/ext/libsass/ast_factory.hpp +87 -0
- data/ext/libsass/ast_fwd_decl.hpp +72 -0
- data/ext/libsass/b64/cencode.h +32 -0
- data/ext/libsass/b64/encode.h +77 -0
- data/ext/libsass/backtrace.hpp +81 -0
- data/ext/libsass/base64vlq.cpp +43 -0
- data/ext/libsass/base64vlq.hpp +28 -0
- data/ext/libsass/bind.cpp +187 -0
- data/ext/libsass/bind.hpp +18 -0
- data/ext/libsass/cencode.c +102 -0
- data/ext/libsass/color_names.hpp +324 -0
- data/ext/libsass/configure.ac +130 -0
- data/ext/libsass/constants.cpp +144 -0
- data/ext/libsass/constants.hpp +145 -0
- data/ext/libsass/context.cpp +507 -0
- data/ext/libsass/context.hpp +150 -0
- data/ext/libsass/contextualize.cpp +157 -0
- data/ext/libsass/contextualize.hpp +65 -0
- data/ext/libsass/copy_c_str.cpp +13 -0
- data/ext/libsass/copy_c_str.hpp +5 -0
- data/ext/libsass/debug.hpp +39 -0
- data/ext/libsass/environment.hpp +75 -0
- data/ext/libsass/error_handling.cpp +28 -0
- data/ext/libsass/error_handling.hpp +28 -0
- data/ext/libsass/eval.cpp +1149 -0
- data/ext/libsass/eval.hpp +80 -0
- data/ext/libsass/expand.cpp +430 -0
- data/ext/libsass/expand.hpp +77 -0
- data/ext/libsass/extconf.rb +6 -0
- data/ext/libsass/extend.cpp +1962 -0
- data/ext/libsass/extend.hpp +50 -0
- data/ext/libsass/file.cpp +291 -0
- data/ext/libsass/file.hpp +18 -0
- data/ext/libsass/functions.cpp +1565 -0
- data/ext/libsass/functions.hpp +187 -0
- data/ext/libsass/inspect.cpp +727 -0
- data/ext/libsass/inspect.hpp +108 -0
- data/ext/libsass/json.cpp +1411 -0
- data/ext/libsass/json.hpp +117 -0
- data/ext/libsass/kwd_arg_macros.hpp +23 -0
- data/ext/libsass/m4/.gitkeep +0 -0
- data/ext/libsass/mapping.hpp +17 -0
- data/ext/libsass/memory_manager.hpp +54 -0
- data/ext/libsass/node.cpp +251 -0
- data/ext/libsass/node.hpp +122 -0
- data/ext/libsass/operation.hpp +153 -0
- data/ext/libsass/output_compressed.cpp +401 -0
- data/ext/libsass/output_compressed.hpp +95 -0
- data/ext/libsass/output_nested.cpp +364 -0
- data/ext/libsass/output_nested.hpp +108 -0
- data/ext/libsass/parser.cpp +2016 -0
- data/ext/libsass/parser.hpp +264 -0
- data/ext/libsass/paths.hpp +69 -0
- data/ext/libsass/position.hpp +22 -0
- data/ext/libsass/posix/getopt.c +562 -0
- data/ext/libsass/posix/getopt.h +95 -0
- data/ext/libsass/prelexer.cpp +688 -0
- data/ext/libsass/prelexer.hpp +513 -0
- data/ext/libsass/remove_placeholders.cpp +59 -0
- data/ext/libsass/remove_placeholders.hpp +43 -0
- data/ext/libsass/res/resource.rc +35 -0
- data/ext/libsass/sass.cpp +33 -0
- data/ext/libsass/sass.h +60 -0
- data/ext/libsass/sass2scss.cpp +834 -0
- data/ext/libsass/sass2scss.h +110 -0
- data/ext/libsass/sass_context.cpp +709 -0
- data/ext/libsass/sass_context.h +120 -0
- data/ext/libsass/sass_functions.cpp +137 -0
- data/ext/libsass/sass_functions.h +90 -0
- data/ext/libsass/sass_interface.cpp +277 -0
- data/ext/libsass/sass_interface.h +97 -0
- data/ext/libsass/sass_util.cpp +136 -0
- data/ext/libsass/sass_util.hpp +259 -0
- data/ext/libsass/sass_values.cpp +337 -0
- data/ext/libsass/sass_values.h +124 -0
- data/ext/libsass/script/bootstrap +10 -0
- data/ext/libsass/script/branding +10 -0
- data/ext/libsass/script/ci-build-libsass +72 -0
- data/ext/libsass/script/ci-install-compiler +4 -0
- data/ext/libsass/script/ci-install-deps +19 -0
- data/ext/libsass/script/ci-report-coverage +25 -0
- data/ext/libsass/script/coveralls-debug +32 -0
- data/ext/libsass/script/spec +5 -0
- data/ext/libsass/script/tap-driver +652 -0
- data/ext/libsass/script/tap-runner +1 -0
- data/ext/libsass/source_map.cpp +133 -0
- data/ext/libsass/source_map.hpp +46 -0
- data/ext/libsass/subset_map.hpp +145 -0
- data/ext/libsass/support/libsass.pc.in +11 -0
- data/ext/libsass/test-driver +127 -0
- data/ext/libsass/test/test_node.cpp +98 -0
- data/ext/libsass/test/test_paths.cpp +29 -0
- data/ext/libsass/test/test_selector_difference.cpp +28 -0
- data/ext/libsass/test/test_specificity.cpp +28 -0
- data/ext/libsass/test/test_subset_map.cpp +472 -0
- data/ext/libsass/test/test_superselector.cpp +71 -0
- data/ext/libsass/test/test_unification.cpp +33 -0
- data/ext/libsass/to_c.cpp +61 -0
- data/ext/libsass/to_c.hpp +44 -0
- data/ext/libsass/to_string.cpp +29 -0
- data/ext/libsass/to_string.hpp +32 -0
- data/ext/libsass/token.hpp +32 -0
- data/ext/libsass/units.cpp +54 -0
- data/ext/libsass/units.hpp +10 -0
- data/ext/libsass/utf8.h +34 -0
- data/ext/libsass/utf8/checked.h +327 -0
- data/ext/libsass/utf8/core.h +329 -0
- data/ext/libsass/utf8/unchecked.h +228 -0
- data/ext/libsass/utf8_string.cpp +102 -0
- data/ext/libsass/utf8_string.hpp +36 -0
- data/ext/libsass/util.cpp +189 -0
- data/ext/libsass/util.hpp +26 -0
- data/ext/libsass/win/libsass.filters +291 -0
- data/ext/libsass/win/libsass.sln +28 -0
- data/ext/libsass/win/libsass.vcxproj +255 -0
- data/lib/sassc.rb +6 -0
- data/lib/sassc/engine.rb +13 -0
- data/lib/sassc/native.rb +44 -0
- data/lib/sassc/native/native_context_api.rb +140 -0
- data/lib/sassc/native/native_functions_api.rb +41 -0
- data/lib/sassc/native/sass_input_style.rb +11 -0
- data/lib/sassc/native/sass_output_style.rb +10 -0
- data/lib/sassc/native/sass_value.rb +95 -0
- data/lib/sassc/native/string_list.rb +8 -0
- data/lib/sassc/version.rb +3 -0
- data/sassc.gemspec +43 -0
- data/test/smoke_test.rb +171 -0
- data/test/test_helper.rb +4 -0
- metadata +281 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#ifndef SASS_C_CONTEXT
|
|
2
|
+
#define SASS_C_CONTEXT
|
|
3
|
+
|
|
4
|
+
#include <stddef.h>
|
|
5
|
+
#include <stdbool.h>
|
|
6
|
+
#include "sass.h"
|
|
7
|
+
|
|
8
|
+
#ifdef __cplusplus
|
|
9
|
+
extern "C" {
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
// Forward declaration
|
|
14
|
+
struct Sass_Compiler;
|
|
15
|
+
|
|
16
|
+
// Forward declaration
|
|
17
|
+
struct Sass_Options;
|
|
18
|
+
struct Sass_Context; // : Sass_Options
|
|
19
|
+
struct Sass_File_Context; // : Sass_Context
|
|
20
|
+
struct Sass_Data_Context; // : Sass_Context
|
|
21
|
+
|
|
22
|
+
// Create and initialize an option struct
|
|
23
|
+
ADDAPI struct Sass_Options* ADDCALL sass_make_options (void);
|
|
24
|
+
// Create and initialize a specific context
|
|
25
|
+
ADDAPI struct Sass_File_Context* ADDCALL sass_make_file_context (const char* input_path);
|
|
26
|
+
ADDAPI struct Sass_Data_Context* ADDCALL sass_make_data_context (char* source_string);
|
|
27
|
+
|
|
28
|
+
// Call the compilation step for the specific context
|
|
29
|
+
ADDAPI int ADDCALL sass_compile_file_context (struct Sass_File_Context* ctx);
|
|
30
|
+
ADDAPI int ADDCALL sass_compile_data_context (struct Sass_Data_Context* ctx);
|
|
31
|
+
|
|
32
|
+
// Create a sass compiler instance for more control
|
|
33
|
+
ADDAPI struct Sass_Compiler* ADDCALL sass_make_file_compiler (struct Sass_File_Context* file_ctx);
|
|
34
|
+
ADDAPI struct Sass_Compiler* ADDCALL sass_make_data_compiler (struct Sass_Data_Context* data_ctx);
|
|
35
|
+
|
|
36
|
+
// Execute the different compilation steps individually
|
|
37
|
+
// Usefull if you only want to query the included files
|
|
38
|
+
ADDAPI int ADDCALL sass_compiler_parse(struct Sass_Compiler* compiler);
|
|
39
|
+
ADDAPI int ADDCALL sass_compiler_execute(struct Sass_Compiler* compiler);
|
|
40
|
+
|
|
41
|
+
// Release all memory allocated with the compiler
|
|
42
|
+
// This does _not_ include any contexts or options
|
|
43
|
+
ADDAPI void ADDCALL sass_delete_compiler(struct Sass_Compiler* compiler);
|
|
44
|
+
|
|
45
|
+
// Release all memory allocated and also ourself
|
|
46
|
+
ADDAPI void ADDCALL sass_delete_file_context (struct Sass_File_Context* ctx);
|
|
47
|
+
ADDAPI void ADDCALL sass_delete_data_context (struct Sass_Data_Context* ctx);
|
|
48
|
+
|
|
49
|
+
// Getters for context from specific implementation
|
|
50
|
+
ADDAPI struct Sass_Context* ADDCALL sass_file_context_get_context (struct Sass_File_Context* file_ctx);
|
|
51
|
+
ADDAPI struct Sass_Context* ADDCALL sass_data_context_get_context (struct Sass_Data_Context* data_ctx);
|
|
52
|
+
|
|
53
|
+
// Getters for context options from Sass_Context
|
|
54
|
+
ADDAPI struct Sass_Options* ADDCALL sass_context_get_options (struct Sass_Context* ctx);
|
|
55
|
+
ADDAPI struct Sass_Options* ADDCALL sass_file_context_get_options (struct Sass_File_Context* file_ctx);
|
|
56
|
+
ADDAPI struct Sass_Options* ADDCALL sass_data_context_get_options (struct Sass_Data_Context* data_ctx);
|
|
57
|
+
ADDAPI void ADDCALL sass_file_context_set_options (struct Sass_File_Context* file_ctx, struct Sass_Options* opt);
|
|
58
|
+
ADDAPI void ADDCALL sass_data_context_set_options (struct Sass_Data_Context* data_ctx, struct Sass_Options* opt);
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// Getters for options
|
|
62
|
+
ADDAPI int ADDCALL sass_option_get_precision (struct Sass_Options* options);
|
|
63
|
+
ADDAPI enum Sass_Output_Style ADDCALL sass_option_get_output_style (struct Sass_Options* options);
|
|
64
|
+
ADDAPI bool ADDCALL sass_option_get_source_comments (struct Sass_Options* options);
|
|
65
|
+
ADDAPI bool ADDCALL sass_option_get_source_map_embed (struct Sass_Options* options);
|
|
66
|
+
ADDAPI bool ADDCALL sass_option_get_source_map_contents (struct Sass_Options* options);
|
|
67
|
+
ADDAPI bool ADDCALL sass_option_get_omit_source_map_url (struct Sass_Options* options);
|
|
68
|
+
ADDAPI bool ADDCALL sass_option_get_is_indented_syntax_src (struct Sass_Options* options);
|
|
69
|
+
ADDAPI const char* ADDCALL sass_option_get_input_path (struct Sass_Options* options);
|
|
70
|
+
ADDAPI const char* ADDCALL sass_option_get_output_path (struct Sass_Options* options);
|
|
71
|
+
ADDAPI const char* ADDCALL sass_option_get_image_path (struct Sass_Options* options);
|
|
72
|
+
ADDAPI const char* ADDCALL sass_option_get_include_path (struct Sass_Options* options);
|
|
73
|
+
ADDAPI const char* ADDCALL sass_option_get_source_map_file (struct Sass_Options* options);
|
|
74
|
+
ADDAPI Sass_C_Function_List ADDCALL sass_option_get_c_functions (struct Sass_Options* options);
|
|
75
|
+
ADDAPI Sass_C_Import_Callback ADDCALL sass_option_get_importer (struct Sass_Options* options);
|
|
76
|
+
|
|
77
|
+
// Setters for options
|
|
78
|
+
ADDAPI void ADDCALL sass_option_set_precision (struct Sass_Options* options, int precision);
|
|
79
|
+
ADDAPI void ADDCALL sass_option_set_output_style (struct Sass_Options* options, enum Sass_Output_Style output_style);
|
|
80
|
+
ADDAPI void ADDCALL sass_option_set_source_comments (struct Sass_Options* options, bool source_comments);
|
|
81
|
+
ADDAPI void ADDCALL sass_option_set_source_map_embed (struct Sass_Options* options, bool source_map_embed);
|
|
82
|
+
ADDAPI void ADDCALL sass_option_set_source_map_contents (struct Sass_Options* options, bool source_map_contents);
|
|
83
|
+
ADDAPI void ADDCALL sass_option_set_omit_source_map_url (struct Sass_Options* options, bool omit_source_map_url);
|
|
84
|
+
ADDAPI void ADDCALL sass_option_set_is_indented_syntax_src (struct Sass_Options* options, bool is_indented_syntax_src);
|
|
85
|
+
ADDAPI void ADDCALL sass_option_set_input_path (struct Sass_Options* options, const char* input_path);
|
|
86
|
+
ADDAPI void ADDCALL sass_option_set_output_path (struct Sass_Options* options, const char* output_path);
|
|
87
|
+
ADDAPI void ADDCALL sass_option_set_image_path (struct Sass_Options* options, const char* image_path);
|
|
88
|
+
ADDAPI void ADDCALL sass_option_set_include_path (struct Sass_Options* options, const char* include_path);
|
|
89
|
+
ADDAPI void ADDCALL sass_option_set_source_map_file (struct Sass_Options* options, const char* source_map_file);
|
|
90
|
+
ADDAPI void ADDCALL sass_option_set_c_functions (struct Sass_Options* options, Sass_C_Function_List c_functions);
|
|
91
|
+
ADDAPI void ADDCALL sass_option_set_importer (struct Sass_Options* options, Sass_C_Import_Callback importer);
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
// Getter for context
|
|
95
|
+
ADDAPI const char* ADDCALL sass_context_get_output_string (struct Sass_Context* ctx);
|
|
96
|
+
ADDAPI int ADDCALL sass_context_get_error_status (struct Sass_Context* ctx);
|
|
97
|
+
ADDAPI const char* ADDCALL sass_context_get_error_json (struct Sass_Context* ctx);
|
|
98
|
+
ADDAPI const char* ADDCALL sass_context_get_error_message (struct Sass_Context* ctx);
|
|
99
|
+
ADDAPI const char* ADDCALL sass_context_get_error_file (struct Sass_Context* ctx);
|
|
100
|
+
ADDAPI size_t ADDCALL sass_context_get_error_line (struct Sass_Context* ctx);
|
|
101
|
+
ADDAPI size_t ADDCALL sass_context_get_error_column (struct Sass_Context* ctx);
|
|
102
|
+
ADDAPI const char* ADDCALL sass_context_get_source_map_string (struct Sass_Context* ctx);
|
|
103
|
+
ADDAPI char** ADDCALL sass_context_get_included_files (struct Sass_Context* ctx);
|
|
104
|
+
|
|
105
|
+
// Take ownership of memory (value on context is set to 0)
|
|
106
|
+
ADDAPI char* ADDCALL sass_context_take_error_json (struct Sass_Context* ctx);
|
|
107
|
+
ADDAPI char* ADDCALL sass_context_take_error_message (struct Sass_Context* ctx);
|
|
108
|
+
ADDAPI char* ADDCALL sass_context_take_error_file (struct Sass_Context* ctx);
|
|
109
|
+
ADDAPI char* ADDCALL sass_context_take_output_string (struct Sass_Context* ctx);
|
|
110
|
+
ADDAPI char* ADDCALL sass_context_take_source_map_string (struct Sass_Context* ctx);
|
|
111
|
+
|
|
112
|
+
// Push function for include paths (no manipulation support for now)
|
|
113
|
+
ADDAPI void ADDCALL sass_option_push_include_path (struct Sass_Options* options, const char* path);
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
#ifdef __cplusplus
|
|
117
|
+
} // __cplusplus defined.
|
|
118
|
+
#endif
|
|
119
|
+
|
|
120
|
+
#endif
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#ifdef _WIN32
|
|
2
|
+
#include <io.h>
|
|
3
|
+
#else
|
|
4
|
+
#include <unistd.h>
|
|
5
|
+
#endif
|
|
6
|
+
|
|
7
|
+
#include "context.hpp"
|
|
8
|
+
#include "sass_functions.h"
|
|
9
|
+
|
|
10
|
+
extern "C" {
|
|
11
|
+
using namespace std;
|
|
12
|
+
|
|
13
|
+
// Struct to hold custom function callback
|
|
14
|
+
struct Sass_C_Function_Descriptor {
|
|
15
|
+
const char* signature;
|
|
16
|
+
Sass_C_Function function;
|
|
17
|
+
void* cookie;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
Sass_C_Function_List ADDCALL sass_make_function_list(size_t length)
|
|
21
|
+
{
|
|
22
|
+
return (Sass_C_Function_List) calloc(length + 1, sizeof(Sass_C_Function_Callback));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Sass_C_Function_Callback ADDCALL sass_make_function(const char* signature, Sass_C_Function function, void* cookie)
|
|
26
|
+
{
|
|
27
|
+
Sass_C_Function_Callback cb = (Sass_C_Function_Callback) calloc(1, sizeof(Sass_C_Function_Descriptor));
|
|
28
|
+
if (cb == 0) return 0;
|
|
29
|
+
cb->signature = signature;
|
|
30
|
+
cb->function = function;
|
|
31
|
+
cb->cookie = cookie;
|
|
32
|
+
return cb;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Setters and getters for callbacks on function lists
|
|
36
|
+
Sass_C_Function_Callback ADDCALL sass_function_get_list_entry(Sass_C_Function_List list, size_t pos) { return list[pos]; }
|
|
37
|
+
void sass_function_set_list_entry(Sass_C_Function_List list, size_t pos, Sass_C_Function_Callback cb) { list[pos] = cb; }
|
|
38
|
+
|
|
39
|
+
const char* ADDCALL sass_function_get_signature(Sass_C_Function_Callback fn) { return fn->signature; }
|
|
40
|
+
Sass_C_Function ADDCALL sass_function_get_function(Sass_C_Function_Callback fn) { return fn->function; }
|
|
41
|
+
void* ADDCALL sass_function_get_cookie(Sass_C_Function_Callback fn) { return fn->cookie; }
|
|
42
|
+
|
|
43
|
+
// External import entry
|
|
44
|
+
struct Sass_Import {
|
|
45
|
+
char* path;
|
|
46
|
+
char* base;
|
|
47
|
+
char* source;
|
|
48
|
+
char* srcmap;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Struct to hold importer callback
|
|
52
|
+
struct Sass_C_Import_Descriptor {
|
|
53
|
+
Sass_C_Import_Fn function;
|
|
54
|
+
void* cookie;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
Sass_C_Import_Callback ADDCALL sass_make_importer(Sass_C_Import_Fn function, void* cookie)
|
|
58
|
+
{
|
|
59
|
+
Sass_C_Import_Callback cb = (Sass_C_Import_Callback) calloc(1, sizeof(Sass_C_Import_Descriptor));
|
|
60
|
+
if (cb == 0) return 0;
|
|
61
|
+
cb->function = function;
|
|
62
|
+
cb->cookie = cookie;
|
|
63
|
+
return cb;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
Sass_C_Import_Fn ADDCALL sass_import_get_function(Sass_C_Import_Callback fn) { return fn->function; }
|
|
67
|
+
void* ADDCALL sass_import_get_cookie(Sass_C_Import_Callback fn) { return fn->cookie; }
|
|
68
|
+
|
|
69
|
+
// Just in case we have some stray import structs
|
|
70
|
+
void ADDCALL sass_delete_importer (Sass_C_Import_Callback fn)
|
|
71
|
+
{
|
|
72
|
+
free(fn);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Creator for sass custom importer return argument list
|
|
76
|
+
struct Sass_Import** ADDCALL sass_make_import_list(size_t length)
|
|
77
|
+
{
|
|
78
|
+
return (Sass_Import**) calloc(length + 1, sizeof(Sass_Import*));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Creator for a single import entry returned by the custom importer inside the list
|
|
82
|
+
// We take ownership of the memory for source and srcmap (freed when context is destroyd)
|
|
83
|
+
struct Sass_Import* ADDCALL sass_make_import(const char* path, const char* base, char* source, char* srcmap)
|
|
84
|
+
{
|
|
85
|
+
Sass_Import* v = (Sass_Import*) calloc(1, sizeof(Sass_Import));
|
|
86
|
+
if (v == 0) return 0;
|
|
87
|
+
v->path = path ? strdup(path) : 0;
|
|
88
|
+
v->base = base ? strdup(base) : 0;
|
|
89
|
+
v->source = source;
|
|
90
|
+
v->srcmap = srcmap;
|
|
91
|
+
return v;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Older style, but somehow still valid - keep around or deprecate?
|
|
95
|
+
struct Sass_Import* ADDCALL sass_make_import_entry(const char* path, char* source, char* srcmap)
|
|
96
|
+
{
|
|
97
|
+
return sass_make_import(path, path, source, srcmap);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Setters and getters for entries on the import list
|
|
101
|
+
void ADDCALL sass_import_set_list_entry(struct Sass_Import** list, size_t idx, struct Sass_Import* entry) { list[idx] = entry; }
|
|
102
|
+
struct Sass_Import* ADDCALL sass_import_get_list_entry(struct Sass_Import** list, size_t idx) { return list[idx]; }
|
|
103
|
+
|
|
104
|
+
// Deallocator for the allocated memory
|
|
105
|
+
void ADDCALL sass_delete_import_list(struct Sass_Import** list)
|
|
106
|
+
{
|
|
107
|
+
struct Sass_Import** it = list;
|
|
108
|
+
if (list == 0) return;
|
|
109
|
+
while(*list) {
|
|
110
|
+
sass_delete_import(*list);
|
|
111
|
+
++list;
|
|
112
|
+
}
|
|
113
|
+
free(it);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Just in case we have some stray import structs
|
|
117
|
+
void ADDCALL sass_delete_import(struct Sass_Import* import)
|
|
118
|
+
{
|
|
119
|
+
free(import->path);
|
|
120
|
+
free(import->base);
|
|
121
|
+
free(import->source);
|
|
122
|
+
free(import->srcmap);
|
|
123
|
+
free(import);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Getter for import entry
|
|
127
|
+
const char* ADDCALL sass_import_get_path(struct Sass_Import* entry) { return entry->path; }
|
|
128
|
+
const char* ADDCALL sass_import_get_base(struct Sass_Import* entry) { return entry->base; }
|
|
129
|
+
const char* ADDCALL sass_import_get_source(struct Sass_Import* entry) { return entry->source; }
|
|
130
|
+
const char* ADDCALL sass_import_get_srcmap(struct Sass_Import* entry) { return entry->srcmap; }
|
|
131
|
+
|
|
132
|
+
// Explicit functions to take ownership of the memory
|
|
133
|
+
// Resets our own property since we do not know if it is still alive
|
|
134
|
+
char* ADDCALL sass_import_take_source(struct Sass_Import* entry) { char* ptr = entry->source; entry->source = 0; return ptr; }
|
|
135
|
+
char* ADDCALL sass_import_take_srcmap(struct Sass_Import* entry) { char* ptr = entry->srcmap; entry->srcmap = 0; return ptr; }
|
|
136
|
+
|
|
137
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#ifndef SASS_C_FUNCTIONS
|
|
2
|
+
#define SASS_C_FUNCTIONS
|
|
3
|
+
|
|
4
|
+
#include <stddef.h>
|
|
5
|
+
#include <stdbool.h>
|
|
6
|
+
#include "sass.h"
|
|
7
|
+
|
|
8
|
+
#ifdef __cplusplus
|
|
9
|
+
extern "C" {
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
// Forward declaration
|
|
14
|
+
struct Sass_Import;
|
|
15
|
+
|
|
16
|
+
// Forward declaration
|
|
17
|
+
struct Sass_C_Import_Descriptor;
|
|
18
|
+
|
|
19
|
+
// Typedef defining the custom importer callback
|
|
20
|
+
typedef struct Sass_C_Import_Descriptor (*Sass_C_Import_Callback);
|
|
21
|
+
// Typedef defining the importer c function prototype
|
|
22
|
+
typedef struct Sass_Import** (*Sass_C_Import_Fn) (const char* url, const char* prev, void* cookie);
|
|
23
|
+
|
|
24
|
+
// Creators for custom importer callback (with some additional pointer)
|
|
25
|
+
// The pointer is mostly used to store the callback into the actual binding
|
|
26
|
+
ADDAPI Sass_C_Import_Callback ADDCALL sass_make_importer (Sass_C_Import_Fn, void* cookie);
|
|
27
|
+
|
|
28
|
+
// Getters for import function descriptors
|
|
29
|
+
ADDAPI Sass_C_Import_Fn ADDCALL sass_import_get_function (Sass_C_Import_Callback fn);
|
|
30
|
+
ADDAPI void* ADDCALL sass_import_get_cookie (Sass_C_Import_Callback fn);
|
|
31
|
+
|
|
32
|
+
// Deallocator for associated memory
|
|
33
|
+
ADDAPI void ADDCALL sass_delete_importer (Sass_C_Import_Callback fn);
|
|
34
|
+
|
|
35
|
+
// Creator for sass custom importer return argument list
|
|
36
|
+
ADDAPI struct Sass_Import** ADDCALL sass_make_import_list (size_t length);
|
|
37
|
+
// Creator for a single import entry returned by the custom importer inside the list
|
|
38
|
+
ADDAPI struct Sass_Import* ADDCALL sass_make_import_entry (const char* path, char* source, char* srcmap);
|
|
39
|
+
ADDAPI struct Sass_Import* ADDCALL sass_make_import (const char* path, const char* base, char* source, char* srcmap);
|
|
40
|
+
|
|
41
|
+
// Setters to insert an entry into the import list (you may also use [] access directly)
|
|
42
|
+
// Since we are dealing with pointers they should have a guaranteed and fixed size
|
|
43
|
+
ADDAPI void ADDCALL sass_import_set_list_entry (struct Sass_Import** list, size_t idx, struct Sass_Import* entry);
|
|
44
|
+
ADDAPI struct Sass_Import* ADDCALL sass_import_get_list_entry (struct Sass_Import** list, size_t idx);
|
|
45
|
+
|
|
46
|
+
// Getters for import entry
|
|
47
|
+
ADDAPI const char* ADDCALL sass_import_get_path (struct Sass_Import*);
|
|
48
|
+
ADDAPI const char* ADDCALL sass_import_get_base (struct Sass_Import*);
|
|
49
|
+
ADDAPI const char* ADDCALL sass_import_get_source (struct Sass_Import*);
|
|
50
|
+
ADDAPI const char* ADDCALL sass_import_get_srcmap (struct Sass_Import*);
|
|
51
|
+
// Explicit functions to take ownership of these items
|
|
52
|
+
// The property on our struct will be reset to NULL
|
|
53
|
+
ADDAPI char* ADDCALL sass_import_take_source (struct Sass_Import*);
|
|
54
|
+
ADDAPI char* ADDCALL sass_import_take_srcmap (struct Sass_Import*);
|
|
55
|
+
|
|
56
|
+
// Deallocator for associated memory (incl. entries)
|
|
57
|
+
ADDAPI void ADDCALL sass_delete_import_list (struct Sass_Import**);
|
|
58
|
+
// Just in case we have some stray import structs
|
|
59
|
+
ADDAPI void ADDCALL sass_delete_import (struct Sass_Import*);
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
// Forward declaration
|
|
63
|
+
struct Sass_C_Function_Descriptor;
|
|
64
|
+
|
|
65
|
+
// Typedef defining null terminated list of custom callbacks
|
|
66
|
+
typedef struct Sass_C_Function_Descriptor* (*Sass_C_Function_List);
|
|
67
|
+
typedef struct Sass_C_Function_Descriptor (*Sass_C_Function_Callback);
|
|
68
|
+
// Typedef defining custom function prototype and its return value type
|
|
69
|
+
typedef union Sass_Value*(*Sass_C_Function) (const union Sass_Value*, void* cookie);
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
// Creators for sass function list and function descriptors
|
|
73
|
+
ADDAPI Sass_C_Function_List ADDCALL sass_make_function_list (size_t length);
|
|
74
|
+
ADDAPI Sass_C_Function_Callback ADDCALL sass_make_function (const char* signature, Sass_C_Function fn, void* cookie);
|
|
75
|
+
|
|
76
|
+
// Setters and getters for callbacks on function lists
|
|
77
|
+
ADDAPI Sass_C_Function_Callback ADDCALL sass_function_get_list_entry(Sass_C_Function_List list, size_t pos);
|
|
78
|
+
ADDAPI void ADDCALL sass_function_set_list_entry(Sass_C_Function_List list, size_t pos, Sass_C_Function_Callback cb);
|
|
79
|
+
|
|
80
|
+
// Getters for custom function descriptors
|
|
81
|
+
ADDAPI const char* ADDCALL sass_function_get_signature (Sass_C_Function_Callback fn);
|
|
82
|
+
ADDAPI Sass_C_Function ADDCALL sass_function_get_function (Sass_C_Function_Callback fn);
|
|
83
|
+
ADDAPI void* ADDCALL sass_function_get_cookie (Sass_C_Function_Callback fn);
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
#ifdef __cplusplus
|
|
87
|
+
} // __cplusplus defined.
|
|
88
|
+
#endif
|
|
89
|
+
|
|
90
|
+
#endif
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
#ifdef _WIN32
|
|
2
|
+
#include <io.h>
|
|
3
|
+
#else
|
|
4
|
+
#include <unistd.h>
|
|
5
|
+
#endif
|
|
6
|
+
|
|
7
|
+
#include "sass_interface.h"
|
|
8
|
+
#include "context.hpp"
|
|
9
|
+
#include "inspect.hpp"
|
|
10
|
+
|
|
11
|
+
#ifndef SASS_ERROR_HANDLING
|
|
12
|
+
#include "error_handling.hpp"
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
#include <iostream>
|
|
16
|
+
#include <sstream>
|
|
17
|
+
#include <string>
|
|
18
|
+
#include <cstdlib>
|
|
19
|
+
#include <cstring>
|
|
20
|
+
|
|
21
|
+
extern "C" {
|
|
22
|
+
using namespace std;
|
|
23
|
+
|
|
24
|
+
sass_context* sass_new_context()
|
|
25
|
+
{ return (sass_context*) calloc(1, sizeof(sass_context)); }
|
|
26
|
+
|
|
27
|
+
// helper for safe access to c_ctx
|
|
28
|
+
static const char* safe_str (const char* str) {
|
|
29
|
+
return str == NULL ? "" : str;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static void copy_strings(const std::vector<std::string>& strings, char*** array, int skip = 0) {
|
|
33
|
+
int num = static_cast<int>(strings.size());
|
|
34
|
+
char** arr = (char**) malloc(sizeof(char*) * (num + 1));
|
|
35
|
+
|
|
36
|
+
for(int i = skip; i < num; i++) {
|
|
37
|
+
arr[i-skip] = (char*) malloc(sizeof(char) * (strings[i].size() + 1));
|
|
38
|
+
std::copy(strings[i].begin(), strings[i].end(), arr[i-skip]);
|
|
39
|
+
arr[i-skip][strings[i].size()] = '\0';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
arr[num-skip] = 0;
|
|
43
|
+
*array = arr;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static void free_string_array(char ** arr) {
|
|
47
|
+
if(!arr)
|
|
48
|
+
return;
|
|
49
|
+
|
|
50
|
+
char **it = arr;
|
|
51
|
+
while (it && (*it)) {
|
|
52
|
+
free(*it);
|
|
53
|
+
++it;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
free(arr);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
void sass_free_context(sass_context* ctx)
|
|
60
|
+
{
|
|
61
|
+
if (ctx->output_string) free(ctx->output_string);
|
|
62
|
+
if (ctx->source_map_string) free(ctx->source_map_string);
|
|
63
|
+
if (ctx->error_message) free(ctx->error_message);
|
|
64
|
+
if (ctx->c_functions) free(ctx->c_functions);
|
|
65
|
+
|
|
66
|
+
free_string_array(ctx->included_files);
|
|
67
|
+
|
|
68
|
+
free(ctx);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
sass_file_context* sass_new_file_context()
|
|
72
|
+
{ return (sass_file_context*) calloc(1, sizeof(sass_file_context)); }
|
|
73
|
+
|
|
74
|
+
void sass_free_file_context(sass_file_context* ctx)
|
|
75
|
+
{
|
|
76
|
+
if (ctx->output_string) free(ctx->output_string);
|
|
77
|
+
if (ctx->source_map_string) free(ctx->source_map_string);
|
|
78
|
+
if (ctx->error_message) free(ctx->error_message);
|
|
79
|
+
if (ctx->c_functions) free(ctx->c_functions);
|
|
80
|
+
|
|
81
|
+
free_string_array(ctx->included_files);
|
|
82
|
+
|
|
83
|
+
free(ctx);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
sass_folder_context* sass_new_folder_context()
|
|
87
|
+
{ return (sass_folder_context*) calloc(1, sizeof(sass_folder_context)); }
|
|
88
|
+
|
|
89
|
+
void sass_free_folder_context(sass_folder_context* ctx)
|
|
90
|
+
{
|
|
91
|
+
free_string_array(ctx->included_files);
|
|
92
|
+
free(ctx);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
int sass_compile(sass_context* c_ctx)
|
|
96
|
+
{
|
|
97
|
+
using namespace Sass;
|
|
98
|
+
try {
|
|
99
|
+
string input_path = safe_str(c_ctx->input_path);
|
|
100
|
+
int lastindex = static_cast<int>(input_path.find_last_of("."));
|
|
101
|
+
string output_path;
|
|
102
|
+
if (!c_ctx->output_path) {
|
|
103
|
+
if (input_path != "") {
|
|
104
|
+
output_path = (lastindex > -1 ? input_path.substr(0, lastindex) : input_path) + ".css";
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
output_path = c_ctx->output_path;
|
|
109
|
+
}
|
|
110
|
+
Context cpp_ctx(
|
|
111
|
+
Context::Data().source_c_str(c_ctx->source_string)
|
|
112
|
+
.output_path(output_path)
|
|
113
|
+
.output_style((Output_Style) c_ctx->options.output_style)
|
|
114
|
+
.is_indented_syntax_src(c_ctx->options.is_indented_syntax_src)
|
|
115
|
+
.source_comments(c_ctx->options.source_comments)
|
|
116
|
+
.source_map_file(safe_str(c_ctx->options.source_map_file))
|
|
117
|
+
.source_map_embed(c_ctx->options.source_map_embed)
|
|
118
|
+
.source_map_contents(c_ctx->options.source_map_contents)
|
|
119
|
+
.omit_source_map_url(c_ctx->options.omit_source_map_url)
|
|
120
|
+
.image_path(safe_str(c_ctx->options.image_path))
|
|
121
|
+
.include_paths_c_str(c_ctx->options.include_paths)
|
|
122
|
+
.include_paths_array(0)
|
|
123
|
+
.include_paths(vector<string>())
|
|
124
|
+
.precision(c_ctx->options.precision ? c_ctx->options.precision : 5)
|
|
125
|
+
.importer(0)
|
|
126
|
+
);
|
|
127
|
+
if (c_ctx->c_functions) {
|
|
128
|
+
struct Sass_C_Function_Descriptor** this_func_data = c_ctx->c_functions;
|
|
129
|
+
while ((this_func_data) && (*this_func_data)) {
|
|
130
|
+
cpp_ctx.c_functions.push_back(*this_func_data);
|
|
131
|
+
++this_func_data;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
c_ctx->output_string = cpp_ctx.compile_string();
|
|
135
|
+
c_ctx->source_map_string = cpp_ctx.generate_source_map();
|
|
136
|
+
c_ctx->error_message = 0;
|
|
137
|
+
c_ctx->error_status = 0;
|
|
138
|
+
|
|
139
|
+
copy_strings(cpp_ctx.get_included_files(1), &c_ctx->included_files, 1);
|
|
140
|
+
}
|
|
141
|
+
catch (Sass_Error& e) {
|
|
142
|
+
stringstream msg_stream;
|
|
143
|
+
msg_stream << e.path << ":" << e.position.line << ": " << e.message << endl;
|
|
144
|
+
c_ctx->error_message = strdup(msg_stream.str().c_str());
|
|
145
|
+
c_ctx->error_status = 1;
|
|
146
|
+
c_ctx->output_string = 0;
|
|
147
|
+
c_ctx->source_map_string = 0;
|
|
148
|
+
}
|
|
149
|
+
catch(bad_alloc& ba) {
|
|
150
|
+
stringstream msg_stream;
|
|
151
|
+
msg_stream << "Unable to allocate memory: " << ba.what() << endl;
|
|
152
|
+
c_ctx->error_message = strdup(msg_stream.str().c_str());
|
|
153
|
+
c_ctx->error_status = 1;
|
|
154
|
+
c_ctx->output_string = 0;
|
|
155
|
+
c_ctx->source_map_string = 0;
|
|
156
|
+
}
|
|
157
|
+
catch (std::exception& e) {
|
|
158
|
+
stringstream msg_stream;
|
|
159
|
+
msg_stream << "Error: " << e.what() << endl;
|
|
160
|
+
c_ctx->error_message = strdup(msg_stream.str().c_str());
|
|
161
|
+
c_ctx->error_status = 1;
|
|
162
|
+
c_ctx->output_string = 0;
|
|
163
|
+
c_ctx->source_map_string = 0;
|
|
164
|
+
}
|
|
165
|
+
catch (string& e) {
|
|
166
|
+
stringstream msg_stream;
|
|
167
|
+
msg_stream << "Error: " << e << endl;
|
|
168
|
+
c_ctx->error_message = strdup(msg_stream.str().c_str());
|
|
169
|
+
c_ctx->error_status = 1;
|
|
170
|
+
c_ctx->output_string = 0;
|
|
171
|
+
c_ctx->source_map_string = 0;
|
|
172
|
+
}
|
|
173
|
+
catch (...) {
|
|
174
|
+
// couldn't find the specified file in the include paths; report an error
|
|
175
|
+
stringstream msg_stream;
|
|
176
|
+
msg_stream << "Unknown error occurred" << endl;
|
|
177
|
+
c_ctx->error_message = strdup(msg_stream.str().c_str());
|
|
178
|
+
c_ctx->error_status = 1;
|
|
179
|
+
c_ctx->output_string = 0;
|
|
180
|
+
c_ctx->source_map_string = 0;
|
|
181
|
+
}
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
int sass_compile_file(sass_file_context* c_ctx)
|
|
186
|
+
{
|
|
187
|
+
using namespace Sass;
|
|
188
|
+
try {
|
|
189
|
+
string input_path = safe_str(c_ctx->input_path);
|
|
190
|
+
int lastindex = static_cast<int>(input_path.find_last_of("."));
|
|
191
|
+
string output_path;
|
|
192
|
+
if (!c_ctx->output_path) {
|
|
193
|
+
output_path = (lastindex > -1 ? input_path.substr(0, lastindex) : input_path) + ".css";
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
output_path = c_ctx->output_path;
|
|
197
|
+
}
|
|
198
|
+
Context cpp_ctx(
|
|
199
|
+
Context::Data().entry_point(input_path)
|
|
200
|
+
.output_path(output_path)
|
|
201
|
+
.output_style((Output_Style) c_ctx->options.output_style)
|
|
202
|
+
.is_indented_syntax_src(c_ctx->options.is_indented_syntax_src)
|
|
203
|
+
.source_comments(c_ctx->options.source_comments)
|
|
204
|
+
.source_map_file(safe_str(c_ctx->options.source_map_file))
|
|
205
|
+
.source_map_embed(c_ctx->options.source_map_embed)
|
|
206
|
+
.source_map_contents(c_ctx->options.source_map_contents)
|
|
207
|
+
.omit_source_map_url(c_ctx->options.omit_source_map_url)
|
|
208
|
+
.image_path(safe_str(c_ctx->options.image_path))
|
|
209
|
+
.include_paths_c_str(c_ctx->options.include_paths)
|
|
210
|
+
.include_paths_array(0)
|
|
211
|
+
.include_paths(vector<string>())
|
|
212
|
+
.precision(c_ctx->options.precision ? c_ctx->options.precision : 5)
|
|
213
|
+
);
|
|
214
|
+
if (c_ctx->c_functions) {
|
|
215
|
+
struct Sass_C_Function_Descriptor** this_func_data = c_ctx->c_functions;
|
|
216
|
+
while ((this_func_data) && (*this_func_data)) {
|
|
217
|
+
cpp_ctx.c_functions.push_back(*this_func_data);
|
|
218
|
+
++this_func_data;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
c_ctx->output_string = cpp_ctx.compile_file();
|
|
222
|
+
c_ctx->source_map_string = cpp_ctx.generate_source_map();
|
|
223
|
+
c_ctx->error_message = 0;
|
|
224
|
+
c_ctx->error_status = 0;
|
|
225
|
+
|
|
226
|
+
copy_strings(cpp_ctx.get_included_files(), &c_ctx->included_files);
|
|
227
|
+
}
|
|
228
|
+
catch (Sass_Error& e) {
|
|
229
|
+
stringstream msg_stream;
|
|
230
|
+
msg_stream << e.path << ":" << e.position.line << ": " << e.message << endl;
|
|
231
|
+
c_ctx->error_message = strdup(msg_stream.str().c_str());
|
|
232
|
+
c_ctx->error_status = 1;
|
|
233
|
+
c_ctx->output_string = 0;
|
|
234
|
+
c_ctx->source_map_string = 0;
|
|
235
|
+
}
|
|
236
|
+
catch(bad_alloc& ba) {
|
|
237
|
+
stringstream msg_stream;
|
|
238
|
+
msg_stream << "Unable to allocate memory: " << ba.what() << endl;
|
|
239
|
+
c_ctx->error_message = strdup(msg_stream.str().c_str());
|
|
240
|
+
c_ctx->error_status = 1;
|
|
241
|
+
c_ctx->output_string = 0;
|
|
242
|
+
c_ctx->source_map_string = 0;
|
|
243
|
+
}
|
|
244
|
+
catch (std::exception& e) {
|
|
245
|
+
stringstream msg_stream;
|
|
246
|
+
msg_stream << "Error: " << e.what() << endl;
|
|
247
|
+
c_ctx->error_message = strdup(msg_stream.str().c_str());
|
|
248
|
+
c_ctx->error_status = 1;
|
|
249
|
+
c_ctx->output_string = 0;
|
|
250
|
+
c_ctx->source_map_string = 0;
|
|
251
|
+
}
|
|
252
|
+
catch (string& e) {
|
|
253
|
+
stringstream msg_stream;
|
|
254
|
+
msg_stream << "Error: " << e << endl;
|
|
255
|
+
c_ctx->error_message = strdup(msg_stream.str().c_str());
|
|
256
|
+
c_ctx->error_status = 1;
|
|
257
|
+
c_ctx->output_string = 0;
|
|
258
|
+
c_ctx->source_map_string = 0;
|
|
259
|
+
}
|
|
260
|
+
catch (...) {
|
|
261
|
+
// couldn't find the specified file in the include paths; report an error
|
|
262
|
+
stringstream msg_stream;
|
|
263
|
+
msg_stream << "Unknown error occurred" << endl;
|
|
264
|
+
c_ctx->error_message = strdup(msg_stream.str().c_str());
|
|
265
|
+
c_ctx->error_status = 1;
|
|
266
|
+
c_ctx->output_string = 0;
|
|
267
|
+
c_ctx->source_map_string = 0;
|
|
268
|
+
}
|
|
269
|
+
return 0;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
int sass_compile_folder(sass_folder_context* c_ctx)
|
|
273
|
+
{
|
|
274
|
+
return 1;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
}
|