Class: Compass::Core::SassExtensions::Functions::GradientSupport::ColorStop

### Home Classes Methods

### In Files

- lib/compass/core/sass_extensions/functions/gradient_support.rb

### Parent

Sass::Script::Value::Base

### Methods

- ::color_to_s
- ::color_to_svg_alpha
- ::color_to_svg_s
- ::new
- #assert_legal_color!
- #assert_legal_color_stop!
- #children
- #inspect
- #to_s
- #to_sass

### Included Modules

- Sass::Script::Value::Helpers

### Class/Module Index

Quicksearch

- Compass
- Compass::BrowserSupport
- Compass::Configuration
- Compass::Configuration::Adapters
- Compass::Configuration::Data
- Compass::Configuration::Defaults
- Compass::Configuration::Inheritance
- Compass::Configuration::Inheritance::ClassMethods
- Compass::Configuration::Inheritance::ClassMethods::ArrayProxy
- Compass::Configuration::Inheritance::InstanceMethods
- Compass::Configuration::Paths
- Compass::Configuration::Watch
- Compass::Core
- Compass::Core::CanIUse
- Compass::Core::SassExtensions
- Compass::Core::SassExtensions::Functions
- Compass::Core::SassExtensions::Functions::Colors
- Compass::Core::SassExtensions::Functions::Configuration
- Compass::Core::SassExtensions::Functions::Constants
- Compass::Core::SassExtensions::Functions::CrossBrowserSupport
- Compass::Core::SassExtensions::Functions::CrossBrowserSupport::CSS2FallbackValue
- Compass::Core::SassExtensions::Functions::Display
- Compass::Core::SassExtensions::Functions::Enumerate
- Compass::Core::SassExtensions::Functions::Env
- Compass::Core::SassExtensions::Functions::Files
- Compass::Core::SassExtensions::Functions::FontFiles
- Compass::Core::SassExtensions::Functions::GradientSupport
- Compass::Core::SassExtensions::Functions::GradientSupport::Assertions
- Compass::Core::SassExtensions::Functions::GradientSupport::CSS3AngleToSVGConverter
- Compass::Core::SassExtensions::Functions::GradientSupport::ColorStop
- Compass::Core::SassExtensions::Functions::GradientSupport::Functions
- Compass::Core::SassExtensions::Functions::GradientSupport::Gradient
- Compass::Core::SassExtensions::Functions::GradientSupport::Gradient::ClassMethods
- Compass::Core::SassExtensions::Functions::GradientSupport::LinearGradient
- Compass::Core::SassExtensions::Functions::GradientSupport::RadialGradient
- Compass::Core::SassExtensions::Functions::ImageSize
- Compass::Core::SassExtensions::Functions::ImageSize::ImageProperties
- Compass::Core::SassExtensions::Functions::ImageSize::JPEG
- Compass::Core::SassExtensions::Functions::InlineImage
- Compass::Core::SassExtensions::Functions::Lists
- Compass::Core::SassExtensions::Functions::Math
- Compass::Core::SassExtensions::Functions::SassDeclarationHelper
- Compass::Core::SassExtensions::Functions::Selectors
- Compass::Core::SassExtensions::Functions::Urls
- Compass::Core::SassExtensions::Functions::Urls::FontUrl
- Compass::Core::SassExtensions::Functions::Urls::GeneratedImageUrl
- Compass::Core::SassExtensions::Functions::Urls::ImageUrl
- Compass::Core::SassExtensions::Functions::Urls::StylesheetUrl
- Compass::Error
- Compass::Frameworks
- Compass::Frameworks::Framework
- Compass::HasDeprecatedConstantsFromCore
- Compass::SassExtensions
- Compass::SassExtensions::Functions
- Compass::Util
- Sass
- Sass::Script
- Sass::Script::CrossBrowserFunctionCall
- Sass::Script::Funcall
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::HasSimpleCrossBrowserFunctionSupport
- Sass::Script::List
- Sass::Script::Value
- Sass::Script::Value::ArgList
- Sass::Script::Value::Base
- Sass::Script::Value::List
- Sass::Script::Value::Map
- Sass::Tree
- Sass::Tree::Node

No matching classes.

# Compass::Core::SassExtensions::Functions::GradientSupport::ColorStop

### Attributes

color[RW]
stop[RW]

### Public Class Methods

color_to_s(c) click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 203
    def self.color_to_s(c)
      if c.is_a?(Sass::Script::Value::String)
        c.value.dup
      else
        c.inspect.dup
      end
    end

color_to_svg_alpha(c) click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 191
    def self.color_to_svg_alpha(c)
      # svg doesn't support the "transparent" keyword; we need to manually
      # refactor it into "transparent black"
      if c.is_a?(Sass::Script::Value::String) && c.value == "transparent"
        0
      elsif c.is_a?(Sass::Script::Value::String) && c.value == "currentColor"
        1
      else
        c.alpha
      end
    end

color_to_svg_s(c) click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 179
    def self.color_to_svg_s(c)
      # svg doesn't support the "transparent" keyword; we need to manually
      # refactor it into "transparent black"
      if c.is_a?(Sass::Script::Value::String) && c.value == "transparent"
        "black"
      elsif c.is_a?(Sass::Script::Value::String)
        c.value.dup
      else
        self.color_to_s(c.with(:alpha => 1))
      end
    end

new(color, stop = nil) click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 152
    def initialize(color, stop = nil)
      assert_legal_color! color
      assert_legal_color_stop! stop if stop
      self.color, self.stop = color, stop
    end

### Public Instance Methods

assert_legal_color!(color) click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 161
    def assert_legal_color!(color)
      unless Sass::Script::Value::Color === color ||
             Sass::Script::Tree::Funcall === color ||
             (Sass::Script::Value::String === color && color.value == "currentColor")||
             (Sass::Script::Value::String === color && color.value == "transparent")
        raise Sass::SyntaxError, "Expected a color. Got: #{color}"
      end
    end

assert_legal_color_stop!(stop) click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 169
    def assert_legal_color_stop!(stop)
      case stop
      when Sass::Script::Value::String
        return stop.value.start_with?("calc(")
      when Sass::Script::Value::Number
        return true
      end
      raise Sass::SyntaxError, "Expected a number or numerical expression. Got: #{stop.inspect}"
    end

children() click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 149
    def children
      [color, stop].compact
    end

inspect() click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 157
    def inspect
      to_s
    end

to_s(options = self.options) click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 211
    def to_s(options = self.options)
      s = self.class.color_to_s(color)
      if stop
        s << " "
        if stop.respond_to?(:unitless?) && stop.unitless?
          s << stop.times(number(100, "%")).inspect
        else
          s << stop.to_s
        end
      end
      s
    end

to_sass(options = nil) click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 224
    def to_sass(options = nil)
      identifier("color-stop(#{color.to_sass rescue nil}, #{stop.to_sass rescue nil})")
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.