From 901d275fd45878207ee12490456f47516496de7d Mon Sep 17 00:00:00 2001 From: Edward Ocampo-Gooding Date: Mon, 13 Jul 2015 18:06:48 +0000 Subject: [PATCH] Add support for Sass Color types --- lib/sassc/native/native_functions_api.rb | 3 +++ lib/sassc/script/color.rb | 2 +- test/functions_test.rb | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/sassc/native/native_functions_api.rb b/lib/sassc/native/native_functions_api.rb index d71f7c5a..d9c025af 100644 --- a/lib/sassc/native/native_functions_api.rb +++ b/lib/sassc/native/native_functions_api.rb @@ -17,6 +17,9 @@ module Native attach_function :sass_make_string, [:string], :sass_value_ptr + # ADDAPI union Sass_Value* ADDCALL sass_make_color (double r, double g, double b, double a); + attach_function :sass_make_color, [:double, :double, :double, :double], :sass_value_ptr + # ADDAPI enum Sass_Tag ADDCALL sass_value_get_tag (const union Sass_Value* v); attach_function :sass_value_get_tag, [:sass_value_ptr], SassTag attach_function :sass_value_is_null, [:sass_value_ptr], :bool diff --git a/lib/sassc/script/color.rb b/lib/sassc/script/color.rb index e74538a8..c654233e 100644 --- a/lib/sassc/script/color.rb +++ b/lib/sassc/script/color.rb @@ -4,7 +4,7 @@ module SassC module Script class Color < ::Sass::Script::Value::Color def to_native - Native::make_string(to_s) + Native::make_color(red, green, blue, alpha) end end end diff --git a/test/functions_test.rb b/test/functions_test.rb index c08ae032..03aff47d 100644 --- a/test/functions_test.rb +++ b/test/functions_test.rb @@ -53,6 +53,18 @@ def test_function_with_no_return_value EOS end + def test_function_that_returns_a_color + engine = Engine.new(<<-SCSS) +div { + background: returns-a-color(); } + SCSS + + assert_equal <<-EXPECTED_SCSS, engine.render +div { + background: black; } + EXPECTED_SCSS + end + def test_function_with_optional_arguments engine = Engine.new("div {url: optional_arguments('first'); url: optional_arguments('second', 'qux')}") assert_equal <<-EOS, engine.render @@ -137,6 +149,10 @@ def nice_color_argument(color) return Script::String.new(color.to_s, :string) end + def returns_a_color() + return Script::Color.new(red: 0, green: 0, blue: 0) + end + module Compass def stylesheet_path(path) Script::String.new("/css/#{path.value}", :identifier)