sassc 2.1.0.pre1-x86-mingw32
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 +17 -0
- data/.gitmodules +3 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +66 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +68 -0
- data/Rakefile +30 -0
- data/lib/sassc/2.3/libsass.so +0 -0
- data/lib/sassc/2.4/libsass.so +0 -0
- data/lib/sassc/2.5/libsass.so +0 -0
- data/lib/sassc/2.6/libsass.so +0 -0
- data/lib/sassc/dependency.rb +17 -0
- data/lib/sassc/engine.rb +139 -0
- data/lib/sassc/error.rb +37 -0
- data/lib/sassc/functions_handler.rb +75 -0
- data/lib/sassc/import_handler.rb +50 -0
- data/lib/sassc/importer.rb +31 -0
- data/lib/sassc/native/lib_c.rb +21 -0
- data/lib/sassc/native/native_context_api.rb +147 -0
- data/lib/sassc/native/native_functions_api.rb +164 -0
- data/lib/sassc/native/sass2scss_api.rb +10 -0
- data/lib/sassc/native/sass_input_style.rb +13 -0
- data/lib/sassc/native/sass_output_style.rb +12 -0
- data/lib/sassc/native/sass_value.rb +97 -0
- data/lib/sassc/native/string_list.rb +10 -0
- data/lib/sassc/native.rb +70 -0
- data/lib/sassc/sass_2_scss.rb +9 -0
- data/lib/sassc/script/functions.rb +8 -0
- data/lib/sassc/script/value/bool.rb +32 -0
- data/lib/sassc/script/value/color.rb +95 -0
- data/lib/sassc/script/value/list.rb +136 -0
- data/lib/sassc/script/value/map.rb +69 -0
- data/lib/sassc/script/value/number.rb +389 -0
- data/lib/sassc/script/value/string.rb +96 -0
- data/lib/sassc/script/value.rb +137 -0
- data/lib/sassc/script/value_conversion/base.rb +13 -0
- data/lib/sassc/script/value_conversion/bool.rb +13 -0
- data/lib/sassc/script/value_conversion/color.rb +18 -0
- data/lib/sassc/script/value_conversion/list.rb +25 -0
- data/lib/sassc/script/value_conversion/map.rb +21 -0
- data/lib/sassc/script/value_conversion/number.rb +13 -0
- data/lib/sassc/script/value_conversion/string.rb +17 -0
- data/lib/sassc/script/value_conversion.rb +69 -0
- data/lib/sassc/script.rb +19 -0
- data/lib/sassc/util/normalized_map.rb +117 -0
- data/lib/sassc/util.rb +231 -0
- data/lib/sassc/version.rb +5 -0
- data/lib/sassc.rb +57 -0
- data/sassc.gemspec +57 -0
- data/test/custom_importer_test.rb +127 -0
- data/test/engine_test.rb +314 -0
- data/test/error_test.rb +29 -0
- data/test/fixtures/paths.scss +10 -0
- data/test/functions_test.rb +303 -0
- data/test/native_test.rb +213 -0
- data/test/output_style_test.rb +107 -0
- data/test/sass_2_scss_test.rb +14 -0
- data/test/test_helper.rb +45 -0
- metadata +242 -0
@@ -0,0 +1,147 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SassC
|
4
|
+
module Native
|
5
|
+
attach_function :version, :libsass_version, [], :string
|
6
|
+
|
7
|
+
# Create and initialize an option struct
|
8
|
+
# ADDAPI struct Sass_Options* ADDCALL sass_make_options (void);
|
9
|
+
attach_function :sass_make_options, [], :sass_options_ptr
|
10
|
+
|
11
|
+
# Create and initialize a specific context
|
12
|
+
# ADDAPI struct Sass_File_Context* ADDCALL sass_make_file_context (const char* input_path);
|
13
|
+
# ADDAPI struct Sass_Data_Context* ADDCALL sass_make_data_context (char* source_string);
|
14
|
+
attach_function :sass_make_file_context, [:string], :sass_file_context_ptr
|
15
|
+
attach_function :_make_data_context, :sass_make_data_context, [:pointer], :sass_data_context_ptr
|
16
|
+
|
17
|
+
def self.make_data_context(data)
|
18
|
+
_make_data_context(Native.native_string(data))
|
19
|
+
end
|
20
|
+
|
21
|
+
# Call the compilation step for the specific context
|
22
|
+
# ADDAPI int ADDCALL sass_compile_file_context (struct Sass_File_Context* ctx);
|
23
|
+
# ADDAPI int ADDCALL sass_compile_data_context (struct Sass_Data_Context* ctx);
|
24
|
+
attach_function :sass_compile_file_context, [:sass_file_context_ptr], :int
|
25
|
+
attach_function :sass_compile_data_context, [:sass_data_context_ptr], :int
|
26
|
+
|
27
|
+
# Create a sass compiler instance for more control
|
28
|
+
# ADDAPI struct Sass_Compiler* ADDCALL sass_make_file_compiler (struct Sass_File_Context* file_ctx);
|
29
|
+
# ADDAPI struct Sass_Compiler* ADDCALL sass_make_data_compiler (struct Sass_Data_Context* data_ctx);
|
30
|
+
|
31
|
+
# Execute the different compilation steps individually
|
32
|
+
# Usefull if you only want to query the included files
|
33
|
+
# ADDAPI int ADDCALL sass_compiler_parse(struct Sass_Compiler* compiler);
|
34
|
+
# ADDAPI int ADDCALL sass_compiler_execute(struct Sass_Compiler* compiler);
|
35
|
+
|
36
|
+
# Release all memory allocated with the compiler
|
37
|
+
# This does _not_ include any contexts or options
|
38
|
+
# ADDAPI void ADDCALL sass_delete_compiler(struct Sass_Compiler* compiler);
|
39
|
+
|
40
|
+
# Release all memory allocated and also ourself
|
41
|
+
# ADDAPI void ADDCALL sass_delete_file_context (struct Sass_File_Context* ctx);
|
42
|
+
# ADDAPI void ADDCALL sass_delete_data_context (struct Sass_Data_Context* ctx);
|
43
|
+
attach_function :sass_delete_file_context, [:sass_file_context_ptr], :void
|
44
|
+
attach_function :sass_delete_data_context, [:sass_data_context_ptr], :void
|
45
|
+
|
46
|
+
# Getters for context from specific implementation
|
47
|
+
# ADDAPI struct Sass_Context* ADDCALL sass_file_context_get_context (struct Sass_File_Context* file_ctx);
|
48
|
+
# ADDAPI struct Sass_Context* ADDCALL sass_data_context_get_context (struct Sass_Data_Context* data_ctx);
|
49
|
+
attach_function :sass_file_context_get_context, [:sass_file_context_ptr], :sass_context_ptr
|
50
|
+
attach_function :sass_data_context_get_context, [:sass_data_context_ptr], :sass_context_ptr
|
51
|
+
|
52
|
+
# Getters for context options from Sass_Context
|
53
|
+
# ADDAPI struct Sass_Options* ADDCALL sass_context_get_options (struct Sass_Context* ctx);
|
54
|
+
# ADDAPI struct Sass_Options* ADDCALL sass_file_context_get_options (struct Sass_File_Context* file_ctx);
|
55
|
+
# ADDAPI struct Sass_Options* ADDCALL sass_data_context_get_options (struct Sass_Data_Context* data_ctx);
|
56
|
+
# ADDAPI void ADDCALL sass_file_context_set_options (struct Sass_File_Context* file_ctx, struct Sass_Options* opt);
|
57
|
+
# ADDAPI void ADDCALL sass_data_context_set_options (struct Sass_Data_Context* data_ctx, struct Sass_Options* opt);
|
58
|
+
attach_function :sass_context_get_options, [:sass_context_ptr], :sass_options_ptr
|
59
|
+
attach_function :sass_file_context_get_options, [:sass_file_context_ptr], :sass_options_ptr
|
60
|
+
attach_function :sass_data_context_get_options, [:sass_data_context_ptr], :sass_options_ptr
|
61
|
+
attach_function :sass_file_context_set_options, [:sass_file_context_ptr, :sass_options_ptr], :void
|
62
|
+
attach_function :sass_data_context_set_options, [:sass_data_context_ptr, :sass_options_ptr], :void
|
63
|
+
|
64
|
+
# Getters for options
|
65
|
+
# ADDAPI int ADDCALL sass_option_get_precision (struct Sass_Options* options);
|
66
|
+
# ADDAPI enum Sass_Output_Style ADDCALL sass_option_get_output_style (struct Sass_Options* options);
|
67
|
+
# ADDAPI bool ADDCALL sass_option_get_source_comments (struct Sass_Options* options);
|
68
|
+
# ADDAPI bool ADDCALL sass_option_get_source_map_embed (struct Sass_Options* options);
|
69
|
+
# ADDAPI bool ADDCALL sass_option_get_source_map_contents (struct Sass_Options* options);
|
70
|
+
# ADDAPI bool ADDCALL sass_option_get_omit_source_map_url (struct Sass_Options* options);
|
71
|
+
# ADDAPI bool ADDCALL sass_option_get_is_indented_syntax_src (struct Sass_Options* options);
|
72
|
+
# ADDAPI const char* ADDCALL sass_option_get_input_path (struct Sass_Options* options);
|
73
|
+
# ADDAPI const char* ADDCALL sass_option_get_output_path (struct Sass_Options* options);
|
74
|
+
# ADDAPI const char* ADDCALL sass_option_get_include_path (struct Sass_Options* options);
|
75
|
+
# ADDAPI const char* ADDCALL sass_option_get_source_map_file (struct Sass_Options* options);
|
76
|
+
# ADDAPI Sass_C_Function_List ADDCALL sass_option_get_c_functions (struct Sass_Options* options);
|
77
|
+
attach_function :sass_option_get_precision, [:sass_options_ptr], :int
|
78
|
+
attach_function :sass_option_get_output_style, [:sass_options_ptr], SassOutputStyle
|
79
|
+
attach_function :sass_option_get_source_comments, [:sass_options_ptr], :bool
|
80
|
+
attach_function :sass_option_get_source_map_embed, [:sass_options_ptr], :bool
|
81
|
+
attach_function :sass_option_get_source_map_contents, [:sass_options_ptr], :bool
|
82
|
+
attach_function :sass_option_get_omit_source_map_url, [:sass_options_ptr], :bool
|
83
|
+
attach_function :sass_option_get_is_indented_syntax_src, [:sass_options_ptr], :bool
|
84
|
+
attach_function :sass_option_get_input_path, [:sass_options_ptr], :string
|
85
|
+
attach_function :sass_option_get_output_path, [:sass_options_ptr], :string
|
86
|
+
attach_function :sass_option_get_include_path, [:sass_options_ptr], :string
|
87
|
+
attach_function :sass_option_get_source_map_file, [:sass_options_ptr], :string
|
88
|
+
attach_function :sass_option_get_c_functions, [:sass_options_ptr], :sass_c_function_list_ptr
|
89
|
+
# ADDAPI Sass_C_Import_Callback ADDCALL sass_option_get_importer (struct Sass_Options* options);
|
90
|
+
|
91
|
+
# Setters for options
|
92
|
+
# ADDAPI void ADDCALL sass_option_set_precision (struct Sass_Options* options, int precision);
|
93
|
+
# ADDAPI void ADDCALL sass_option_set_output_style (struct Sass_Options* options, enum Sass_Output_Style output_style);
|
94
|
+
# ADDAPI void ADDCALL sass_option_set_source_comments (struct Sass_Options* options, bool source_comments);
|
95
|
+
# ADDAPI void ADDCALL sass_option_set_source_map_embed (struct Sass_Options* options, bool source_map_embed);
|
96
|
+
# ADDAPI void ADDCALL sass_option_set_source_map_contents (struct Sass_Options* options, bool source_map_contents);
|
97
|
+
# ADDAPI void ADDCALL sass_option_set_omit_source_map_url (struct Sass_Options* options, bool omit_source_map_url);
|
98
|
+
# ADDAPI void ADDCALL sass_option_set_is_indented_syntax_src (struct Sass_Options* options, bool is_indented_syntax_src);
|
99
|
+
# ADDAPI void ADDCALL sass_option_set_input_path (struct Sass_Options* options, const char* input_path);
|
100
|
+
# ADDAPI void ADDCALL sass_option_set_output_path (struct Sass_Options* options, const char* output_path);
|
101
|
+
# ADDAPI void ADDCALL sass_option_set_include_path (struct Sass_Options* options, const char* include_path);
|
102
|
+
# ADDAPI void ADDCALL sass_option_set_source_map_file (struct Sass_Options* options, const char* source_map_file);
|
103
|
+
# ADDAPI void ADDCALL sass_option_set_c_functions (struct Sass_Options* options, Sass_C_Function_List c_functions);
|
104
|
+
# ADDAPI void ADDCALL sass_option_set_c_importers (struct Sass_Options* options, Sass_Importer_List c_importers);
|
105
|
+
attach_function :sass_option_set_precision, [:sass_options_ptr, :int], :void
|
106
|
+
attach_function :sass_option_set_output_style, [:sass_options_ptr, SassOutputStyle], :void
|
107
|
+
attach_function :sass_option_set_source_comments, [:sass_options_ptr, :bool], :void
|
108
|
+
attach_function :sass_option_set_source_map_embed, [:sass_options_ptr, :bool], :void
|
109
|
+
attach_function :sass_option_set_source_map_contents, [:sass_options_ptr, :bool], :void
|
110
|
+
attach_function :sass_option_set_omit_source_map_url, [:sass_options_ptr, :bool], :void
|
111
|
+
attach_function :sass_option_set_is_indented_syntax_src, [:sass_options_ptr, :bool], :void
|
112
|
+
attach_function :sass_option_set_input_path, [:sass_options_ptr, :string], :void
|
113
|
+
attach_function :sass_option_set_output_path, [:sass_options_ptr, :string], :void
|
114
|
+
attach_function :sass_option_set_include_path, [:sass_options_ptr, :string], :void
|
115
|
+
attach_function :sass_option_set_source_map_file, [:sass_options_ptr, :string], :void
|
116
|
+
attach_function :sass_option_set_c_functions, [:sass_options_ptr, :pointer], :void
|
117
|
+
attach_function :sass_option_set_c_importers, [:sass_options_ptr, :pointer], :void
|
118
|
+
#attach_function :sass_option_set_c_importers, [:sass_options_ptr, :sass_importer], :void
|
119
|
+
|
120
|
+
# Getter for context
|
121
|
+
# ADDAPI const char* ADDCALL sass_context_get_output_string (struct Sass_Context* ctx);
|
122
|
+
# ADDAPI int ADDCALL sass_context_get_error_status (struct Sass_Context* ctx);
|
123
|
+
# ADDAPI const char* ADDCALL sass_context_get_error_json (struct Sass_Context* ctx);
|
124
|
+
# ADDAPI const char* ADDCALL sass_context_get_error_message (struct Sass_Context* ctx);
|
125
|
+
# ADDAPI const char* ADDCALL sass_context_get_error_file (struct Sass_Context* ctx);
|
126
|
+
# ADDAPI size_t ADDCALL sass_context_get_error_line (struct Sass_Context* ctx);
|
127
|
+
# ADDAPI size_t ADDCALL sass_context_get_error_column (struct Sass_Context* ctx);
|
128
|
+
# ADDAPI const char* ADDCALL sass_context_get_source_map_string (struct Sass_Context* ctx);
|
129
|
+
# ADDAPI char** ADDCALL sass_context_get_included_files (struct Sass_Context* ctx);
|
130
|
+
attach_function :sass_context_get_output_string, [:sass_context_ptr], :string
|
131
|
+
attach_function :sass_context_get_error_status, [:sass_context_ptr], :int
|
132
|
+
attach_function :sass_context_get_error_json, [:sass_context_ptr], :string
|
133
|
+
attach_function :sass_context_get_error_message, [:sass_context_ptr], :string
|
134
|
+
attach_function :sass_context_get_error_file, [:sass_context_ptr], :string
|
135
|
+
attach_function :sass_context_get_error_line, [:sass_context_ptr], :size_t
|
136
|
+
attach_function :sass_context_get_error_column, [:sass_context_ptr], :size_t
|
137
|
+
attach_function :sass_context_get_source_map_string, [:sass_context_ptr], :string
|
138
|
+
attach_function :_context_get_included_files, :sass_context_get_included_files, [:sass_context_ptr], :pointer
|
139
|
+
|
140
|
+
def self.context_get_included_files(*args)
|
141
|
+
return_string_array _context_get_included_files(*args)
|
142
|
+
end
|
143
|
+
|
144
|
+
# ADDAPI Sass_Import_Entry ADDCALL sass_compiler_get_last_import(struct Sass_Compiler* compiler);
|
145
|
+
attach_function :sass_compiler_get_last_import, [:pointer], :pointer
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SassC
|
4
|
+
module Native
|
5
|
+
# Creators for sass function list and function descriptors
|
6
|
+
# ADDAPI Sass_C_Function_List ADDCALL sass_make_function_list (size_t length);
|
7
|
+
# ADDAPI Sass_C_Function_Callback ADDCALL sass_make_function (const char* signature, Sass_C_Function fn, void* cookie);
|
8
|
+
attach_function :sass_make_function_list, [:size_t], :sass_c_function_list_ptr
|
9
|
+
attach_function :sass_make_function, [:string, :sass_c_function, :pointer], :sass_c_function_callback_ptr
|
10
|
+
|
11
|
+
# Setters and getters for callbacks on function lists
|
12
|
+
# ADDAPI Sass_C_Function_Callback ADDCALL sass_function_get_list_entry(Sass_C_Function_List list, size_t pos);
|
13
|
+
# ADDAPI void ADDCALL sass_function_set_list_entry(Sass_C_Function_List list, size_t pos, Sass_C_Function_Callback cb);
|
14
|
+
attach_function :sass_function_get_list_entry, [:sass_c_function_list_ptr, :size_t], :sass_c_function_callback_ptr
|
15
|
+
attach_function :sass_function_set_list_entry, [:sass_c_function_list_ptr, :size_t, :sass_c_function_callback_ptr], :void
|
16
|
+
|
17
|
+
# ADDAPI union Sass_Value* ADDCALL sass_make_number (double val, const char* unit);
|
18
|
+
attach_function :sass_make_number, [:double, :string], :sass_value_ptr
|
19
|
+
|
20
|
+
# ADDAPI union Sass_Value* ADDCALL sass_make_string (const char* val);
|
21
|
+
attach_function :sass_make_string, [:string], :sass_value_ptr
|
22
|
+
|
23
|
+
# ADDAPI union Sass_Value* ADDCALL sass_make_qstring (const char* val);
|
24
|
+
attach_function :sass_make_qstring, [:string], :sass_value_ptr
|
25
|
+
|
26
|
+
# ADDAPI union Sass_Value* ADDCALL sass_make_color (double r, double g, double b, double a);
|
27
|
+
attach_function :sass_make_color, [:double, :double, :double, :double], :sass_value_ptr
|
28
|
+
|
29
|
+
# ADDAPI union Sass_Value* ADDCALL sass_make_map (size_t len);
|
30
|
+
attach_function :sass_make_map, [:size_t], :sass_value_ptr
|
31
|
+
|
32
|
+
# ADDAPI union Sass_Value* ADDCALL sass_make_list (size_t len, enum Sass_Separator sep)
|
33
|
+
attach_function :sass_make_list, [:size_t, SassSeparator], :sass_value_ptr
|
34
|
+
|
35
|
+
# ADDAPI union Sass_Value* ADDCALL sass_make_boolean (boolean val);
|
36
|
+
attach_function :sass_make_boolean, [:bool], :sass_value_ptr
|
37
|
+
|
38
|
+
# ADDAPI void ADDCALL sass_map_set_key (union Sass_Value* v, size_t i, union Sass_Value*);
|
39
|
+
attach_function :sass_map_set_key, [:sass_value_ptr, :size_t, :sass_value_ptr], :void
|
40
|
+
|
41
|
+
# ADDAPI union Sass_Value* ADDCALL sass_map_get_key (const union Sass_Value* v, size_t i);
|
42
|
+
attach_function :sass_map_get_key, [:sass_value_ptr, :size_t], :sass_value_ptr
|
43
|
+
|
44
|
+
# ADDAPI void ADDCALL sass_map_set_value (union Sass_Value* v, size_t i, union Sass_Value*);
|
45
|
+
attach_function :sass_map_set_value, [:sass_value_ptr, :size_t, :sass_value_ptr], :void
|
46
|
+
|
47
|
+
# ADDAPI union Sass_Value* ADDCALL sass_map_get_value (const union Sass_Value* v, size_t i);
|
48
|
+
attach_function :sass_map_get_value, [:sass_value_ptr, :size_t], :sass_value_ptr
|
49
|
+
|
50
|
+
# ADDAPI size_t ADDCALL sass_map_get_length (const union Sass_Value* v);
|
51
|
+
attach_function :sass_map_get_length, [:sass_value_ptr], :size_t
|
52
|
+
|
53
|
+
# ADDAPI union Sass_Value* ADDCALL sass_list_get_value (const union Sass_Value* v, size_t i);
|
54
|
+
attach_function :sass_list_get_value, [:sass_value_ptr, :size_t], :sass_value_ptr
|
55
|
+
|
56
|
+
# ADDAPI void ADDCALL sass_list_set_value (union Sass_Value* v, size_t i, union Sass_Value* value);
|
57
|
+
attach_function :sass_list_set_value, [:sass_value_ptr, :size_t, :sass_value_ptr], :void
|
58
|
+
|
59
|
+
# ADDAPI size_t ADDCALL sass_list_get_length (const union Sass_Value* v);
|
60
|
+
attach_function :sass_list_get_length, [:sass_value_ptr], :size_t
|
61
|
+
|
62
|
+
# ADDAPI union Sass_Value* ADDCALL sass_make_error (const char* msg);
|
63
|
+
attach_function :sass_make_error, [:string], :sass_value_ptr
|
64
|
+
|
65
|
+
# ADDAPI enum Sass_Tag ADDCALL sass_value_get_tag (const union Sass_Value* v);
|
66
|
+
attach_function :sass_value_get_tag, [:sass_value_ptr], SassTag
|
67
|
+
attach_function :sass_value_is_null, [:sass_value_ptr], :bool
|
68
|
+
|
69
|
+
# ADDAPI const char* ADDCALL sass_string_get_value (const union Sass_Value* v);
|
70
|
+
attach_function :sass_string_get_value, [:sass_value_ptr], :string
|
71
|
+
|
72
|
+
# ADDAPI bool ADDCALL sass_string_is_quoted(const union Sass_Value* v);
|
73
|
+
attach_function :sass_string_is_quoted, [:sass_value_ptr], :bool
|
74
|
+
|
75
|
+
# ADDAPI const char* ADDCALL sass_number_get_value (const union Sass_Value* v);
|
76
|
+
attach_function :sass_number_get_value, [:sass_value_ptr], :double
|
77
|
+
|
78
|
+
# ADDAPI const char* ADDCALL sass_number_get_unit (const union Sass_Value* v);
|
79
|
+
attach_function :sass_number_get_unit, [:sass_value_ptr], :string
|
80
|
+
|
81
|
+
# ADDAPI const char* ADDCALL sass_boolean_get_value (const union Sass_Value* v);
|
82
|
+
attach_function :sass_boolean_get_value, [:sass_value_ptr], :bool
|
83
|
+
|
84
|
+
def self.string_get_type(native_value)
|
85
|
+
string_is_quoted(native_value) ? :string : :identifier
|
86
|
+
end
|
87
|
+
|
88
|
+
# ADDAPI double ADDCALL sass_color_get_r (const union Sass_Value* v);
|
89
|
+
# ADDAPI void ADDCALL sass_color_set_r (union Sass_Value* v, double r);
|
90
|
+
# ADDAPI double ADDCALL sass_color_get_g (const union Sass_Value* v);
|
91
|
+
# ADDAPI void ADDCALL sass_color_set_g (union Sass_Value* v, double g);
|
92
|
+
# ADDAPI double ADDCALL sass_color_get_b (const union Sass_Value* v);
|
93
|
+
# ADDAPI void ADDCALL sass_color_set_b (union Sass_Value* v, double b);
|
94
|
+
# ADDAPI double ADDCALL sass_color_get_a (const union Sass_Value* v);
|
95
|
+
# ADDAPI void ADDCALL sass_color_set_a (union Sass_Value* v, double a);
|
96
|
+
['r', 'g', 'b', 'a'].each do |color_channel|
|
97
|
+
attach_function "sass_color_get_#{color_channel}".to_sym, [:sass_value_ptr], :double
|
98
|
+
attach_function "sass_color_set_#{color_channel}".to_sym, [:sass_value_ptr, :double], :void
|
99
|
+
end
|
100
|
+
|
101
|
+
# ADDAPI size_t ADDCALL sass_list_get_length(const union Sass_Value* v)
|
102
|
+
# ADDAPI union Sass_Value* ADDCALL sass_list_get_value (const union Sass_Value* v, size_t i);
|
103
|
+
attach_function :sass_list_get_length, [:sass_value_ptr], :size_t
|
104
|
+
attach_function :sass_list_get_value, [:sass_value_ptr, :size_t], :sass_value_ptr
|
105
|
+
|
106
|
+
# ADDAPI char* ADDCALL sass_error_get_message (const union Sass_Value* v);
|
107
|
+
# ADDAPI void ADDCALL sass_error_set_message (union Sass_Value* v, char* msg);
|
108
|
+
attach_function :sass_error_get_message, [:sass_value_ptr], :string
|
109
|
+
attach_function :sass_error_set_message, [:sass_value_ptr, :pointer], :void
|
110
|
+
|
111
|
+
# Getters for custom function descriptors
|
112
|
+
# ADDAPI const char* ADDCALL sass_function_get_signature (Sass_C_Function_Callback fn);
|
113
|
+
# ADDAPI Sass_C_Function ADDCALL sass_function_get_function (Sass_C_Function_Callback fn);
|
114
|
+
# ADDAPI void* ADDCALL sass_function_get_cookie (Sass_C_Function_Callback fn);
|
115
|
+
attach_function :sass_function_get_signature, [:sass_c_function_callback_ptr], :string
|
116
|
+
attach_function :sass_function_get_function, [:sass_c_function_callback_ptr], :sass_c_function
|
117
|
+
attach_function :sass_function_get_cookie, [:sass_c_function_callback_ptr], :pointer
|
118
|
+
|
119
|
+
# Creators for custom importer callback (with some additional pointer)
|
120
|
+
# The pointer is mostly used to store the callback into the actual binding
|
121
|
+
# ADDAPI Sass_C_Import_Callback ADDCALL sass_make_importer (Sass_C_Import_Fn, void* cookie);
|
122
|
+
attach_function :sass_make_importer, [:sass_c_import_function, :pointer], :sass_importer
|
123
|
+
|
124
|
+
# Getters for import function descriptors
|
125
|
+
# ADDAPI Sass_C_Import_Fn ADDCALL sass_import_get_function (Sass_C_Import_Callback fn);
|
126
|
+
# ADDAPI void* ADDCALL sass_import_get_cookie (Sass_C_Import_Callback fn);
|
127
|
+
|
128
|
+
# Deallocator for associated memory
|
129
|
+
# ADDAPI void ADDCALL sass_delete_importer (Sass_C_Import_Callback fn);
|
130
|
+
|
131
|
+
# Creator for sass custom importer return argument list
|
132
|
+
# ADDAPI struct Sass_Import** ADDCALL sass_make_import_list (size_t length);
|
133
|
+
attach_function :sass_make_import_list, [:size_t], :sass_import_list_ptr
|
134
|
+
|
135
|
+
# Creator for a single import entry returned by the custom importer inside the list
|
136
|
+
# ADDAPI struct Sass_Import* ADDCALL sass_make_import_entry (const char* path, char* source, char* srcmap);
|
137
|
+
# ADDAPI struct Sass_Import* ADDCALL sass_make_import (const char* path, const char* base, char* source, char* srcmap);
|
138
|
+
attach_function :sass_make_import_entry, [:string, :pointer, :pointer], :sass_import_ptr
|
139
|
+
|
140
|
+
# Setters to insert an entry into the import list (you may also use [] access directly)
|
141
|
+
# Since we are dealing with pointers they should have a guaranteed and fixed size
|
142
|
+
# ADDAPI void ADDCALL sass_import_set_list_entry (struct Sass_Import** list, size_t idx, struct Sass_Import* entry);
|
143
|
+
attach_function :sass_import_set_list_entry, [:sass_import_list_ptr, :size_t, :sass_import_ptr], :void
|
144
|
+
# ADDAPI struct Sass_Import* ADDCALL sass_import_get_list_entry (struct Sass_Import** list, size_t idx);
|
145
|
+
|
146
|
+
# Getters for import entry
|
147
|
+
# ADDAPI const char* ADDCALL sass_import_get_imp_path (struct Sass_Import*);
|
148
|
+
attach_function :sass_import_get_imp_path, [:sass_import_ptr], :string
|
149
|
+
# ADDAPI const char* ADDCALL sass_import_get_abs_path (struct Sass_Import*);
|
150
|
+
attach_function :sass_import_get_abs_path, [:sass_import_ptr], :string
|
151
|
+
# ADDAPI const char* ADDCALL sass_import_get_source (struct Sass_Import*);
|
152
|
+
attach_function :sass_import_get_source, [:sass_import_ptr], :string
|
153
|
+
# ADDAPI const char* ADDCALL sass_import_get_srcmap (struct Sass_Import*);
|
154
|
+
# Explicit functions to take ownership of these items
|
155
|
+
# The property on our struct will be reset to NULL
|
156
|
+
# ADDAPI char* ADDCALL sass_import_take_source (struct Sass_Import*);
|
157
|
+
# ADDAPI char* ADDCALL sass_import_take_srcmap (struct Sass_Import*);
|
158
|
+
|
159
|
+
# Deallocator for associated memory (incl. entries)
|
160
|
+
# ADDAPI void ADDCALL sass_delete_import_list (struct Sass_Import**);
|
161
|
+
# Just in case we have some stray import structs
|
162
|
+
# ADDAPI void ADDCALL sass_delete_import (struct Sass_Import*);
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SassC
|
4
|
+
module Native
|
5
|
+
# ADDAPI char* ADDCALL sass2scss (const char* sass, const int options);
|
6
|
+
attach_function :sass2scss, [:string, :int], :string
|
7
|
+
|
8
|
+
# ADDAPI const char* ADDCALL sass2scss_version(void);
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SassC
|
4
|
+
module Native
|
5
|
+
class SassValue < FFI::Union; end
|
6
|
+
|
7
|
+
SassTag = enum(
|
8
|
+
:sass_boolean,
|
9
|
+
:sass_number,
|
10
|
+
:sass_color,
|
11
|
+
:sass_string,
|
12
|
+
:sass_list,
|
13
|
+
:sass_map,
|
14
|
+
:sass_null,
|
15
|
+
:sass_error,
|
16
|
+
:sass_warning
|
17
|
+
)
|
18
|
+
|
19
|
+
SassSeparator = enum(
|
20
|
+
:sass_comma,
|
21
|
+
:sass_space
|
22
|
+
)
|
23
|
+
|
24
|
+
class SassUnknown < FFI::Struct
|
25
|
+
layout :tag, SassTag
|
26
|
+
end
|
27
|
+
|
28
|
+
class SassBoolean < FFI::Struct
|
29
|
+
layout :tag, SassTag,
|
30
|
+
:value, :bool
|
31
|
+
end
|
32
|
+
|
33
|
+
class SassNumber < FFI::Struct
|
34
|
+
layout :tag, SassTag,
|
35
|
+
:value, :double,
|
36
|
+
:unit, :string
|
37
|
+
end
|
38
|
+
|
39
|
+
class SassColor < FFI::Struct
|
40
|
+
layout :tag, SassTag,
|
41
|
+
:r, :double,
|
42
|
+
:g, :double,
|
43
|
+
:b, :double,
|
44
|
+
:a, :double
|
45
|
+
end
|
46
|
+
|
47
|
+
class SassString < FFI::Struct
|
48
|
+
layout :tag, SassTag,
|
49
|
+
:value, :string
|
50
|
+
end
|
51
|
+
|
52
|
+
class SassList < FFI::Struct
|
53
|
+
layout :tag, SassTag,
|
54
|
+
:separator, SassSeparator,
|
55
|
+
:length, :size_t,
|
56
|
+
:values, :pointer
|
57
|
+
end
|
58
|
+
|
59
|
+
class SassMapPair < FFI::Struct
|
60
|
+
layout :key, SassValue.ptr,
|
61
|
+
:value, SassValue.ptr
|
62
|
+
end
|
63
|
+
|
64
|
+
class SassMap < FFI::Struct
|
65
|
+
layout :tag, SassTag,
|
66
|
+
:length, :size_t,
|
67
|
+
:pairs, SassMapPair.ptr
|
68
|
+
end
|
69
|
+
|
70
|
+
class SassNull < FFI::Struct
|
71
|
+
layout :tag, SassTag
|
72
|
+
end
|
73
|
+
|
74
|
+
class SassError < FFI::Struct
|
75
|
+
layout :tag, SassTag,
|
76
|
+
:message, :string
|
77
|
+
end
|
78
|
+
|
79
|
+
class SassWarning < FFI::Struct
|
80
|
+
layout :tag, SassTag,
|
81
|
+
:message, :string
|
82
|
+
end
|
83
|
+
|
84
|
+
class SassValue # < FFI::Union
|
85
|
+
layout :unknown, SassUnknown,
|
86
|
+
:boolean, SassBoolean,
|
87
|
+
:number, SassNumber,
|
88
|
+
:color, SassColor,
|
89
|
+
:string, SassString,
|
90
|
+
:list, SassList,
|
91
|
+
:map, SassMap,
|
92
|
+
:null, SassNull,
|
93
|
+
:error, SassError,
|
94
|
+
:warning, SassWarning
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/sassc/native.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ffi"
|
4
|
+
|
5
|
+
module SassC
|
6
|
+
module Native
|
7
|
+
extend FFI::Library
|
8
|
+
|
9
|
+
spec = Gem.loaded_specs["sassc"]
|
10
|
+
gem_root = spec.gem_dir
|
11
|
+
|
12
|
+
dl_ext = (RUBY_PLATFORM =~ /darwin/ ? 'bundle' : 'so')
|
13
|
+
ruby_version_so_path = "#{gem_root}/lib/sassc/#{RUBY_VERSION[/\d+.\d+/]}/libsass.#{dl_ext}"
|
14
|
+
if File.exist?(ruby_version_so_path)
|
15
|
+
ffi_lib ruby_version_so_path
|
16
|
+
else
|
17
|
+
ffi_lib "#{gem_root}/lib/sassc/libsass.#{dl_ext}"
|
18
|
+
end
|
19
|
+
|
20
|
+
require_relative "native/sass_value"
|
21
|
+
|
22
|
+
typedef :pointer, :sass_options_ptr
|
23
|
+
typedef :pointer, :sass_context_ptr
|
24
|
+
typedef :pointer, :sass_file_context_ptr
|
25
|
+
typedef :pointer, :sass_data_context_ptr
|
26
|
+
|
27
|
+
typedef :pointer, :sass_c_function_list_ptr
|
28
|
+
typedef :pointer, :sass_c_function_callback_ptr
|
29
|
+
typedef :pointer, :sass_value_ptr
|
30
|
+
|
31
|
+
typedef :pointer, :sass_import_list_ptr
|
32
|
+
typedef :pointer, :sass_importer
|
33
|
+
typedef :pointer, :sass_import_ptr
|
34
|
+
|
35
|
+
callback :sass_c_function, [:pointer, :pointer], :pointer
|
36
|
+
callback :sass_c_import_function, [:pointer, :pointer, :pointer], :pointer
|
37
|
+
|
38
|
+
require_relative "native/sass_input_style"
|
39
|
+
require_relative "native/sass_output_style"
|
40
|
+
require_relative "native/string_list"
|
41
|
+
require_relative "native/lib_c"
|
42
|
+
|
43
|
+
# Remove the redundant "sass_" from the beginning of every method name
|
44
|
+
def self.attach_function(*args)
|
45
|
+
super if args.size != 3
|
46
|
+
|
47
|
+
if args[0] =~ /^sass_/
|
48
|
+
args.unshift args[0].to_s.sub(/^sass_/, "")
|
49
|
+
end
|
50
|
+
|
51
|
+
super(*args)
|
52
|
+
end
|
53
|
+
|
54
|
+
# https://github.com/ffi/ffi/wiki/Examples#array-of-strings
|
55
|
+
def self.return_string_array(ptr)
|
56
|
+
ptr.null? ? [] : ptr.get_array_of_string(0).compact
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.native_string(string)
|
60
|
+
string = "#{string}\0"
|
61
|
+
data = Native::LibC.malloc(string.bytesize)
|
62
|
+
data.write_string(string)
|
63
|
+
data
|
64
|
+
end
|
65
|
+
|
66
|
+
require_relative "native/native_context_api"
|
67
|
+
require_relative "native/native_functions_api"
|
68
|
+
require_relative "native/sass2scss_api"
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A SassScript object representing a boolean (true or false) value.
|
4
|
+
|
5
|
+
class SassC::Script::Value::Bool < SassC::Script::Value
|
6
|
+
|
7
|
+
# The true value in SassScript.
|
8
|
+
# This is assigned before new is overridden below so that we use the default implementation.
|
9
|
+
TRUE = new(true)
|
10
|
+
|
11
|
+
# The false value in SassScript.
|
12
|
+
# This is assigned before new is overridden below so that we use the default implementation.
|
13
|
+
FALSE = new(false)
|
14
|
+
|
15
|
+
# We override object creation so that users of the core API
|
16
|
+
# will not need to know that booleans are specific constants.
|
17
|
+
# Tests `value` for truthiness and returns the TRUE or FALSE constant.
|
18
|
+
def self.new(value)
|
19
|
+
value ? TRUE : FALSE
|
20
|
+
end
|
21
|
+
|
22
|
+
# The pure Ruby value of this Boolean
|
23
|
+
attr_reader :value
|
24
|
+
alias_method :to_bool, :value
|
25
|
+
|
26
|
+
# Returns the string "true" or "false" for this value
|
27
|
+
def to_s(opts = {})
|
28
|
+
@value.to_s
|
29
|
+
end
|
30
|
+
alias_method :to_sass, :to_s
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A SassScript object representing a CSS color.
|
4
|
+
# This class provides a very bare-bones system for storing a RGB(A) or HSL(A)
|
5
|
+
# color and converting it to a CSS color function.
|
6
|
+
#
|
7
|
+
# If your Sass method accepts a color you will need to perform any
|
8
|
+
# needed color mathematics or transformations yourself.
|
9
|
+
|
10
|
+
class SassC::Script::Value::Color < SassC::Script::Value
|
11
|
+
|
12
|
+
attr_reader :red
|
13
|
+
attr_reader :green
|
14
|
+
attr_reader :blue
|
15
|
+
attr_reader :hue
|
16
|
+
attr_reader :saturation
|
17
|
+
attr_reader :lightness
|
18
|
+
attr_reader :alpha
|
19
|
+
|
20
|
+
# Creates a new color with (`red`, `green`, `blue`) or (`hue`, `saturation`, `lightness`
|
21
|
+
# values, plus an optional `alpha` transparency value.
|
22
|
+
def initialize(red:nil, green:nil, blue:nil, hue:nil, saturation:nil, lightness:nil, alpha:1.0)
|
23
|
+
if red && green && blue && alpha
|
24
|
+
@mode = :rgba
|
25
|
+
@red = SassC::Util.clamp(red.to_i, 0, 255)
|
26
|
+
@green = SassC::Util.clamp(green.to_i, 0, 255)
|
27
|
+
@blue = SassC::Util.clamp(blue.to_i, 0, 255)
|
28
|
+
@alpha = SassC::Util.clamp(alpha.to_f, 0.0, 1.0)
|
29
|
+
elsif hue && saturation && lightness && alpha
|
30
|
+
@mode = :hsla
|
31
|
+
@hue = SassC::Util.clamp(hue.to_i, 0, 360)
|
32
|
+
@saturation = SassC::Util.clamp(saturation.to_i, 0, 100)
|
33
|
+
@lightness = SassC::Util.clamp(lightness.to_i, 0, 100)
|
34
|
+
@alpha = SassC::Util.clamp(alpha.to_f, 0.0, 1.0)
|
35
|
+
else
|
36
|
+
raise SassC::UnsupportedValue, "Unable to determine color configuration for "
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns a CSS color declaration in the form
|
41
|
+
# `rgb(…)`, `rgba(…)`, `hsl(…)`, or `hsla(…)`.
|
42
|
+
def to_s
|
43
|
+
if rgba? && @alpha == 1.0
|
44
|
+
return "rgb(#{@red}, #{@green}, #{@blue})"
|
45
|
+
elsif rgba?
|
46
|
+
return "rgba(#{@red}, #{@green}, #{@blue}, #{alpha_string})"
|
47
|
+
elsif hsla? && @alpha == 1.0
|
48
|
+
return "hsl(#{@hue}, #{@saturation}%, #{@lightness}%)"
|
49
|
+
else # hsla?
|
50
|
+
return "hsla(#{@hue}, #{@saturation}%, #{@lightness}%, #{alpha_string})"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# True if this color has RGBA values
|
55
|
+
def rgba?
|
56
|
+
@mode == :rgba
|
57
|
+
end
|
58
|
+
|
59
|
+
# True if this color has HSLA values
|
60
|
+
def hlsa?
|
61
|
+
@mode == :hlsa
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns the alpha value of this color as a string
|
65
|
+
# and rounded to 8 decimal places.
|
66
|
+
def alpha_string
|
67
|
+
alpha.round(8).to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
# Returns the values of this color in an array.
|
71
|
+
# Provided for compatibility between different SassC::Script::Value classes
|
72
|
+
def value
|
73
|
+
return [
|
74
|
+
red, green, blue,
|
75
|
+
hue, saturation, lightness,
|
76
|
+
alpha,
|
77
|
+
].compact
|
78
|
+
end
|
79
|
+
|
80
|
+
# True if this Color is equal to `other_color`
|
81
|
+
def eql?(other_color)
|
82
|
+
unless other_color.is_a?(self.class)
|
83
|
+
raise ArgumentError, "No implicit conversion of #{other_color.class} to #{self.class}"
|
84
|
+
end
|
85
|
+
self.value == other_color.value
|
86
|
+
end
|
87
|
+
alias_method :==, :eql?
|
88
|
+
|
89
|
+
# Returns a numeric value for comparing two Color objects
|
90
|
+
# This method is used internally by the Hash class and is not the same as `.to_h`
|
91
|
+
def hash
|
92
|
+
value.hash
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|