Sha256: 6629d9da53cdcf199b285be61950fb16642dd03e833692d267d8998d2823f275

Contents?: true

Size: 1.3 KB

Versions: 8

Compression:

Stored size: 1.3 KB

Contents

module SassC
  module Script
    module ValueConversion
      def self.from_native(native_value, options)
        case value_tag = Native.value_get_tag(native_value)
        when :sass_null
          # no-op
        when :sass_string
          value = Native.string_get_value(native_value)
          type = Native.string_get_type(native_value)
          argument = Script::String.new(value, type)

          argument
        when :sass_color
          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)

          argument = Script::Color.new([red, green, blue, alpha])
          argument.options = options

          argument
        else
          raise UnsupportedValue.new("Sass argument of type #{value_tag} unsupported")
        end
      end

      def self.to_native(value)
        case value_name = value.class.name.split("::").last
        when "String"
          String.new(value).to_native
        when "Color"
          Color.new(value).to_native
        else
          raise UnsupportedValue.new("Sass return type #{value_name} unsupported")
        end
      end
    end
  end
end

require_relative "value_conversion/base"
require_relative "value_conversion/string"
require_relative "value_conversion/color"

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sassc-1.8.2 lib/sassc/script/value_conversion.rb
sassc-1.8.1 lib/sassc/script/value_conversion.rb
sassc-1.8.0 lib/sassc/script/value_conversion.rb
sassc-1.8.0.pre2 lib/sassc/script/value_conversion.rb
sassc-1.8.0.pre1 lib/sassc/script/value_conversion.rb
sassc-1.7.1 lib/sassc/script/value_conversion.rb
sassc-1.7.0 lib/sassc/script/value_conversion.rb
sassc-1.6.0 lib/sassc/script/value_conversion.rb