Class: Gradient::CSSPrinter
- Inherits:
-
Object
- Object
- Gradient::CSSPrinter
- Defined in:
- lib/gradient/css_printer.rb
Constant Summary collapse
- ORIENTATIONS =
%i(horizontal vertical diagonal_top diagonal_bottom radial)
Instance Method Summary collapse
- #css(type: :linear, property: "background", **args) ⇒ Object
-
#initialize(map) ⇒ CSSPrinter
constructor
A new instance of CSSPrinter.
- #linear(vendor: nil, direction: "to right", angle: nil, repeating: false) ⇒ Object
- #radial(vendor: nil, shape: nil, size: nil, position: nil, repeating: false) ⇒ Object
- #rgba_values ⇒ Object
Constructor Details
#initialize(map) ⇒ CSSPrinter
Returns a new instance of CSSPrinter.
6 7 8 |
# File 'lib/gradient/css_printer.rb', line 6 def initialize(map) @map = map end |
Instance Method Details
#css(type: :linear, property: "background", **args) ⇒ Object
10 11 12 |
# File 'lib/gradient/css_printer.rb', line 10 def css(type: :linear, property: "background", **args) "#{property}:#{send(type,**args)};" end |
#linear(vendor: nil, direction: "to right", angle: nil, repeating: false) ⇒ Object
14 15 16 17 18 |
# File 'lib/gradient/css_printer.rb', line 14 def linear(vendor: nil, direction: "to right", angle: nil, repeating: false) angle_or_direction = [angle || direction] arguments = (angle_or_direction + rgba_values) format_css_function(vendor, repeating, "linear-gradient") + "(#{arguments.join(", ")})" end |
#radial(vendor: nil, shape: nil, size: nil, position: nil, repeating: false) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/gradient/css_printer.rb', line 20 def radial(vendor: nil, shape: nil, size: nil, position: nil, repeating: false) shape_and_size_at_position = [] shape_and_size_at_position << shape if shape shape_and_size_at_position << size if size shape_and_size_at_position << position if position arguments = rgba_values arguments.unshift(shape_and_size_at_position.join(" ")) if shape_and_size_at_position.any? format_css_function(vendor, repeating, "radial-gradient") + "(#{arguments.join(", ")})" end |
#rgba_values ⇒ Object
30 31 32 |
# File 'lib/gradient/css_printer.rb', line 30 def rgba_values @map.points.map { |point| point_to_rgba(point) } end |