Sha256: d3af73be1619ce54ec0b6159a63cbb1dc20bc2f036bf860b0e0e0efe73c8670f

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

module Bootstrap
  module ViewHelpers
    module Components
      class Button < Component
        class Radio < Button
          def to_html
            input_options = input_html_options
            content_tag(:label, html_options) do
              content_tag(:input, label, input_options)
            end
          end

          protected

          attr_reader :checked, :input_options

          def inject_class_name_to_options
            super
            options[:class] << ' disabled' if options[:disabled]
          end

          def html_options
            @checked ||= options.delete(:checked)
            options
          end

          def input_html_options
            input_options = options.slice!(:id, :name)
            @options, input_options = input_options, options
            @input_options ||= { id: SecureRandom.hex, checked: checked,
                               name: 'options', type: 'radio',
                               autocomplete: 'off' }.merge(input_options)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bootstrap-view_helpers-0.0.3 lib/bootstrap/view_helpers/components/button/radio.rb
bootstrap-view_helpers-0.0.2 lib/bootstrap/view_helpers/components/button/radio.rb