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

Inherits:
Sass::Script::Value::Base show all
Includes:
Constants, Assertions, Functions, Gradient, InlineImage
Defined in:
lib/compass/core/sass_extensions/functions/gradient_support.rb,
lib/compass/core/sass_extensions/functions/gradient_support.rb

Constant Summary

Constants included from Constants

Constants::POSITIONS

Constants inherited from Sass::Script::Value::Base

Sass::Script::Value::Base::NO_CHILDREN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from InlineImage

#inline_font_files, #inline_image

Methods included from Constants

#is_position, #is_position_list, #is_url, #opposite_position

Methods included from Functions

#_build_linear_gradient, #_linear_gradient, #_linear_gradient_legacy, #color_stops_in_percentages, #convert_angle_from_offical, #grad_color_stops, #grad_end_position, #grad_point, #grad_position, #linear_end_position, #linear_svg_gradient, #radial_gradient, #radial_svg_gradient, #reverse_side_or_corner

Methods included from Assertions

#assert_type

Methods included from Gradient

#angle?, #has_aspect?, included, #inspect, #is_position

Methods inherited from Sass::Script::Value::Base

#opts

Constructor Details

#initialize(position_or_angle, color_stops, legacy = false) ⇒ LinearGradient

Returns a new instance of LinearGradient.



382
383
384
385
386
387
388
389
# 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

Instance Attribute Details

#color_stopsObject

Returns the value of attribute color_stops.



376
377
378
# File 'lib/compass/core/sass_extensions/functions/gradient_support.rb', line 376

def color_stops
  @color_stops
end

#legacyObject

Returns the value of attribute legacy.



376
377
378
# File 'lib/compass/core/sass_extensions/functions/gradient_support.rb', line 376

def legacy
  @legacy
end

#position_or_angleObject

Returns the value of attribute position_or_angle.



376
377
378
# File 'lib/compass/core/sass_extensions/functions/gradient_support.rb', line 376

def position_or_angle
  @position_or_angle
end

Instance Method Details

#childrenObject



378
379
380
# 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) ⇒ Object



402
403
404
405
406
407
408
409
# 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) ⇒ Boolean

Returns:

  • (Boolean)


426
427
428
429
430
431
432
433
434
435
436
# 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) ⇒ Object



455
456
457
# 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) ⇒ Object

Output the original webkit gradient syntax



439
440
441
442
443
444
445
446
447
448
449
# 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) ⇒ Object



411
412
413
414
415
416
417
418
419
420
# 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) ⇒ Object



391
392
393
394
395
396
397
398
399
400
# 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) ⇒ Object



451
452
453
# 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