sassc 1.8.2 → 1.8.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d364a5c0cc8d7b4890657139a0970c0bf39385e
4
- data.tar.gz: 095ebc9195614341559f74e687e59ee951c75dcf
3
+ metadata.gz: 4711ad9a2cb9091ae22ff8fb0c373f767212dbec
4
+ data.tar.gz: 5d51cbb258d5855a729028c1db0ce35871e991cb
5
5
  SHA512:
6
- metadata.gz: 9e97b7a55b207c857d6f2017e7877e6f7df3385e6c366ccc5412ab2fdddf73578ffd6be0279427b6b51df81d886bbd368000a267c8039c9411e7c3c9c7ee4759
7
- data.tar.gz: 40a4b7bcca1a22180400841ce114f5b67c72e8e88e30315dacd265a9c3470994df40695f8d65a23c58074d141c328e7cdaa46f792ae4c49b8b9da392d877b5be
6
+ metadata.gz: ea92abeccd8eda5bd3c7c7dfa7e64bd8bab8182891ff6bb9fcb11f995ab2b6e45c6bb5a0a2260c5eb55131e4ef409bf9754aae6ef50524e2c3f0ea3900bd18a0
7
+ data.tar.gz: 4d3defd176979708077f1f80fb549643e471092097f201f86e0cf702ec23e90407173bafde4abee9d697ee9ba5f42cf33cf17e1b2f9dc0a9a3138d4395540684
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
+ /.rvmrc
3
4
  /Gemfile.lock
4
5
  /_yardoc/
5
6
  /coverage/
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Use `libsass` with Ruby!
4
4
 
5
- This gem combines the speed of `libsass`, the [Sass C implementation](https://github.com/sass/libsass), with the easy of use of the original [Ruby Sass](https://github.com/sass/sass) library.
5
+ This gem combines the speed of `libsass`, the [Sass C implementation](https://github.com/sass/libsass), with the ease of use of the original [Ruby Sass](https://github.com/sass/sass) library.
6
6
 
7
7
  ### libsass Version
8
8
 
@@ -25,6 +25,8 @@ and [awesome contributors](https://github.com/bolandrm/sassc-ruby/graphs/contrib
25
25
 
26
26
  ## Changelog
27
27
 
28
+ - **1.8.3**
29
+ - [Passing empty string into engine does not raise error](https://github.com/sass/sassc-ruby/pull/31)
28
30
  - **1.8.2**
29
31
  - Update to Libsass 3.3.2
30
32
  - **1.8.1**
@@ -17,6 +17,8 @@ module SassC
17
17
  end
18
18
 
19
19
  def render
20
+ return @template.dup if @template.empty?
21
+
20
22
  data_context = Native.make_data_context(@template)
21
23
  context = Native.data_context_get_context(data_context)
22
24
  native_options = Native.context_get_options(context)
@@ -24,7 +24,7 @@ module SassC
24
24
  def import_function
25
25
  @import_function ||= FFI::Function.new(:pointer, [:string, :pointer, :pointer]) do |path, importer_entry, compiler|
26
26
  last_import = Native::compiler_get_last_import(compiler)
27
- parent_path = Native::import_get_imp_path(last_import)
27
+ parent_path = Native::import_get_abs_path(last_import)
28
28
 
29
29
  imports = [*@importer.imports(path, parent_path)]
30
30
  imports_to_native(imports)
@@ -24,6 +24,24 @@ module SassC
24
24
  # ADDAPI union Sass_Value* ADDCALL sass_make_color (double r, double g, double b, double a);
25
25
  attach_function :sass_make_color, [:double, :double, :double, :double], :sass_value_ptr
26
26
 
27
+ # ADDAPI union Sass_Value* ADDCALL sass_make_map (size_t len);
28
+ attach_function :sass_make_map, [:size_t], :sass_value_ptr
29
+
30
+ # ADDAPI void ADDCALL sass_map_set_key (union Sass_Value* v, size_t i, union Sass_Value*);
31
+ attach_function :sass_map_set_key, [:sass_value_ptr, :size_t, :sass_value_ptr], :void
32
+
33
+ # ADDAPI union Sass_Value* ADDCALL sass_map_get_key (const union Sass_Value* v, size_t i);
34
+ attach_function :sass_map_get_key, [:sass_value_ptr, :size_t], :sass_value_ptr
35
+
36
+ # ADDAPI void ADDCALL sass_map_set_value (union Sass_Value* v, size_t i, union Sass_Value*);
37
+ attach_function :sass_map_set_value, [:sass_value_ptr, :size_t, :sass_value_ptr], :void
38
+
39
+ # ADDAPI union Sass_Value* ADDCALL sass_map_get_value (const union Sass_Value* v, size_t i);
40
+ attach_function :sass_map_get_value, [:sass_value_ptr, :size_t], :sass_value_ptr
41
+
42
+ # ADDAPI size_t ADDCALL sass_map_get_length (const union Sass_Value* v);
43
+ attach_function :sass_map_get_length, [:sass_value_ptr], :size_t
44
+
27
45
  # ADDAPI union Sass_Value* ADDCALL sass_make_error (const char* msg);
28
46
  attach_function :sass_make_error, [:string], :sass_value_ptr
29
47
 
@@ -37,6 +55,12 @@ module SassC
37
55
  # ADDAPI bool ADDCALL sass_string_is_quoted(const union Sass_Value* v);
38
56
  attach_function :sass_string_is_quoted, [:sass_value_ptr], :bool
39
57
 
58
+ # ADDAPI const char* ADDCALL sass_number_get_value (const union Sass_Value* v);
59
+ attach_function :sass_number_get_value, [:sass_value_ptr], :double
60
+
61
+ # ADDAPI const char* ADDCALL sass_number_get_unit (const union Sass_Value* v);
62
+ attach_function :sass_number_get_unit, [:sass_value_ptr], :string
63
+
40
64
  def self.string_get_type(native_value)
41
65
  string_is_quoted(native_value) ? :string : :identifier
42
66
  end
@@ -103,6 +127,7 @@ module SassC
103
127
  # ADDAPI const char* ADDCALL sass_import_get_imp_path (struct Sass_Import*);
104
128
  attach_function :sass_import_get_imp_path, [:sass_import_ptr], :string
105
129
  # ADDAPI const char* ADDCALL sass_import_get_abs_path (struct Sass_Import*);
130
+ attach_function :sass_import_get_abs_path, [:sass_import_ptr], :string
106
131
  # ADDAPI const char* ADDCALL sass_import_get_source (struct Sass_Import*);
107
132
  attach_function :sass_import_get_source, [:sass_import_ptr], :string
108
133
  # ADDAPI const char* ADDCALL sass_import_get_srcmap (struct Sass_Import*);
@@ -10,6 +10,12 @@ module SassC
10
10
  type = Native.string_get_type(native_value)
11
11
  argument = Script::String.new(value, type)
12
12
 
13
+ argument
14
+ when :sass_number
15
+ value = Native.number_get_value(native_value)
16
+ unit = Native.number_get_unit(native_value)
17
+ argument = Sass::Script::Value::Number.new(value, unit)
18
+
13
19
  argument
14
20
  when :sass_color
15
21
  red, green, blue, alpha = Native.color_get_r(native_value), Native.color_get_g(native_value), Native.color_get_b(native_value), Native.color_get_a(native_value)
@@ -17,6 +23,18 @@ module SassC
17
23
  argument = Script::Color.new([red, green, blue, alpha])
18
24
  argument.options = options
19
25
 
26
+ argument
27
+ when :sass_map
28
+ values = {}
29
+ length = Native::map_get_length native_value
30
+
31
+ (0..length-1).each do |index|
32
+ key = Native::map_get_key(native_value, index)
33
+ value = Native::map_get_value(native_value, index)
34
+ values[from_native(key, options)] = from_native(value, options)
35
+ end
36
+
37
+ argument = Sass::Script::Value::Map.new values
20
38
  argument
21
39
  else
22
40
  raise UnsupportedValue.new("Sass argument of type #{value_tag} unsupported")
@@ -29,6 +47,10 @@ module SassC
29
47
  String.new(value).to_native
30
48
  when "Color"
31
49
  Color.new(value).to_native
50
+ when "Number"
51
+ Number.new(value).to_native
52
+ when "Map"
53
+ Map.new(value).to_native
32
54
  else
33
55
  raise UnsupportedValue.new("Sass return type #{value_name} unsupported")
34
56
  end
@@ -39,4 +61,6 @@ end
39
61
 
40
62
  require_relative "value_conversion/base"
41
63
  require_relative "value_conversion/string"
64
+ require_relative "value_conversion/number"
42
65
  require_relative "value_conversion/color"
66
+ require_relative "value_conversion/map"
@@ -0,0 +1,19 @@
1
+ module SassC
2
+ module Script
3
+ module ValueConversion
4
+ class Map < Base
5
+ def to_native
6
+ hash = @value.to_h
7
+ native_map = Native::make_map( hash.size )
8
+ hash.each_with_index do |(key, value), index|
9
+ key = ValueConversion.to_native key
10
+ value = ValueConversion.to_native value
11
+ Native::map_set_key( native_map, index, key )
12
+ Native::map_set_value( native_map, index, value )
13
+ end
14
+ return native_map
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ module SassC
2
+ module Script
3
+ module ValueConversion
4
+ class Number < Base
5
+ def to_native
6
+ Native::make_number(@value.value, @value.numerator_units.first)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module SassC
2
- VERSION = "1.8.2"
2
+ VERSION = "1.8.3"
3
3
  end
@@ -189,5 +189,10 @@ CSS
189
189
  assert_match /sourceMappingURL/, output
190
190
  assert_match /.foo/, output
191
191
  end
192
+
193
+ def test_empty_template
194
+ output = Engine.new('').render
195
+ assert_equal '', output
196
+ end
192
197
  end
193
198
  end
@@ -64,6 +64,22 @@ module SassC
64
64
  CSS
65
65
  end
66
66
 
67
+ def test_function_that_returns_a_number
68
+ assert_sass <<-SCSS, <<-CSS
69
+ div { width: returns-a-number(); }
70
+ SCSS
71
+ div { width: -312rem; }
72
+ CSS
73
+ end
74
+
75
+ def test_function_that_takes_a_number
76
+ assert_sass <<-SCSS, <<-CSS
77
+ div { display: inspect-number(42.1px); }
78
+ SCSS
79
+ div { display: 42.1px; }
80
+ CSS
81
+ end
82
+
67
83
  def test_function_with_optional_arguments
68
84
  assert_sass <<-SCSS, <<-EXPECTED_CSS
69
85
  div {
@@ -87,14 +103,14 @@ module SassC
87
103
  end
88
104
 
89
105
  def test_function_with_unsupported_tag
90
- engine = Engine.new("div {url: function_with_unsupported_tag(1);}")
106
+ engine = Engine.new("div {url: function_with_unsupported_tag(());}")
91
107
 
92
108
  exception = assert_raises(SassC::SyntaxError) do
93
109
  engine.render
94
110
  end
95
111
 
96
- assert_match /Sass argument of type sass_number unsupported/, exception.message
97
- assert_equal "[SassC::FunctionsHandler] Sass argument of type sass_number unsupported", stderr_output
112
+ assert_match /Sass argument of type sass_list unsupported/, exception.message
113
+ assert_equal "[SassC::FunctionsHandler] Sass argument of type sass_list unsupported", stderr_output
98
114
  end
99
115
 
100
116
  def test_function_with_error
@@ -117,6 +133,23 @@ module SassC
117
133
  CSS
118
134
  end
119
135
 
136
+ def test_function_that_returns_a_sass_map
137
+ assert_sass <<-SCSS, <<-CSS
138
+ $my-map: returns-sass-map();
139
+ div { background: map-get( $my-map, color ); }
140
+ SCSS
141
+ div { background: black; }
142
+ CSS
143
+ end
144
+
145
+ def test_function_that_takes_a_sass_map
146
+ assert_sass <<-SCSS, <<-CSS
147
+ div { background-color: map-get( inspect-map(( color: black, number: 1.23px, string: "abc", map: ( x: 'y' ))), color ); }
148
+ SCSS
149
+ div { background-color: black; }
150
+ CSS
151
+ end
152
+
120
153
  private
121
154
 
122
155
  def assert_sass(sass, expected_css)
@@ -151,7 +184,7 @@ module SassC
151
184
  raise StandardError, "Intentional wrong thing happened somewhere inside the custom function"
152
185
  end
153
186
 
154
- def function_with_unsupported_tag(number)
187
+ def function_with_unsupported_tag(value)
155
188
  end
156
189
 
157
190
  def nice_color_argument(color)
@@ -162,10 +195,49 @@ module SassC
162
195
  return Script::Color.new(red: 0, green: 0, blue: 0)
163
196
  end
164
197
 
198
+ def returns_a_number
199
+ return Sass::Script::Value::Number.new(-312,'rem')
200
+ end
201
+
202
+ def inspect_number ( argument )
203
+ raise StandardError.new "passed value is not a Sass::Script::Value::Number" unless argument.is_a? Sass::Script::Value::Number
204
+ return argument
205
+ end
206
+
207
+ def inspect_map ( argument )
208
+ argument.to_h.each_pair do |key, value|
209
+ raise StandardError.new "key #{key.inspect} is not a string" unless key.is_a? Sass::Script::Value::String
210
+
211
+ valueClass = case key.value
212
+ when 'string'
213
+ Sass::Script::Value::String
214
+ when 'number'
215
+ Sass::Script::Value::Number
216
+ when 'color'
217
+ Sass::Script::Value::Color
218
+ when 'map'
219
+ Sass::Script::Value::Map
220
+ end
221
+
222
+ raise StandardError.new "unknown key #{key.inspect}" unless valueClass
223
+ raise StandardError.new "value for #{key.inspect} is not a #{valueClass}" unless value.is_a? valueClass
224
+ end
225
+ return argument
226
+ end
227
+
165
228
  def returns_sass_value
166
229
  return Sass::Script::Value::Color.new(red: 0, green: 0, blue: 0)
167
230
  end
168
231
 
232
+ def returns_sass_map
233
+ key = Script::String.new("color", "string")
234
+ value = Sass::Script::Value::Color.new(red: 0, green: 0, blue: 0)
235
+ values = {}
236
+ values[key] = value
237
+ map = Sass::Script::Value::Map.new values
238
+ return map
239
+ end
240
+
169
241
  module Compass
170
242
  def stylesheet_path(path)
171
243
  Script::String.new("/css/#{path.value}", :identifier)
@@ -96,6 +96,10 @@ module SassC
96
96
  assert_equal :sass_string, Native.value_get_tag(string)
97
97
  assert_equal "hello", Native.string_get_value(string)
98
98
 
99
+ number = Native.make_number(123.4, "rem")
100
+ assert_equal 123.4, Native.number_get_value(number)
101
+ assert_equal "rem", Native.number_get_unit(number)
102
+
99
103
  Native.compile_data_context(data_context)
100
104
 
101
105
  css = Native.context_get_output_string(context)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sassc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Boland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-14 00:00:00.000000000 Z
11
+ date: 2016-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -347,6 +347,8 @@ files:
347
347
  - lib/sassc/script/value_conversion.rb
348
348
  - lib/sassc/script/value_conversion/base.rb
349
349
  - lib/sassc/script/value_conversion/color.rb
350
+ - lib/sassc/script/value_conversion/map.rb
351
+ - lib/sassc/script/value_conversion/number.rb
350
352
  - lib/sassc/script/value_conversion/string.rb
351
353
  - lib/sassc/version.rb
352
354
  - lib/tasks/libsass.rb