Module: Sevgi::Graphics::Mixtures::Tile

Defined in:
lib/sevgi/graphics/mixtures/tile.rb

Overview

rubocop:disable Metrics/MethodLength DSL helpers for repeated SVG use elements.

Constant Summary collapse

PREFIX =

Prefix used for generated tile CSS classes.

"tile"

Instance Method Summary collapse

Instance Method Details

#Tile(id = Undefined, nx: Undefined, dx: Undefined, ox: 0, ny: Undefined, dy: Undefined, oy: 0, proc: nil, &block) ⇒ Sevgi::Graphics::Element

Builds a two-dimensional tile grid.

Parameters:

  • id (String) (defaults to: Undefined)

    referenced template id

  • nx (Integer) (defaults to: Undefined)

    number of columns

  • dx (Numeric) (defaults to: Undefined)

    horizontal spacing

  • ox (Numeric) (defaults to: 0)

    horizontal offset

  • ny (Integer) (defaults to: Undefined)

    number of rows

  • dy (Numeric) (defaults to: Undefined)

    vertical spacing

  • oy (Numeric) (defaults to: 0)

    vertical offset

  • proc (Proc, nil) (defaults to: nil)

    optional coordinate/customization proc

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when a required tile argument is missing or invalid



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sevgi/graphics/mixtures/tile.rb', line 23

def Tile(
  id = Undefined,
  nx: Undefined,
  dx: Undefined,
  ox: 0,
  ny: Undefined,
  dy: Undefined,
  oy: 0,
  proc: nil,
  &block
)
  Helper.assert(id:, nx:, dx:, ox:, ny:, dy:, oy:, proc:)

  href, coords = id, proc do |x, y|
    # rubocop:disable Style/NestedTernaryOperator
    # for pretty kwargs handling
    x.zero? ? (y.zero? ? {} : {y:}) : (y.zero? ? {x:} : {x:, y:})
    # rubocop:enable Style/NestedTernaryOperator
  end

  defs { g(id:, &block) } if block

  Within do
    ny.times do |y|
      rs = Helper.classify(as: "row", index: y, upper: ny)

      nx.times do |x|
        cs = Helper.classify(as: "col", index: x, upper: nx)

        element = use(
          id: [href, y + 1, x + 1].join("-"),
          href: "##{href}",
          class: [*rs, *cs].join(" "),
          **coords.((x * dx) + ox, (y * dy) + oy)
        )
        proc&.call(element, x:, y:, nx:, ny:)
      end
    end
  end
end

#TileX(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil, &block) ⇒ Sevgi::Graphics::Element

Builds a one-dimensional horizontal tile row.

Parameters:

  • id (String) (defaults to: Undefined)

    referenced template id

  • n (Integer) (defaults to: Undefined)

    number of instances

  • d (Numeric) (defaults to: Undefined)

    horizontal spacing

  • o (Numeric) (defaults to: 0)

    horizontal offset

  • proc (Proc, nil) (defaults to: nil)

    optional coordinate/customization proc

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when a required tile argument is missing or invalid



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/sevgi/graphics/mixtures/tile.rb', line 72

def TileX(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil, &block)
  Helper.assert(id:, n:, d:, o:, proc:)

  href, coords = id, proc do |x|
    # for pretty kwargs handling
    x.zero? ? {} : {x:}
  end

  defs { g(id:, &block) } if block

  Within do
    n.times do |x|
      cs = Helper.classify(as: "col", index: x, upper: n)

      element = use(
        id: [href, x + 1].join("-"),
        href: "##{href}",
        class: cs.join(" "),
        **coords.((x * d) + o)
      )
      proc&.call(element, x:, n:)
    end
  end
end

#TileY(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil, &block) ⇒ Sevgi::Graphics::Element

Builds a one-dimensional vertical tile column.

Parameters:

  • id (String) (defaults to: Undefined)

    referenced template id

  • n (Integer) (defaults to: Undefined)

    number of instances

  • d (Numeric) (defaults to: Undefined)

    vertical spacing

  • o (Numeric) (defaults to: 0)

    vertical offset

  • proc (Proc, nil) (defaults to: nil)

    optional coordinate/customization proc

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when a required tile argument is missing or invalid



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/sevgi/graphics/mixtures/tile.rb', line 105

def TileY(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil, &block)
  Helper.assert(id:, n:, d:, o:, proc:)

  href, coords = id, proc do |y|
    # for pretty kwargs handling
    y.zero? ? {} : {y:}
  end

  defs { g(id:, &block) } if block

  Within do
    n.times do |y|
      rs = Helper.classify(as: "row", index: y, upper: n)

      element = use(
        id: [href, y + 1].join("-"),
        href: "##{href}",
        class: rs.join(" "),
        **coords.((y * d) + o)
      )
      proc&.call(element, y:, n:)
    end
  end
end