Module: Coco::TagHelper
- Included in:
- AlpineHelper, SeamlessTextarea, Tag
- Defined in:
- app/helpers/coco/tag_helper.rb
Instance Method Summary collapse
- #prefix_attr_keys(attrs, prefix) ⇒ Object
- #random_id(length = 6) ⇒ Object
-
#style_str(styles) ⇒ Object
Converts an hash to an string of CSS styles for use in HTML ‘style` attributes.
Instance Method Details
#prefix_attr_keys(attrs, prefix) ⇒ Object
3 4 5 |
# File 'app/helpers/coco/tag_helper.rb', line 3 def prefix_attr_keys(attrs, prefix) attrs.transform_keys! { [prefix, _1].map(&:to_s).join("-") } end |
#random_id(length = 6) ⇒ Object
14 15 16 |
# File 'app/helpers/coco/tag_helper.rb', line 14 def random_id(length = 6) ("a".."z").to_a.shuffle[0, length].join end |
#style_str(styles) ⇒ Object
Converts an hash to an string of CSS styles for use in HTML ‘style` attributes
8 9 10 11 12 |
# File 'app/helpers/coco/tag_helper.rb', line 8 def style_str(styles) styles.to_h.compact.reduce([]) do |array, (key, value)| array << "#{key.to_s.dasherize}: #{value}" end.join("; ") end |