From d228da902de3b5b6e24c2677144e14ca59fbdabe 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 f13661fc..17b0e2d2 100644 --- a/lib/sassc/native/native_functions_api.rb +++ b/lib/sassc/native/native_functions_api.rb @@ -21,6 +21,9 @@ module Native # ADDAPI union Sass_Value* ADDCALL sass_make_qstring (const char* val); attach_function :sass_make_qstring, [: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 85791ed2..33b9e9e4 100644 --- a/test/functions_test.rb +++ b/test/functions_test.rb @@ -56,6 +56,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(<<-SCSS) div { @@ -139,6 +151,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)