Sha256: a41f22d3ce77c03a12df3b7413cb6b110a098bb563e9cd1905208e0222a05945

Contents?: true

Size: 543 Bytes

Versions: 1

Compression:

Stored size: 543 Bytes

Contents

module Form
  module Component
    class Label < Base
      def attributes
        options.except(:text).tap do |attrs|
          attrs[:for] ||= id_attribute
        end
      end

      def text
        scopes = [
          [:form, :labels, form.base_name, name].flatten.compact.join(".").to_sym,
          :"form.labels.#{name}",
          humanize(name)
        ].compact

        options.fetch :text, t(scopes.shift, default: scopes)
      end

      def to_html
        Tag.new(:label, text, attributes).to_s
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
form-0.0.1.alpha1 lib/form/component/label.rb