Module: Playbook::Spacing

Included in:
KitBase
Defined in:
lib/playbook/spacing.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/playbook/spacing.rb', line 5

def self.included(base)
  base.prop :gap
  base.prop :column_gap
  base.prop :row_gap
  base.prop :margin
  base.prop :margin_bottom
  base.prop :margin_left
  base.prop :margin_right
  base.prop :margin_top
  base.prop :margin_x
  base.prop :margin_y
  base.prop :max_width
  base.prop :min_width
  base.prop :width
  base.prop :padding
  base.prop :padding_bottom
  base.prop :padding_left
  base.prop :padding_right
  base.prop :padding_top
  base.prop :padding_x
  base.prop :padding_y
end

Instance Method Details

#break_method_valuesObject



107
108
109
# File 'lib/playbook/spacing.rb', line 107

def break_method_values
  %w[on at]
end

#column_gap_optionsObject



68
69
70
71
72
# File 'lib/playbook/spacing.rb', line 68

def column_gap_options
  {
    column_gap: "column_gap",
  }
end

#column_gap_propsObject



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/playbook/spacing.rb', line 191

def column_gap_props
  selected_column_gap_props = column_gap_options.keys.select { |sk| try(sk) }
  return nil unless selected_column_gap_props.present?

  selected_column_gap_props.map do |k|
    column_gap_value = send(k)
    if column_gap_value.is_a?(Hash)
      column_gap_value.map do |media_size, column_gap_spacing_value|
        "column_gap_#{media_size}_#{column_gap_spacing_value.underscore}" if gap_values.include?(column_gap_spacing_value.to_s)
      end
    elsif gap_values.include?(column_gap_value.to_s)
      "column_gap_#{column_gap_value.underscore}"
    end
  end.compact.join(" ")
end

#filter_classname(value) ⇒ Object



137
138
139
140
141
142
143
# File 'lib/playbook/spacing.rb', line 137

def filter_classname(value)
  if value.include?("%")
    value.gsub("%", "_percent")
  else
    value
  end
end

#gap_optionsObject



62
63
64
65
66
# File 'lib/playbook/spacing.rb', line 62

def gap_options
  {
    gap: "gap",
  }
end

#gap_propsObject



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/playbook/spacing.rb', line 175

def gap_props
  selected_gap_props = gap_options.keys.select { |sk| try(sk) }
  return nil unless selected_gap_props.present?

  selected_gap_props.map do |k|
    gap_value = send(k)
    if gap_value.is_a?(Hash)
      gap_value.map do |media_size, gap_spacing_value|
        "gap_#{media_size}_#{gap_spacing_value.underscore}" if gap_values.include?(gap_spacing_value.to_s)
      end
    elsif gap_values.include?(gap_value.to_s)
      "gap_#{gap_value.underscore}"
    end
  end.compact.join(" ")
end

#gap_valuesObject



58
59
60
# File 'lib/playbook/spacing.rb', line 58

def gap_values
  %w[none xxs xs sm md lg xl]
end

#max_width_optionsObject



28
29
30
31
32
# File 'lib/playbook/spacing.rb', line 28

def max_width_options
  {
    max_width: "mw",
  }
end

#max_width_propsObject



155
156
157
158
159
160
161
162
163
# File 'lib/playbook/spacing.rb', line 155

def max_width_props
  selected_mw_props = max_width_options.keys.select { |sk| try(sk) }
  return nil unless selected_mw_props.present?

  selected_mw_props.map do |k|
    width_value = send(k)
    "max_width_#{filter_classname(width_value)}" if max_width_values.include? width_value
  end.compact.join(" ")
end

#max_width_valuesObject



46
47
48
# File 'lib/playbook/spacing.rb', line 46

def max_width_values
  %w[0% xs sm md lg xl xxl 0 none 100%]
end

#min_width_optionsObject



34
35
36
37
38
# File 'lib/playbook/spacing.rb', line 34

def min_width_options
  {
    min_width: "minw",
  }
end

#min_width_propsObject



145
146
147
148
149
150
151
152
153
# File 'lib/playbook/spacing.rb', line 145

def min_width_props
  selected_minw_props = min_width_options.keys.select { |sk| try(sk) }
  return nil unless selected_minw_props.present?

  selected_minw_props.map do |k|
    width_value = send(k)
    "min_width_#{filter_classname(width_value)}" if min_width_values.include? width_value
  end.compact.join(" ")
end

#min_width_valuesObject



50
51
52
# File 'lib/playbook/spacing.rb', line 50

def min_width_values
  %w[0% xs sm md lg xl xxl 0 none 100%]
end

#row_gap_optionsObject



74
75
76
77
78
# File 'lib/playbook/spacing.rb', line 74

def row_gap_options
  {
    row_gap: "row_gap",
  }
end

#row_gap_propsObject



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/playbook/spacing.rb', line 207

def row_gap_props
  selected_row_gap_props = row_gap_options.keys.select { |sk| try(sk) }
  return nil unless selected_row_gap_props.present?

  selected_row_gap_props.map do |k|
    row_gap_value = send(k)
    if row_gap_value.is_a?(Hash)
      row_gap_value.map do |media_size, row_gap_spacing_value|
        "row_gap_#{media_size}_#{row_gap_spacing_value.underscore}" if gap_values.include?(row_gap_spacing_value.to_s)
      end
    elsif gap_values.include?(row_gap_value.to_s)
      "row_gap_#{row_gap_value.underscore}"
    end
  end.compact.join(" ")
end

#screen_size_valuesObject



103
104
105
# File 'lib/playbook/spacing.rb', line 103

def screen_size_values
  %w[xs sm md lg xl default]
end

#spacing_optionsObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/playbook/spacing.rb', line 80

def spacing_options
  {
    margin: "m",
    margin_bottom: "mb",
    margin_left: "ml",
    margin_right: "mr",
    margin_top: "mt",
    margin_x: "mx",
    margin_y: "my",
    padding: "p",
    padding_bottom: "pb",
    padding_left: "pl",
    padding_right: "pr",
    padding_top: "pt",
    padding_x: "px",
    padding_y: "py",
  }
end

#spacing_propsObject



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

def spacing_props
  selected_props = spacing_options.keys.select { |sk| try(sk) }
  return nil unless selected_props.present?

  css = ""
  selected_props.each do |prop|
    responsive = try(prop).is_a?(::Hash)
    spacing_value = send(prop)
    prefix = spacing_options[prop]

    if responsive
      default_value = spacing_value.delete(:default) || nil
      break_value = spacing_value.delete(:break) || break_method_values.first
      spacing_value.each do |key, value|
        css += "break_#{break_value}_#{key}\:#{prefix}_#{value} " if screen_size_values.include?(key.to_s) && spacing_values.include?(value.to_s)
      end

      css += "#{prefix}_#{default_value} " if spacing_values.include?(default_value)
    elsif spacing_values.include?(spacing_value)
      css += "#{prefix}_#{spacing_value} "
    end
  end

  css.strip unless css.blank?
end

#spacing_valuesObject



99
100
101
# File 'lib/playbook/spacing.rb', line 99

def spacing_values
  %w[none xxs xs sm md lg xl auto initial inherit]
end

#width_optionsObject



40
41
42
43
44
# File 'lib/playbook/spacing.rb', line 40

def width_options
  {
    width: "w",
  }
end

#width_propsObject



165
166
167
168
169
170
171
172
173
# File 'lib/playbook/spacing.rb', line 165

def width_props
  selected_w_props = width_options.keys.select { |sk| try(sk) }
  return nil unless selected_w_props.present?

  selected_w_props.map do |k|
    width_value = send(k)
    "width_#{filter_classname(width_value)}" if width_values.include? width_value
  end.compact.join(" ")
end

#width_valuesObject



54
55
56
# File 'lib/playbook/spacing.rb', line 54

def width_values
  %w[0% xs sm md lg xl xxl 0 none 100%]
end