Module: MarginHelper

Included in:
Shoes::Drawable
Defined in:
lacci/lib/shoes/margin_helper.rb

Instance Method Summary collapse

Instance Method Details

#margin_parse(kwargs) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lacci/lib/shoes/margin_helper.rb', line 3

def margin_parse(kwargs)

    if kwargs[:margin]

      if kwargs[:margin].is_a?(Numeric)

        if !kwargs[:margin_top]
          kwargs[:margin_top] = kwargs[:margin]
        end
        if !kwargs[:margin_bottom]
          kwargs[:margin_bottom] = kwargs[:margin]
        end
        if !kwargs[:margin_left]
          kwargs[:margin_left] = kwargs[:margin]
        end
        if !kwargs[:margin_right]
          kwargs[:margin_right] = kwargs[:margin]
        end

      elsif kwargs[:margin].is_a?(Hash)

        kwargs[:margin].each do |key,value|
          kwargs[:"margin_#{key}"] = value
        end

      else
        margin_props = kwargs[:margin].is_a?(String) ? kwargs[:margin].split(/\s+|\,|-/) : kwargs[:margin]
        if margin_props.length == 1

          if !kwargs[:margin_top]
            kwargs[:margin_top] = margin_props[0]
          end
          if !kwargs[:margin_bottom]
            kwargs[:margin_bottom] = margin_props[0]
          end
          if !kwargs[:margin_left]
            kwargs[:margin_left] = margin_props[0]
          end
          if !kwargs[:margin_right]
            kwargs[:margin_right] = margin_props[0]
          end

        elsif margin_props.length == 2

          raise(Shoes::Errors::InvalidAttributeValueError, "Margin don't support 2-3 values as Array/string input for using 2-3 input you can use the hash input method like '{left:value, right:value, top:value, bottom:value}'")

        elsif margin_props.length == 3

          raise(Shoes::Errors::InvalidAttributeValueError, "Margin don't support 2-3 values as Array/string input for using 2-3 input you can use the hash input method like '{left:value,right:value,top:value,bottom:value}'")
        
        else

          if !kwargs[:margin_top]
            kwargs[:margin_top] = margin_props[1]
          end
          if !kwargs[:margin_bottom]
            kwargs[:margin_bottom] = margin_props[3]
          end
          if !kwargs[:margin_left]
            kwargs[:margin_left] = margin_props[0]
          end
          if !kwargs[:margin_right]
            kwargs[:margin_right] = margin_props[2]
          end

        end
      end
      kwargs[:margin] = nil
    end
    if kwargs["options"] && !kwargs[:margin] && !kwargs[:margin_left] && !kwargs[:margin_right] && !kwargs[:margin_top] && !kwargs[:margin_bottom]
      kwargs[options].each do |key,value|
        kwargs[key] = value
      end
    end
    kwargs
end