### Home Classes Methods

### In Files

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

### Methods

- #color_stops
- #color_stops_in_percentages
- #grad_color_stops
- #grad_end_position
- #grad_point
- #grad_position
- #linear_end_position
- #linear_gradient
- #linear_svg_gradient
- #radial_gradient
- #radial_svg_gradient

### Class/Module Index

Quicksearch

- Compass
- Compass::Actions
- Compass::AppIntegration
- Compass::AppIntegration::Helpers
- Compass::AppIntegration::Rails
- Compass::AppIntegration::StandAlone
- Compass::AppIntegration::StandAlone::ConfigurationDefaults
- Compass::AppIntegration::StandAlone::Installer
- Compass::BrowserSupport
- Compass::Commands
- Compass::Commands::Base
- Compass::Commands::CleanProject
- Compass::Commands::CleanProjectOptionsParser
- Compass::Commands::CompileProjectOptionsParser
- Compass::Commands::ConfigurationOptionsParser
- Compass::Commands::CreateProject
- Compass::Commands::CreateProjectOptionsParser
- Compass::Commands::Default
- Compass::Commands::DefaultOptionsParser
- Compass::Commands::ExtensionCommand
- Compass::Commands::ExtensionOptionsParser
- Compass::Commands::ExtensionsOptionParser
- Compass::Commands::GenerateGridBackground
- Compass::Commands::GridBackgroundOptionsParser
- Compass::Commands::Help
- Compass::Commands::HelpOptionsParser
- Compass::Commands::Imports
- Compass::Commands::InstallerCommand
- Compass::Commands::Interactive
- Compass::Commands::InteractiveOptionsParser
- Compass::Commands::ListFrameworks
- Compass::Commands::MemoryDebugger
- Compass::Commands::PrintVersion
- Compass::Commands::ProjectBase
- Compass::Commands::ProjectStats
- Compass::Commands::Registry
- Compass::Commands::Sprite
- Compass::Commands::SpriteOptionsParser
- Compass::Commands::StampPattern
- Compass::Commands::StampPatternOptionsParser
- Compass::Commands::StatsOptionsParser
- Compass::Commands::StructureOptionsParser
- Compass::Commands::UnpackExtension
- Compass::Commands::UpdateProject
- Compass::Commands::ValidateProject
- Compass::Commands::ValidationOptionsParser
- Compass::Commands::VersionOptionsParser
- Compass::Commands::WatchProject
- Compass::Commands::WatchProjectOptionsParser
- Compass::Commands::WriteConfiguration
- Compass::Compiler
- Compass::Configuration
- Compass::Configuration::Adapters
- Compass::Configuration::Comments
- Compass::Configuration::Data
- Compass::Configuration::Defaults
- Compass::Configuration::FileData
- Compass::Configuration::Helpers
- Compass::Configuration::Inheritance
- Compass::Configuration::Inheritance::ClassMethods
- Compass::Configuration::Inheritance::ClassMethods::ArrayProxy
- Compass::Configuration::Inheritance::InstanceMethods
- Compass::Configuration::Paths
- Compass::Configuration::Serialization
- Compass::Error
- Compass::Exec
- Compass::Exec::CommandOptionParser
- Compass::Exec::GlobalOptionsParser
- Compass::Exec::Helpers
- Compass::Exec::ProjectOptionsParser
- Compass::Exec::SubCommandUI
- Compass::Exec::SwitchUI
- Compass::FilesystemConflict
- Compass::Frameworks
- Compass::Frameworks::Framework
- Compass::GridBuilder
- Compass::Installers
- Compass::Installers::BareInstaller
- Compass::Installers::Base
- Compass::Installers::Manifest
- Compass::Installers::Manifest::Entry
- Compass::Installers::ManifestInstaller
- Compass::Installers::TemplateContext
- Compass::Logger
- Compass::MissingDependency
- Compass::NullLogger
- Compass::PNG
- Compass::SassExtensions
- Compass::SassExtensions::Functions
- Compass::SassExtensions::Functions::Colors
- Compass::SassExtensions::Functions::Constants
- Compass::SassExtensions::Functions::CrossBrowserSupport
- Compass::SassExtensions::Functions::CrossBrowserSupport::CSS2FallbackValue
- Compass::SassExtensions::Functions::Display
- Compass::SassExtensions::Functions::Enumerate
- Compass::SassExtensions::Functions::Env
- Compass::SassExtensions::Functions::FontFiles
- Compass::SassExtensions::Functions::GradientSupport
- Compass::SassExtensions::Functions::GradientSupport::Assertions
- Compass::SassExtensions::Functions::GradientSupport::ColorStop
- Compass::SassExtensions::Functions::GradientSupport::Functions
- Compass::SassExtensions::Functions::GradientSupport::Gradient
- Compass::SassExtensions::Functions::GradientSupport::Gradient::ClassMethods
- Compass::SassExtensions::Functions::GradientSupport::LinearGradient
- Compass::SassExtensions::Functions::GradientSupport::RadialGradient
- Compass::SassExtensions::Functions::ImageSize
- Compass::SassExtensions::Functions::ImageSize::ImageProperties
- Compass::SassExtensions::Functions::ImageSize::JPEG
- Compass::SassExtensions::Functions::InlineImage
- Compass::SassExtensions::Functions::Lists
- Compass::SassExtensions::Functions::Math
- Compass::SassExtensions::Functions::Selectors
- Compass::SassExtensions::Functions::Sprites
- Compass::SassExtensions::Functions::Sprites::VariableReader
- Compass::SassExtensions::Functions::Urls
- Compass::SassExtensions::Functions::Urls::FontUrl
- Compass::SassExtensions::Functions::Urls::GeneratedImageUrl
- Compass::SassExtensions::Functions::Urls::ImageUrl
- Compass::SassExtensions::Functions::Urls::StylesheetUrl
- Compass::SassExtensions::Sprites
- Compass::SassExtensions::Sprites::ChunkyPngEngine
- Compass::SassExtensions::Sprites::Engine
- Compass::SassExtensions::Sprites::Image
- Compass::SassExtensions::Sprites::ImageMethods
- Compass::SassExtensions::Sprites::ImageRow
- Compass::SassExtensions::Sprites::LayoutMethods
- Compass::SassExtensions::Sprites::RowFitter
- Compass::SassExtensions::Sprites::SpriteMap
- Compass::SassExtensions::Sprites::SpriteMethods
- Compass::SpriteException
- Compass::SpriteImporter
- Compass::Sprites
- Compass::Sprites::Binding
- Compass::Stats
- Compass::Stats::CssFile
- Compass::Stats::SassFile
- Compass::Stats::StatsVisitor
- Compass::TestCase
- Compass::Util
- Compass::Version
- Sass
- Sass::Script
- Sass::Script::CrossBrowserFunctionCall
- Sass::Script::Funcall
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::HasSimpleCrossBrowserFunctionSupport
- Sass::Script::List
- Sass::Tree
- Sass::Tree::Node
- QuickCache

No matching classes.

# Compass::SassExtensions::Functions::GradientSupport::Functions

### Public Instance Methods

color_stops(*args) click to toggle source

    # File lib/compass/sass_extensions/functions/gradient_support.rb, line 245
    def color_stops(*args)
      Sass::Script::List.new(args.map do |arg|
        if ColorStop === arg
          arg
        elsif Sass::Script::Color === arg
          ColorStop.new(arg)
        elsif Sass::Script::List === arg
          ColorStop.new(*arg.value)
        elsif Sass::Script::String === arg && arg.value == "transparent"
          ColorStop.new(arg)
        else
          raise Sass::SyntaxError, "Not a valid color stop: #{arg.class.name}: #{arg}"
        end
      end, :comma)
    end

color_stops_in_percentages(color_list) click to toggle source

    # File lib/compass/sass_extensions/functions/gradient_support.rb, line 314
    def color_stops_in_percentages(color_list)
      assert_type color_list, :List
      color_list = normalize_stops(color_list)
      max = color_list.value.last.stop
      last_value = nil
      color_stops = color_list.value.map do |pos|
        # have to convert absolute units to percentages for use in color stop functions.
        stop = pos.stop
        stop = stop.div(max).times(Sass::Script::Number.new(100,["%"])) if stop.numerator_units == max.numerator_units && max.numerator_units != ["%"]
        # Make sure the color stops are specified in the right order.
        if last_value && stop.numerator_units == last_value.numerator_units && stop.denominator_units == last_value.denominator_units && (stop.value * 1000).round < (last_value.value * 1000).round
          raise Sass::SyntaxError.new("Color stops must be specified in increasing order. #{stop.value} came after #{last_value.value}.")
        end
        last_value = stop
        [stop, pos.color]
      end
    end

grad_color_stops(color_list) click to toggle source

returns color-stop() calls for use in webkit.

    # File lib/compass/sass_extensions/functions/gradient_support.rb, line 307
    def grad_color_stops(color_list)
      stops = color_stops_in_percentages(color_list).map do |stop, color|
        "color-stop(#{stop.inspect}, #{ColorStop.color_to_s(color)})"
      end
      Sass::Script::String.new(stops.join(", "))
    end

grad_end_position(color_list, radial = Sass::Script::Bool.new(false)) click to toggle source

returns the end position of the gradient from the color stop

    # File lib/compass/sass_extensions/functions/gradient_support.rb, line 352
    def grad_end_position(color_list, radial = Sass::Script::Bool.new(false))
      assert_type color_list, :List
      default = Sass::Script::Number.new(100)
      grad_position(color_list, Sass::Script::Number.new(color_list.value.size), default, radial)
    end

grad_point(position) click to toggle source

given a position list, return a corresponding position in percents otherwise, returns the original argument

    # File lib/compass/sass_extensions/functions/gradient_support.rb, line 208
    def grad_point(position)
      original_value = position
      position = unless position.is_a?(Sass::Script::List)
        Sass::Script::List.new([position], :space)
      else
        Sass::Script::List.new(position.value.dup, position.separator)
      end
      # Handle unknown arguments by passing them along untouched.
      unless position.value.all?{|p| is_position(p).to_bool }
        return original_value
      end
      if (position.value.first.value =~ /top|bottom/) or (position.value.last.value =~ /left|right/)
        # browsers are pretty forgiving of reversed positions so we are too.
        position.value.reverse!
      end
      if position.value.size == 1
        if position.value.first.value =~ /top|bottom/
          position.value.unshift Sass::Script::String.new("center")
        elsif position.value.first.value =~ /left|right/
          position.value.push Sass::Script::String.new("center")
        end
      end
      position.value.map! do |p|
        case p.value
        when /top|left/
          Sass::Script::Number.new(0, ["%"])
        when /bottom|right/
          Sass::Script::Number.new(100, ["%"])
        when /center/
          Sass::Script::Number.new(50, ["%"])
        else
          p
        end
      end
      position
    end

grad_position(color_list, index, default, radial = Sass::Script::Bool.new(false)) click to toggle source

    # File lib/compass/sass_extensions/functions/gradient_support.rb, line 358
    def grad_position(color_list, index, default, radial = Sass::Script::Bool.new(false))
      assert_type color_list, :List
      stop = color_list.value[index.value - 1].stop
      if stop && radial.to_bool
        orig_stop = stop
        if stop.unitless?
          if stop.value <= 1
            # A unitless number is assumed to be a percentage when it's between 0 and 1
            stop = stop.times(Sass::Script::Number.new(100, ["%"]))
          else
            # Otherwise, a unitless number is assumed to be in pixels
            stop = stop.times(Sass::Script::Number.new(1, ["px"]))
          end
        end
        if stop.numerator_units == ["%"] && color_list.value.last.stop && color_list.value.last.stop.numerator_units == ["px"]
          stop = stop.times(color_list.value.last.stop).div(Sass::Script::Number.new(100, ["%"]))
        end
        Compass::Logger.new.record(:warning, "Webkit only supports pixels for the start and end stops for radial gradients. Got: #{orig_stop}") if stop.numerator_units != ["px"]
        stop.div(Sass::Script::Number.new(1, stop.numerator_units, stop.denominator_units))
      elsif stop
        stop
      else
        default
      end
    end

linear_end_position(position_or_angle, color_list) click to toggle source

only used for webkit

    # File lib/compass/sass_extensions/functions/gradient_support.rb, line 333
    def linear_end_position(position_or_angle, color_list)
      start_point = grad_point(position_or_angle || Sass::Script::String.new("top"))
      end_point = grad_point(opposite_position(position_or_angle || Sass::Script::String.new("top")))
      end_target = color_list.value.last.stop

      if color_list.value.last.stop && color_list.value.last.stop.numerator_units == ["px"]
        new_end = color_list.value.last.stop.value
        if start_point.value.first == end_point.value.first && start_point.value.last.value == 0
          # this means top-to-bottom
          end_point.value[1] = Sass::Script::Number.new(end_target.value)
        elsif start_point.value.last == end_point.value.last && start_point.value.first.value == 0
          # this implies left-to-right
          end_point.value[0] = Sass::Script::Number.new(end_target.value)
        end
      end
      end_point
    end

linear_gradient(position_or_angle, *color_stops) click to toggle source

    # File lib/compass/sass_extensions/functions/gradient_support.rb, line 289
    def linear_gradient(position_or_angle, *color_stops)
      if color_stop?(position_or_angle)
        color_stops.unshift(position_or_angle)
        position_or_angle = nil
      elsif list_of_color_stops?(position_or_angle)
        color_stops = position_or_angle.value + color_stops
        position_or_angle = nil
      end
      position_or_angle = nil if position_or_angle && !position_or_angle.to_bool

      # Support legacy use of the color-stops() function
      if color_stops.size == 1 && (stops = list_of_color_stops?(color_stops.first))
        color_stops = stops
      end
      LinearGradient.new(position_or_angle, send(:color_stops, *color_stops))
    end

linear_svg_gradient(color_stops, start) click to toggle source

    # File lib/compass/sass_extensions/functions/gradient_support.rb, line 384
    def linear_svg_gradient(color_stops, start)
      x1, y1 = *grad_point(start).value
      x2, y2 = *grad_point(opposite_position(start)).value
      stops = color_stops_in_percentages(color_stops)

      svg = linear_svg(stops, x1, y1, x2, y2)
      inline_image_string(svg.gsub(/\s+/, ' '), 'image/svg+xml')
    end

radial_gradient(position_or_angle, shape_and_size, *color_stops) click to toggle source

    # File lib/compass/sass_extensions/functions/gradient_support.rb, line 261
    def radial_gradient(position_or_angle, shape_and_size, *color_stops)
      # Have to deal with variable length/meaning arguments.
      if color_stop?(shape_and_size)
        color_stops.unshift(shape_and_size)
        shape_and_size = nil
      elsif list_of_color_stops?(shape_and_size)
        # Support legacy use of the color-stops() function
        color_stops = shape_and_size.value + color_stops
        shape_and_size = nil
      end
      shape_and_size = nil if shape_and_size && !shape_and_size.to_bool # nil out explictly passed falses
      # ditto for position_or_angle
      if color_stop?(position_or_angle)
        color_stops.unshift(position_or_angle)
        position_or_angle = nil
      elsif list_of_color_stops?(position_or_angle)
        color_stops = position_or_angle.value + color_stops
        position_or_angle = nil
      end
      position_or_angle = nil if position_or_angle && !position_or_angle.to_bool

      # Support legacy use of the color-stops() function
      if color_stops.size == 1 && list_of_color_stops?(color_stops.first)
        color_stops = color_stops.first.value
      end
      RadialGradient.new(position_or_angle, shape_and_size, send(:color_stops, *color_stops))
    end

radial_svg_gradient(color_stops, center) click to toggle source

    # File lib/compass/sass_extensions/functions/gradient_support.rb, line 393
    def radial_svg_gradient(color_stops, center)
      cx, cy = *grad_point(center).value
      r = grad_end_position(color_stops,  Sass::Script::Bool.new(true))
      stops = color_stops_in_percentages(color_stops)

      svg = radial_svg(stops, cx, cy, r)
      inline_image_string(svg.gsub(/\s+/, ' '), 'image/svg+xml')
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.