rails_bootstrap_form 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rails_bootstrap_form/bootstrap_form_options.rb +28 -0
- data/lib/rails_bootstrap_form/components/labels.rb +34 -0
- data/lib/rails_bootstrap_form/components.rb +2 -0
- data/lib/rails_bootstrap_form/field_wrapper_builder.rb +2 -0
- data/lib/rails_bootstrap_form/version.rb +1 -1
- metadata +2 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: eeb7afe12b186dfa741279347931a85c33ff4950dcb691d6089e18767d5edb80
         | 
| 4 | 
            +
              data.tar.gz: 18787c6cfd1ad0c3156f1611395551fb5c9c41d1e17983ac1393b7987d099455
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7de97d7da63f5742b0db6816e908335540c1b66eaab7509bca8257005dc30e7bb2dd7f1974d3f7d0cf45dcdb909e9644c4cd29bddd7de6450bad05e2216f7c64
         | 
| 7 | 
            +
              data.tar.gz: 97997858453d5b926fb23a8a64fe36294d5cf08c7d164a8a984eb5b42ee5d956451908567d4f3473bf1cd369b2570119bb211c8071f26096e78e3b90852bdc54
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
| @@ -34,6 +34,27 @@ module RailsBootstrapForm | |
| 34 34 | 
             
                # Default is nil.
         | 
| 35 35 | 
             
                attr_accessor :help_text
         | 
| 36 36 |  | 
| 37 | 
            +
                # An option to override automatically generated label text.
         | 
| 38 | 
            +
                attr_accessor :label_text
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                # An option to custmize whether the label is to be displayed or not.
         | 
| 41 | 
            +
                attr_accessor :skip_label
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                # An option to customize whether the label is only visible to screen readers.
         | 
| 44 | 
            +
                attr_accessor :hide_label
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                # The CSS class that will be used when the label is only accessible by screen
         | 
| 47 | 
            +
                # readers. Default is `visually-hidden`
         | 
| 48 | 
            +
                attr_accessor :hide_class
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                # Default CSS class that will be applied to all label tags.
         | 
| 51 | 
            +
                # Default is `form-label`.
         | 
| 52 | 
            +
                attr_accessor :label_class
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                # An additional CSS class that will be added along with the existing
         | 
| 55 | 
            +
                # `label_class` of the label. Default is nil.
         | 
| 56 | 
            +
                attr_accessor :additional_label_class
         | 
| 57 | 
            +
             | 
| 37 58 | 
             
                def initialize(options = {})
         | 
| 38 59 | 
             
                  set_defaults
         | 
| 39 60 | 
             
                  set_bootstrap_form_options(options)
         | 
| @@ -83,6 +104,13 @@ module RailsBootstrapForm | |
| 83 104 | 
             
                  @additional_field_class = nil
         | 
| 84 105 |  | 
| 85 106 | 
             
                  @help_text = nil
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                  @label_text = ""
         | 
| 109 | 
            +
                  @skip_label = false
         | 
| 110 | 
            +
                  @hide_label = false
         | 
| 111 | 
            +
                  @hide_class = "visually-hidden"
         | 
| 112 | 
            +
                  @label_class = "form-label"
         | 
| 113 | 
            +
                  @additional_label_class = nil
         | 
| 86 114 | 
             
                end
         | 
| 87 115 |  | 
| 88 116 | 
             
                private :set_defaults
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            # -*- frozen_string_literal: true -*-
         | 
| 3 | 
            +
            # -*- warn_indent: true -*-
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module RailsBootstrapForm
         | 
| 6 | 
            +
              module Components
         | 
| 7 | 
            +
                module Labels
         | 
| 8 | 
            +
                  extend ActiveSupport::Concern
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def self.included(base_class)
         | 
| 11 | 
            +
                    def label(attribute, bootstrap_options)
         | 
| 12 | 
            +
                      unless bootstrap_options.skip_label
         | 
| 13 | 
            +
                        label_class = label_classes(attribute, bootstrap_options)
         | 
| 14 | 
            +
                        label_text = label_text(attribute, bootstrap_options)
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                        super(attribute, label_text, class: label_class)
         | 
| 17 | 
            +
                      end
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    def label_classes(attribute, bootstrap_options)
         | 
| 21 | 
            +
                      classes = [bootstrap_options.label_class, bootstrap_options.additional_label_class]
         | 
| 22 | 
            +
                      classes << bootstrap_options.hide_class if bootstrap_options.hide_label
         | 
| 23 | 
            +
                      classes.flatten.compact
         | 
| 24 | 
            +
                    end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                    def label_text(attribute, bootstrap_options)
         | 
| 27 | 
            +
                      bootstrap_options.label_text || object&.class.try(:human_attribute_name, attribute)
         | 
| 28 | 
            +
                    end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                    private :label, :label_classes, :label_text
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
            end
         | 
| @@ -13,9 +13,11 @@ module RailsBootstrapForm | |
| 13 13 | 
             
                end
         | 
| 14 14 |  | 
| 15 15 | 
             
                def field_wrapper(attribute, bootstrap_options, options, &block)
         | 
| 16 | 
            +
                  label = label(attribute, bootstrap_options)
         | 
| 16 17 | 
             
                  help_text = help_text(attribute, bootstrap_options)
         | 
| 17 18 |  | 
| 18 19 | 
             
                  tag.div(class: field_wrapper_classes) do
         | 
| 20 | 
            +
                    concat(label)
         | 
| 19 21 | 
             
                    concat(capture(&block))
         | 
| 20 22 | 
             
                    concat(help_text)
         | 
| 21 23 | 
             
                  end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rails_bootstrap_form
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Harshal LADHE (shivam091)
         | 
| @@ -109,6 +109,7 @@ files: | |
| 109 109 | 
             
            - lib/rails_bootstrap_form/bootstrap_form_options.rb
         | 
| 110 110 | 
             
            - lib/rails_bootstrap_form/components.rb
         | 
| 111 111 | 
             
            - lib/rails_bootstrap_form/components/help_text.rb
         | 
| 112 | 
            +
            - lib/rails_bootstrap_form/components/labels.rb
         | 
| 112 113 | 
             
            - lib/rails_bootstrap_form/configuration.rb
         | 
| 113 114 | 
             
            - lib/rails_bootstrap_form/engine.rb
         | 
| 114 115 | 
             
            - lib/rails_bootstrap_form/field_wrapper_builder.rb
         |