class Bootstrap::ViewHelpers::Components::Button
Constants
- TYPES
Attributes
label[R]
Public Class Methods
build(view_context, options, &block)
click to toggle source
# File lib/bootstrap/view_helpers/components/button.rb, line 21 def build(view_context, options, &block) type = options.delete(:type) || defaults[:type] options[:type] = options[:html_type] unless TYPES.keys.include? type raise ButtonTypeNotFoundError, type end TYPES[type].new(view_context, options, &block) end
Protected Class Methods
defaults()
click to toggle source
# File lib/bootstrap/view_helpers/components/button.rb, line 32 def defaults { type: :button, style: ContextualClasses::PRIMARY } end
Public Instance Methods
to_html()
click to toggle source
# File lib/bootstrap/view_helpers/components/button.rb, line 37 def to_html content_tag(:button, label, html_options) end
Protected Instance Methods
defaults()
click to toggle source
# File lib/bootstrap/view_helpers/components/button.rb, line 45 def defaults Button.send(:defaults) end
html_options()
click to toggle source
# File lib/bootstrap/view_helpers/components/button.rb, line 76 def html_options { type: :submit }.merge(options) end
inject_additional_attributes()
click to toggle source
# File lib/bootstrap/view_helpers/components/button.rb, line 49 def inject_additional_attributes inject_class_name_to_options inject_aria_attributes inject_data_attributes @label = options.delete(:label) end
inject_aria_attributes()
click to toggle source
rubocop:disable Style/DoubleNegation
# File lib/bootstrap/view_helpers/components/button.rb, line 64 def inject_aria_attributes options[:aria] ||= {} options[:aria][:disabled] = true if options[:disabled] options[:aria][:pressed] = !!options[:active] end
inject_class_name_to_options()
click to toggle source
# File lib/bootstrap/view_helpers/components/button.rb, line 56 def inject_class_name_to_options options[:class] ||= '' outline = options[:outline] ? 'outline-' : '' active = options[:active] ? ' active' : '' options[:class] << " btn btn-#{outline}#{style}#{active}" end
inject_data_attributes()
click to toggle source
rubocop:enable Style/DoubleNegation
# File lib/bootstrap/view_helpers/components/button.rb, line 71 def inject_data_attributes options[:data] ||= {} options[:data][:toggle] = 'button' if options.delete(:toggle) end
parse_options(_)
click to toggle source
Calls superclass method
Bootstrap::ViewHelpers::Component#parse_options
# File lib/bootstrap/view_helpers/components/button.rb, line 80 def parse_options(_) super inject_additional_attributes end