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, &block) ⇒ 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.
67 68 69 70 71 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 67 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.
78 79 80 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 78 def HLineBy(length:, x: 0, y: 0, **) 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.
23 24 25 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 23 def HLineTo(x2:, x1: 0, y1: 0, **) 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.
56 57 58 59 60 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 56 def LineBy(angle:, length:, x: 0, y: 0, **) dx = length * ::Math.cos(angle.to_f / 180 * ::Math::PI) dy = length * ::Math.sin(angle.to_f / 180 * ::Math::PI) 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.
14 15 16 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 14 def LineTo(x2:, y2:, x1: 0, y1: 0, **) path(d: "M #{x1} #{y1} L #{x2} #{y2}", **) end |
#square(length:) ⇒ Sevgi::Graphics::Element
Builds a square rect.
85 86 87 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 85 def square(length:, **) rect(width: length, height: length, **) end |
#Symbol(name, **kwargs, &block) ⇒ Sevgi::Graphics::Element
Builds a titled SVG symbol.
31 32 33 34 35 36 37 38 39 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 31 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.
94 95 96 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 94 def VLineBy(length:, x: 0, y: 0, **) 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.
46 47 48 |
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 46 def VLineTo(y2:, x1: 0, y1: 0, **) path(d: "M #{x1} #{y1} V #{y2}", **) end |