Module: Plushie::Type::Border

Defined in:
lib/plushie/type/border.rb

Overview

Border specification for container and widget styling.

A border has color, width, and radius (uniform or per-corner).

Examples:

Keyword construction

Border.from_opts(color: "#3366ff", width: 2, rounded: 8)

DSL block form

container("box") do
  border do
    color "#3366ff"
    width 2
    rounded 8
  end
end

Per-corner radius

Border.from_opts(width: 1, radius: {top_left: 8, top_right: 8, bottom_right: 0, bottom_left: 0})

Defined Under Namespace

Classes: Spec

Constant Summary collapse

FIELD_KEYS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Recognized field keys for border specs.

%i[color width rounded radius].freeze

Class Method Summary collapse

Class Method Details

.encode(value) ⇒ Hash?

Encode a border value for the wire protocol.

Parameters:

  • value (Spec, Hash, nil)

Returns:

  • (Hash, nil)


94
95
96
97
98
99
100
101
# File 'lib/plushie/type/border.rb', line 94

def encode(value)
  case value
  when Spec then value.to_wire
  when Hash then value
  when nil then nil
  else raise ArgumentError, "invalid border: #{value.inspect}"
  end
end

.from_opts(opts) ⇒ Spec

Construct from keyword options.

Parameters:

  • opts (Hash)

    :color, :width, :rounded, :radius

Returns:



82
83
84
85
86
87
88
89
# File 'lib/plushie/type/border.rb', line 82

def from_opts(opts)
  spec = Spec.new
  spec = spec.with(color: Color.cast(opts[:color])) if opts[:color]
  spec = spec.with(width: opts[:width]) if opts[:width]
  spec = spec.with(radius: opts[:rounded]) if opts[:rounded]
  spec = spec.with(radius: opts[:radius]) if opts[:radius]
  spec
end

.newSpec

Create a new border with defaults (no color, zero width, zero radius).

Returns:



75
76
77
# File 'lib/plushie/type/border.rb', line 75

def new
  Spec.new
end