Module: Sevgi::Graphics::Mixtures::Wrappers
- Defined in:
- lib/sevgi/graphics/mixtures/wrappers.rb
Overview
DSL wrappers for common SVG shapes and content patterns.
Instance Method Summary collapse
-
#css(hash = nil, **attributes) ⇒ Sevgi::Graphics::Element
Builds a style element with CSS content.
-
#HLineBy(length:, x: 0, y: 0) ⇒ Sevgi::Graphics::Element
Builds a relative horizontal line path.
-
#HLineTo(x2:, x1: 0, y1: 0) ⇒ Sevgi::Graphics::Element
Builds a horizontal line path ending at an absolute x coordinate.
-
#LineBy(angle:, length:, x: 0, y: 0) ⇒ Sevgi::Graphics::Element
Builds a relative line path from angle and length.
-
#LineTo(x2:, y2:, x1: 0, y1: 0) ⇒ Sevgi::Graphics::Element
Builds a line path ending at an absolute point.
-
#square(length:) ⇒ Sevgi::Graphics::Element
Builds a square rect.
-
#Symbol(name, **kwargs) { ... } ⇒ Sevgi::Graphics::Element
Builds a titled SVG symbol.
-
#VLineBy(length:, x: 0, y: 0) ⇒ Sevgi::Graphics::Element
Builds a relative vertical line path.
-
#VLineTo(y2:, x1: 0, y1: 0) ⇒ Sevgi::Graphics::Element
Builds a vertical line path ending at an absolute y coordinate.
Instance Method Details
#css(hash = nil, **attributes) ⇒ Sevgi::Graphics::Element
Builds a style element with CSS content.
96 97 98 99 100 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 96 def css(hash = nil, **attributes) hash, attributes = attributes, {} unless hash style(Content.css(hash), type: "text/css", **attributes) end |
#HLineBy(length:, x: 0, y: 0) ⇒ Sevgi::Graphics::Element
Builds a relative horizontal line path.
108 109 110 111 112 113 114 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 108 def HLineBy(length:, x: 0, y: 0, **) length = Scalar.number(length, context: "horizontal line", field: :length) x = Scalar.number(x, context: "horizontal line", field: :x) y = Scalar.number(y, context: "horizontal line", field: :y) path(d: "M #{x} #{y} h #{length}", **) end |
#HLineTo(x2:, x1: 0, y1: 0) ⇒ Sevgi::Graphics::Element
Builds a horizontal line path ending at an absolute x coordinate.
32 33 34 35 36 37 38 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 32 def HLineTo(x2:, x1: 0, y1: 0, **) x1 = Scalar.number(x1, context: "horizontal line", field: :x1) y1 = Scalar.number(y1, context: "horizontal line", field: :y1) x2 = Scalar.number(x2, context: "horizontal line", field: :x2) path(d: "M #{x1} #{y1} H #{x2}", **) end |
#LineBy(angle:, length:, x: 0, y: 0) ⇒ Sevgi::Graphics::Element
Builds a relative line path from angle and length.
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 77 def LineBy(angle:, length:, x: 0, y: 0, **) angle, length, x, y = Scalar.numbers([angle, length, x, y], context: "relative line") dx, dy = Scalar.numbers( [ length * ::Math.cos(angle.to_f / 180 * ::Math::PI), length * ::Math.sin(angle.to_f / 180 * ::Math::PI) ], context: "relative line result" ) path(d: "M #{x} #{y} l #{dx} #{dy}", **) end |
#LineTo(x2:, y2:, x1: 0, y1: 0) ⇒ Sevgi::Graphics::Element
Builds a line path ending at an absolute point.
17 18 19 20 21 22 23 24 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 17 def LineTo(x2:, y2:, x1: 0, y1: 0, **) x1 = Scalar.number(x1, context: "absolute line", field: :x1) y1 = Scalar.number(y1, context: "absolute line", field: :y1) x2 = Scalar.number(x2, context: "absolute line", field: :x2) y2 = Scalar.number(y2, context: "absolute line", field: :y2) path(d: "M #{x1} #{y1} L #{x2} #{y2}", **) end |
#square(length:) ⇒ Sevgi::Graphics::Element
Builds a square rect.
120 121 122 123 124 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 120 def square(length:, **) length = Scalar.number(length, context: "square", field: :length) rect(width: length, height: length, **) end |
#Symbol(name, **kwargs) { ... } ⇒ Sevgi::Graphics::Element
Builds a titled SVG symbol.
46 47 48 49 50 51 52 53 54 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 46 def Symbol(name, **kwargs, &block) id = (words = name.split).map(&:downcase).join("-") title = words.map(&:capitalize).join(" ") symbol(id:, **kwargs) do title(title) Within(&block) end end |
#VLineBy(length:, x: 0, y: 0) ⇒ Sevgi::Graphics::Element
Builds a relative vertical line path.
132 133 134 135 136 137 138 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 132 def VLineBy(length:, x: 0, y: 0, **) length = Scalar.number(length, context: "vertical line", field: :length) x = Scalar.number(x, context: "vertical line", field: :x) y = Scalar.number(y, context: "vertical line", field: :y) path(d: "M #{x} #{y} v #{length}", **) end |
#VLineTo(y2:, x1: 0, y1: 0) ⇒ Sevgi::Graphics::Element
Builds a vertical line path ending at an absolute y coordinate.
62 63 64 65 66 67 68 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 62 def VLineTo(y2:, x1: 0, y1: 0, **) x1 = Scalar.number(x1, context: "vertical line", field: :x1) y1 = Scalar.number(y1, context: "vertical line", field: :y1) y2 = Scalar.number(y2, context: "vertical line", field: :y2) path(d: "M #{x1} #{y1} V #{y2}", **) end |