Class: Compass::SassExtensions::Functions::GradientSupport::LinearGradient
- Inherits:
-
Sass::Script::Literal
- Object
- Sass::Script::Literal
- Compass::SassExtensions::Functions::GradientSupport::LinearGradient
- 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
Instance Attribute Summary collapse
-
#color_stops ⇒ Object
Returns the value of attribute color_stops.
-
#position_or_angle ⇒ Object
Returns the value of attribute position_or_angle.
Instance Method Summary collapse
- #children ⇒ Object
-
#initialize(position_or_angle, color_stops) ⇒ 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_pie(options = self.options) ⇒ Object
- #to_s(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
#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
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_stops ⇒ Object
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_angle ⇒ Object
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
#children ⇒ Object
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
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( = self.) 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( = self.) 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. = } 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( = self.) # 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() 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( = self.) s = "linear-gradient(" s << position_or_angle.to_s() << ", " if position_or_angle s << color_stops.to_s() s << ")" end |