Class: Locomotive::FormBuilder
- Inherits:
-
SimpleForm::FormBuilder
- Object
- SimpleForm::FormBuilder
- Locomotive::FormBuilder
- Defined in:
- lib/locomotive/simple_form.rb
Instance Method Summary collapse
- #action(options = {}) ⇒ Object
- #actions(options = {}, &block) ⇒ Object
- #actions_with_back_button(options = {}) ⇒ Object
- #back_button_action(options = {}) ⇒ Object
- #inputs(name = nil, options = {}, &block) ⇒ Object
-
#lookup_model_names ⇒ Object
Extract the model names from the object_name mess, ignoring numeric and explicit child indexes.
- #submit_text(action = :submit) ⇒ Object
- #translate_button(key) ⇒ Object
Instance Method Details
#action(options = {}) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/locomotive/simple_form.rb', line 113 def action( = {}) action = object.persisted? ? :update : :create label = [:label] || (action) loading_text = (:loading_text) template.content_tag :button, label, type: 'submit', class: [:change_class] || "btn btn-primary btn-sm #{[:class]}", data: { loading_text: loading_text } end |
#actions(options = {}, &block) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/locomotive/simple_form.rb', line 83 def actions( = {}, &block) if [:back_url] () else [:class] ||= 'text-right form-actions' template.content_tag(:div, , &block) end end |
#actions_with_back_button(options = {}) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/locomotive/simple_form.rb', line 92 def ( = {}) = () template.content_tag(:div, action + ' '.html_safe + (:or) + ' '.html_safe + , class: 'text-right form-actions') end |
#back_button_action(options = {}) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/locomotive/simple_form.rb', line 102 def ( = {}) label = (:cancel) url = [:back_url] if [:use_stored_location] url = template.last_saved_location(url) end template.link_to(label, url) end |
#inputs(name = nil, options = {}, &block) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/locomotive/simple_form.rb', line 74 def inputs(name = nil, = {}, &block) html = template.content_tag(:legend, template.content_tag(:span, name)) html += template.capture(&block) [:class] ||= 'inputs' template.content_tag(:fieldset, html, ) end |
#lookup_model_names ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/locomotive/simple_form.rb', line 141 def lookup_model_names #:nodoc: @lookup_model_names ||= begin child_index = [:child_index] names = object_name.to_s.scan(/(?!\d)\w+/).flatten names.unshift('locomotive') names.delete(child_index) if child_index names.each { |name| name.gsub!('_attributes', '') } names.freeze end end |
#submit_text(action = :submit) ⇒ Object
124 125 126 |
# File 'lib/locomotive/simple_form.rb', line 124 def submit_text(action = :submit) (action) end |
#translate_button(key) ⇒ Object
128 129 130 |
# File 'lib/locomotive/simple_form.rb', line 128 def (key) template.t("simple_form.buttons.defaults.locomotive.#{key}") end |