Module: NitroKit::LabelHelper

Defined in:
app/helpers/nitro_kit/label_helper.rb

Instance Method Summary collapse

Instance Method Details

#nk_label(name = nil, content_or_options = nil, **attrs, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/nitro_kit/label_helper.rb', line 3

def nk_label(name = nil, content_or_options = nil, **attrs, &block)
  if block_given? && content_or_options.is_a?(Hash)
    attrs = content_or_options = content_or_options.symbolize_keys
  else
    attrs ||= {}
    attrs = attrs.symbolize_keys
  end

  attrs[:for] = sanitize_to_id(name) unless name.blank? || attrs.has_key?("for")

  render(Label.new(**attrs)) { content_or_options || name.to_s.humanize || yield }
end