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

Inherits:
Sass::Script::Literal
  • Object
show all
Includes:
Constants, Assertions, Functions, Gradient, InlineImage
Defined in:
lib/compass/sass_extensions/functions/gradient_support.rb,
lib/compass/sass_extensions/functions/gradient_support.rb

Constant Summary

Constants included from Constants

Constants::POSITIONS

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

#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

Methods included from Assertions

#assert_type

Methods included from Gradient

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

Constructor Details

#initialize(position_or_angle, color_stops) ⇒ LinearGradient

Returns a new instance of LinearGradient.



152
153
154
155
156
157
158
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 152

def initialize(position_or_angle, color_stops)
  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
end

Instance Attribute Details

#color_stopsObject

Returns the value of attribute color_stops.



146
147
148
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 146

def color_stops
  @color_stops
end

#position_or_angleObject

Returns the value of attribute position_or_angle.



146
147
148
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 146

def position_or_angle
  @position_or_angle
end

Instance Method Details

#childrenObject



148
149
150
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 148

def children
  [color_stops, position_or_angle].compact
end

#supports?(aspect) ⇒ Boolean

Returns:

  • (Boolean)


171
172
173
174
175
176
177
178
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 171

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 svg).include?(aspect) && position_or_angle.is_a?(Sass::Script::Number) && position_or_angle.numerator_units.include?("deg")
    false
  else
    super
  end
end

#to_css2(options = self.options) ⇒ Object



200
201
202
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 200

def to_css2(options = self.options)
  Sass::Script::String.new("")
end

#to_owg(options = self.options) ⇒ Object

Output the original webkit gradient syntax



181
182
183
184
185
186
187
188
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 181

def to_owg(options = self.options)
  args = []
  args << grad_point(position_or_angle || Sass::Script::String.new("top"))
  args << linear_end_position(position_or_angle, color_stops)
  args << grad_color_stops(color_stops)
  args.each{|a| a.options = options}
  Sass::Script::String.new("-webkit-gradient(linear, #{args.join(', ')})")
end

#to_pie(options = self.options) ⇒ Object



194
195
196
197
198
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 194

def to_pie(options = self.options)
  # PIE just uses the standard rep, but the property is prefixed so
  # the presence of this attribute helps flag when to render a special rule.
  Sass::Script::String.new to_s(options)
end

#to_s(options = self.options) ⇒ Object



160
161
162
163
164
165
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 160

def to_s(options = self.options)
  s = "linear-gradient("
  s << position_or_angle.to_s(options) << ", " if position_or_angle
  s << color_stops.to_s(options)
  s << ")"
end

#to_svg(options = self.options) ⇒ Object



190
191
192
# File 'lib/compass/sass_extensions/functions/gradient_support.rb', line 190

def to_svg(options = self.options)
  linear_svg_gradient(color_stops, position_or_angle || Sass::Script::String.new("top"))
end