class 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 %w(owg).include?(aspect) && position_or_angle.is_a?(Sass::Script::Value::Number) && position_or_angle.numerator_units.include?("deg")
    false
  elsif %w(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