Skip to content

Commit

Permalink
Add support for Sass Color types
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Ocampo-Gooding committed Jul 13, 2015
1 parent 4264d24 commit 901d275
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/sassc/native/native_functions_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/sassc/script/color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/functions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 901d275

Please sign in to comment.