Sha256: d638ffc440653f240fd4bb8f15c8bad4a6200fdca8db850d0d71c57fb0ab5124

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

# -*- encoding: utf-8 -*-
# -*- frozen_string_literal: true -*-
# -*- warn_indent: true -*-

module RailsBootstrapForm
  module Components
    module Labels
      extend ActiveSupport::Concern

      def self.included(base_class)
        def label(attribute, bootstrap_options)
          unless bootstrap_options.skip_label
            label_class = label_classes(attribute, bootstrap_options)
            label_text = label_text(attribute, bootstrap_options)

            super(attribute, label_text, class: label_class)
          end
        end

        def label_classes(attribute, bootstrap_options)
          classes = [bootstrap_options.label_class, bootstrap_options.additional_label_class]
          classes << bootstrap_options.hide_class if bootstrap_options.hide_label
          classes << "required" if is_attribute_required?(attribute)
          classes << "is-invalid" if is_invalid?(attribute)
          classes.flatten.compact
        end

        def label_text(attribute, bootstrap_options)
          bootstrap_options.label_text || object&.class.try(:human_attribute_name, attribute)
        end

        private :label, :label_classes, :label_text
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_bootstrap_form-0.4.2 lib/rails_bootstrap_form/components/labels.rb
rails_bootstrap_form-0.4.1 lib/rails_bootstrap_form/components/labels.rb
rails_bootstrap_form-0.4.0 lib/rails_bootstrap_form/components/labels.rb
rails_bootstrap_form-0.3.1 lib/rails_bootstrap_form/components/labels.rb
rails_bootstrap_form-0.3.0 lib/rails_bootstrap_form/components/labels.rb