Class: Compass::SassExtensions::Functions::GradientSupport::ColorStop

Inherits:
Sass::Script::Literal
  • Object
show all
Defined in:
lib/compass/sass_extensions/functions/gradient_support.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color, stop = nil) ⇒ ColorStop

Returns a new instance of ColorStop.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 10

def initialize(color, stop = nil)
  unless Sass::Script::Color === color ||
         Sass::Script::Funcall === color ||
         (Sass::Script::String === color && color.value == "transparent")
    raise Sass::SyntaxError, "Expected a color. Got: #{color}"
  end
  if stop && !stop.is_a?(Sass::Script::Number)
    raise Sass::SyntaxError, "Expected a number. Got: #{stop}"
  end
  self.color, self.stop = color, stop
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



6
7
8
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 6

def color
  @color
end

#stopObject

Returns the value of attribute stop.



6
7
8
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 6

def stop
  @stop
end

Class Method Details

.color_to_s(c) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 24

def self.color_to_s(c)
  if c.is_a?(Sass::Script::String)
    c.value.dup
  else
    c.inspect.dup
  end
end

Instance Method Details

#childrenObject



7
8
9
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 7

def children
  [color, stop].compact
end

#inspectObject



21
22
23
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 21

def inspect
  to_s
end

#to_s(options = self.options) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 32

def to_s(options = self.options)
  s = self.class.color_to_s(color)
  if stop
    s << " "
    if stop.unitless?
      s << stop.times(Sass::Script::Number.new(100, ["%"])).inspect
    else
      s << stop.inspect
    end
  end
  s
end