Class: Sandals::Style
- Inherits:
-
Object
- Object
- Sandals::Style
- Defined in:
- lib/sandals/style.rb
Constant Summary collapse
- ELEMENTS =
%i[app stack flow title subtitle para button].freeze
- PROPERTIES =
%i[ background color border radius size weight width padding margin gap align ].freeze
- DIMENSIONS =
%i[radius size width padding margin gap].freeze
- CSS_PROPERTIES =
{ background: "background", color: "color", border: "border", radius: "border-radius", size: "font-size", weight: "font-weight", width: "width", padding: "padding", margin: "margin", gap: "gap" }.freeze
Class Method Summary collapse
- .inline(element, properties) ⇒ Object
- .normalize(element, properties) ⇒ Object
- .validate_element!(element) ⇒ Object
Class Method Details
.inline(element, properties) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/sandals/style.rb', line 44 def self.inline(element, properties) properties.map do |name, value| property = name == :align ? alignment_property(element) : CSS_PROPERTIES.fetch(name) "#{property}: #{value}" end.join("; ") end |
.normalize(element, properties) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sandals/style.rb', line 32 def self.normalize(element, properties) element = validate_element!(element) properties.to_h do |name, value| name = name.to_sym unless PROPERTIES.include?(name) raise ArgumentError, "unknown style property for #{element}: #{name}" end [name, normalize_value(name, value)] end.freeze end |
.validate_element!(element) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/sandals/style.rb', line 24 def self.validate_element!(element) name = element.to_sym return name if ELEMENTS.include?(name) raise ArgumentError, "unknown style element: #{element.inspect}; expected one of #{ELEMENTS.join(", ")}" end |