Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for returning Sass Color types #14

Merged
merged 1 commit into from
Jul 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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 union Sass_Value* ADDCALL sass_make_error (const char* msg);
attach_function :sass_make_error, [:string], :sass_value_ptr

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 @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down