Module: LogoSoup::Core::Css

Defined in:
lib/logosoup/core/css.rb

Overview

CSS utilities.

Class Method Summary collapse

Class Method Details

.fmt_tenth_px(value) ⇒ String

Formats a numeric value rounded to 1 decimal place.

Parameters:

  • value (Numeric)

Returns:

  • (String)


13
14
15
16
17
# File 'lib/logosoup/core/css.rb', line 13

def fmt_tenth_px(value)
  rounded = (value.to_f * 10).round / 10.0
  rounded = 0.0 if rounded.abs < 1e-9
  rounded.to_i == rounded ? rounded.to_i.to_s : rounded.to_s
end

.style_string(styles) ⇒ String

Builds an inline style string from a hash.

Parameters:

  • styles (Hash{Symbol=>String,nil})

Returns:

  • (String)


23
24
25
# File 'lib/logosoup/core/css.rb', line 23

def style_string(styles)
  styles.compact.map { |key, val| "#{key.to_s.tr('_', '-')}: #{val};" }.join(" ")
end