Module: Voom::Presenters::DSL::Components::Mixins::Padding

Included in:
Button, Card, Content, Grid, Grid::Column, Separator
Defined in:
lib/voom/presenters/dsl/components/mixins/padding.rb

Instance Method Summary collapse

Instance Method Details

#coerce_padding(padding, default_level: 2) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/voom/presenters/dsl/components/mixins/padding.rb', line 7

def coerce_padding(padding, default_level: 2)
  case padding
  when true, :full, :all
    [:"top#{default_level}", :"right#{default_level}", :"bottom#{default_level}", :"left#{default_level}"]
  when false, :none
    []
  else
    Array(padding).map do |item|
      %i(top right bottom left).include?(item) ? :"#{item}#{default_level}" : item
    end
  end
end

#validate_padding(padding_) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/voom/presenters/dsl/components/mixins/padding.rb', line 20

def validate_padding(padding_)
  valid_padding = %i(top right bottom left
                     top0 right0 bottom0 left0
                     top1 right1 bottom1 left1
                     top2 right2 bottom2 left2
                     top3 right3 bottom3 left3)
  validation_msg = 'Padding must either be true or :full, :all, false or :none, '\
                 "or an array containing zero or more of the following: #{valid_padding.join(', ')}"
  if padding_.respond_to?(:pop)
    raise Errors::ParameterValidation, validation_msg if (padding_ - valid_padding).any?
  else
    raise Errors::ParameterValidation, validation_msg unless padding_ === true ||
        padding_ === false ||
        %i(full none).include(padding_)
  end
  padding_
end