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) { ... } ⇒ 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

Yields:

  • evaluates the template drawing DSL in a generated group

Yield Returns:

  • (Object)

    ignored block result

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when a required tile argument is missing or invalid



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
63
64
# File 'lib/sevgi/graphics/mixtures/tile.rb', line 25

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) { ... } ⇒ 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

Yields:

  • evaluates the template drawing DSL in a generated group

Yield Returns:

  • (Object)

    ignored block result

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when a required tile argument is missing or invalid



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

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) { ... } ⇒ 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

Yields:

  • evaluates the template drawing DSL in a generated group

Yield Returns:

  • (Object)

    ignored block result

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when a required tile argument is missing or invalid



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/sevgi/graphics/mixtures/tile.rb', line 111

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