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
- #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 |
# File 'lib/playbook/spacing.rb', line 5 def self.included(base) 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
82 83 84 |
# File 'lib/playbook/spacing.rb', line 82 def break_method_values %w[on at] end |
#filter_classname(value) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/playbook/spacing.rb', line 112 def filter_classname(value) if value.include?("%") value.gsub("%", "_percent") else value end end |
#max_width_options ⇒ Object
25 26 27 28 29 |
# File 'lib/playbook/spacing.rb', line 25 def { max_width: "mw", } end |
#max_width_props ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/playbook/spacing.rb', line 130 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
43 44 45 |
# File 'lib/playbook/spacing.rb', line 43 def max_width_values %w[0% xs sm md lg xl xxl 0 none 100%] end |
#min_width_options ⇒ Object
31 32 33 34 35 |
# File 'lib/playbook/spacing.rb', line 31 def { min_width: "minw", } end |
#min_width_props ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'lib/playbook/spacing.rb', line 120 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
47 48 49 |
# File 'lib/playbook/spacing.rb', line 47 def min_width_values %w[0% xs sm md lg xl xxl 0 none 100%] end |
#screen_size_values ⇒ Object
78 79 80 |
# File 'lib/playbook/spacing.rb', line 78 def screen_size_values %w[xs sm md lg xl default] end |
#spacing_options ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/playbook/spacing.rb', line 55 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
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/playbook/spacing.rb', line 86 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
74 75 76 |
# File 'lib/playbook/spacing.rb', line 74 def spacing_values %w[none xxs xs sm md lg xl auto initial inherit] end |
#width_options ⇒ Object
37 38 39 40 41 |
# File 'lib/playbook/spacing.rb', line 37 def { width: "w", } end |
#width_props ⇒ Object
140 141 142 143 144 145 146 147 148 |
# File 'lib/playbook/spacing.rb', line 140 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
51 52 53 |
# File 'lib/playbook/spacing.rb', line 51 def width_values %w[0% xs sm md lg xl xxl 0 none 100%] end |