Module: Playbook::Spacing
- Included in:
- KitBase
- Defined in:
- lib/playbook/spacing.rb
Class Method Summary collapse
Instance Method Summary collapse
- #break_method_values ⇒ Object
- #filter_classname(value) ⇒ Object
- #gap_options ⇒ Object
- #gap_props ⇒ Object
- #gap_values ⇒ Object
- #max_width_options ⇒ Object
- #max_width_props ⇒ Object
- #max_width_values ⇒ Object
- #min_width_options ⇒ Object
- #min_width_props ⇒ Object
- #min_width_values ⇒ Object
- #screen_size_values ⇒ Object
- #spacing_options ⇒ Object
- #spacing_props ⇒ Object
- #spacing_values ⇒ Object
- #width_options ⇒ Object
- #width_props ⇒ Object
- #width_values ⇒ Object
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 |
# File 'lib/playbook/spacing.rb', line 5 def self.included(base) base.prop :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_values ⇒ Object
93 94 95 |
# File 'lib/playbook/spacing.rb', line 93 def break_method_values %w[on at] end |
#filter_classname(value) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/playbook/spacing.rb', line 123 def filter_classname(value) if value.include?("%") value.gsub("%", "_percent") else value end end |
#gap_options ⇒ Object
60 61 62 63 64 |
# File 'lib/playbook/spacing.rb', line 60 def { gap: "gap", } end |
#gap_props ⇒ Object
161 162 163 164 165 166 167 168 169 |
# File 'lib/playbook/spacing.rb', line 161 def gap_props selected_gap_props = .keys.select { |sk| try(sk) } return nil unless selected_gap_props.present? selected_gap_props.map do |k| gap_value = send(k) "gap_#{gap_value}" if gap_values.include? gap_value end.compact.join(" ") end |
#gap_values ⇒ Object
56 57 58 |
# File 'lib/playbook/spacing.rb', line 56 def gap_values %w[none xxs xs sm md lg xl] end |
#max_width_options ⇒ Object
26 27 28 29 30 |
# File 'lib/playbook/spacing.rb', line 26 def { max_width: "mw", } end |
#max_width_props ⇒ Object
141 142 143 144 145 146 147 148 149 |
# File 'lib/playbook/spacing.rb', line 141 def max_width_props selected_mw_props = .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_values ⇒ Object
44 45 46 |
# File 'lib/playbook/spacing.rb', line 44 def max_width_values %w[0% xs sm md lg xl xxl 0 none 100%] end |
#min_width_options ⇒ Object
32 33 34 35 36 |
# File 'lib/playbook/spacing.rb', line 32 def { min_width: "minw", } end |
#min_width_props ⇒ Object
131 132 133 134 135 136 137 138 139 |
# File 'lib/playbook/spacing.rb', line 131 def min_width_props selected_minw_props = .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_values ⇒ Object
48 49 50 |
# File 'lib/playbook/spacing.rb', line 48 def min_width_values %w[0% xs sm md lg xl xxl 0 none 100%] end |
#screen_size_values ⇒ Object
89 90 91 |
# File 'lib/playbook/spacing.rb', line 89 def screen_size_values %w[xs sm md lg xl default] end |
#spacing_options ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/playbook/spacing.rb', line 66 def { 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_props ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/playbook/spacing.rb', line 97 def spacing_props selected_props = .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 = [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_values ⇒ Object
85 86 87 |
# File 'lib/playbook/spacing.rb', line 85 def spacing_values %w[none xxs xs sm md lg xl auto initial inherit] end |
#width_options ⇒ Object
38 39 40 41 42 |
# File 'lib/playbook/spacing.rb', line 38 def { width: "w", } end |
#width_props ⇒ Object
151 152 153 154 155 156 157 158 159 |
# File 'lib/playbook/spacing.rb', line 151 def width_props selected_w_props = .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_values ⇒ Object
52 53 54 |
# File 'lib/playbook/spacing.rb', line 52 def width_values %w[0% xs sm md lg xl xxl 0 none 100%] end |