Module: DefaultForm::Builder::Wrap
- Included in:
- Helper
- Defined in:
- lib/default_form/builder/wrap.rb
Instance Method Summary collapse
- #help_tag(text) ⇒ Object
- #object_has_errors?(method) ⇒ Boolean
- #offset(css) ⇒ Object
- #wrapping(type, inner, tag: 'div', wrap: {}) ⇒ Object
- #wrapping_all(inner, method = nil, wrap: {}, required: false) ⇒ Object
Instance Method Details
#help_tag(text) ⇒ Object
49 50 51 |
# File 'lib/default_form/builder/wrap.rb', line 49 def help_tag(text) DefaultForm.config.help_tag.call(self, text) end |
#object_has_errors?(method) ⇒ Boolean
53 54 55 |
# File 'lib/default_form/builder/wrap.rb', line 53 def object_has_errors?(method) object.respond_to?(:errors) && object.errors.respond_to?(:[]) && object.errors[method].present? end |
#offset(css) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/default_form/builder/wrap.rb', line 41 def offset(css) if css.present? content_tag(:div, '', class: css) else ''.html_safe end end |
#wrapping(type, inner, tag: 'div', wrap: {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/default_form/builder/wrap.rb', line 6 def wrapping(type, inner, tag: 'div', wrap: {}) if wrap[type].present? css_ary = wrap[type].split(' > ') css_ary.reverse_each.with_index do |css, index| if index == 0 inner = content_tag(tag, inner, class: css) else inner = content_tag('div', inner, class: css) end end end inner end |
#wrapping_all(inner, method = nil, wrap: {}, required: false) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/default_form/builder/wrap.rb', line 21 def wrapping_all(inner, method = nil, wrap: {}, required: false) if method && object_has_errors?(method) final_css = wrap[:all_error] elsif required final_css = wrap[:all_required] else final_css = wrap[:all] end if final_css if method help_text = default_help(method) inner += help_tag(help_text) if help_text end content_tag(:div, inner, class: final_css) else inner end end |