Class: TemplateForm::BaseInput
- Inherits:
-
Object
- Object
- TemplateForm::BaseInput
- Defined in:
- lib/template_form/base_input.rb
Direct Known Subclasses
CheckboxInput, FileInput, GroupedSelectInput, SelectInput, TextInput, TextareaInput
Instance Method Summary collapse
-
#initialize(builder, attribute_name, options) ⇒ BaseInput
constructor
A new instance of BaseInput.
- #render ⇒ Object
Constructor Details
#initialize(builder, attribute_name, options) ⇒ BaseInput
Returns a new instance of BaseInput.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/template_form/base_input.rb', line 6 def initialize(builder, attribute_name, ) @builder = builder @attribute_name = attribute_name @view = .delete(:view) @form_type = .delete(:form_type) || builder.form_type # Use the `:label` option to override the default label text. # Use `label: false` to indicate no label should be shown (check `has_label` in the template). @has_label = !(.has_key?(:label) && [:label] == false) @label_text = .delete(:label) || '' = Hash.new { |h,k| h[k] = '' }.update(.delete(:label_options) || {}) @hint_text = .delete(:hint) || '' data_attributes = (.delete(:data) || {}).transform_keys { |k| "data-#{k}" } = .merge! data_attributes [:class] ||= '' end |
Instance Method Details
#render ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/template_form/base_input.rb', line 29 def render template.render( builder, attribute_name: attribute_name, has_label: has_label, label_text: label_text, label_options: , hint_text: hint_text, options: , errors: errors, view: view ).html_safe end |