Class: Compass::Core::SassExtensions::Functions::GradientSupport::LinearGradient
- Inherits:
-
Sass::Script::Value::Base
- Object
- Sass::Script::Value::Base
- Compass::Core::SassExtensions::Functions::GradientSupport::LinearGradient
- 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 inherited from Sass::Script::Value::Base
Sass::Script::Value::Base::NO_CHILDREN
Instance Attribute Summary collapse
-
#color_stops ⇒ Object
Returns the value of attribute color_stops.
-
#legacy ⇒ Object
Returns the value of attribute legacy.
-
#position_or_angle ⇒ Object
Returns the value of attribute position_or_angle.
Instance Method Summary collapse
- #children ⇒ Object
- #convert_to_or_from_legacy(position_or_angle, options = self.options) ⇒ Object
-
#initialize(position_or_angle, color_stops, legacy = false) ⇒ LinearGradient
constructor
A new instance of LinearGradient.
- #supports?(aspect) ⇒ Boolean
- #to_css2(options = self.options) ⇒ Object
-
#to_owg(options = self.options) ⇒ Object
Output the original webkit gradient syntax.
- #to_s(options = self.options) ⇒ Object
- #to_s_prefixed(options = self.options) ⇒ Object
- #to_svg(options = self.options) ⇒ Object
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
Methods included from Gradient
#angle?, #has_aspect?, included, #inspect, #is_position
Methods inherited from Sass::Script::Value::Base
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_stops ⇒ Object
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 |
#legacy ⇒ Object
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_angle ⇒ Object
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
#children ⇒ Object
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, = self.) 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() end |
#supports?(aspect) ⇒ 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( = self.) 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( = self.) 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. = } 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( = self.) s = 'linear-gradient(' if legacy s << convert_to_or_from_legacy(position_or_angle, ) << ", " if position_or_angle else s << position_or_angle.to_s() << ", " if position_or_angle end s << color_stops.to_s() 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( = self.) s = "linear-gradient(" if legacy s << position_or_angle.to_s() << ", " if position_or_angle else s << convert_to_or_from_legacy(position_or_angle, ) << ", " if position_or_angle end s << color_stops.to_s() 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( = self.) linear_svg_gradient(color_stops, position_or_angle || identifier("top")) end |