Sha256: fd9e7cf443a649531c3a6159e8287a2f7a106474dfa813bcbabcbf805eda5b68

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module Bootstrap
  module ViewHelpers
    module Components
      class Button < Component
        class Checkbox < 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,
                               type: 'checkbox', 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/checkbox.rb
bootstrap-view_helpers-0.0.2 lib/bootstrap/view_helpers/components/button/checkbox.rb