Class: Compass::Core::SassExtensions::Functions::GradientSupport::LinearGradient

### Home Classes Methods

### In Files

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

### Parent

Sass::Script::Value::Base

### Methods

- ::new
- #children
- #convert_to_or_from_legacy
- #supports?
- #to_css2
- #to_owg
- #to_s
- #to_s_prefixed
- #to_svg

### Included Modules

- Compass::Core::SassExtensions::Functions::GradientSupport::Gradient
- Compass::Core::SassExtensions::Functions::GradientSupport::Assertions
- Compass::Core::SassExtensions::Functions::GradientSupport::Functions
- Compass::Core::SassExtensions::Functions::Constants
- Compass::Core::SassExtensions::Functions::InlineImage

### 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::LinearGradient

### Attributes

color_stops[RW]
legacy[RW]
position_or_angle[RW]

### Public Class Methods

new(position_or_angle, color_stops, legacy=false) click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 382
    def initialize(position_or_angle, color_stops, legacy=false)
      unless color_stops.value.size >= 2
        raise Sass::SyntaxError, "At least two color stops are required for a linear-gradient"
      end
      self.position_or_angle = position_or_angle
      self.color_stops = color_stops
      self.legacy = legacy
    end

### Public Instance Methods

children() click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 378
    def children
      [color_stops, position_or_angle].compact
    end

convert_to_or_from_legacy(position_or_angle, options = self.options) click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 402
    def convert_to_or_from_legacy(position_or_angle, options = self.options)
      input = if position_or_angle.is_a?(Sass::Script::Value::Number)
          position_or_angle
        else
          opts(list(position_or_angle.to_s.split(' ').map {|s| identifier(s) }, :space))
        end
      return convert_angle_from_offical(input).to_s(options)
    end

supports?(aspect) click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 426
    def supports?(aspect)
      # I don't know how to support degree-based gradients in old webkit gradients (owg) or svg so we just disable them.
      if %(owg).include?(aspect) && position_or_angle.is_a?(Sass::Script::Value::Number) && position_or_angle.numerator_units.include?("deg")
        false
      elsif %(owg svg).include?(aspect) && color_stops.value.any?{|cs| cs.stop.is_a?(Sass::Script::Value::String) }
        # calc expressions cannot be represented in svg or owg
        false
      else
        super
      end
    end

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

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 455
    def to_css2(options = self.options)
      null
    end

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

Output the original webkit gradient syntax

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 439
    def to_owg(options = self.options)
      position_list = reverse_side_or_corner(position_or_angle)

      start_point = grad_point(position_list)
      args = []
      args << start_point
      args << linear_end_position(position_list, start_point, color_stops.value.last.stop)
      args << grad_color_stops(color_stops)
      args.each{|a| a.options = options}
      Sass::Script::String.new("-webkit-gradient(linear, #{args.join(', ')})")
    end

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

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 411
    def to_s(options = self.options)
      s = 'linear-gradient('
      if legacy
        s << convert_to_or_from_legacy(position_or_angle, options) << ", " if position_or_angle
      else
        s << position_or_angle.to_s(options) << ", " if position_or_angle
      end
      s << color_stops.to_s(options)
      s << ")"
    end

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

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 391
    def to_s_prefixed(options = self.options)
      s = "linear-gradient("
      if legacy
        s << position_or_angle.to_s(options) << ", " if position_or_angle
      else
        s << convert_to_or_from_legacy(position_or_angle, options) << ", " if position_or_angle
      end
      s << color_stops.to_s(options)
      s << ")"
    end

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

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 451
    def to_svg(options = self.options)
      linear_svg_gradient(color_stops, position_or_angle || identifier("top"))
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.