Module: BootstrapForm::Helpers::Bootstrap
- Included in:
- FormBuilder
- Defined in:
- lib/bootstrap_form/helpers/bootstrap.rb
Instance Method Summary collapse
- #alert_message(title, options = {}) ⇒ Object
- #error_summary ⇒ Object
- #errors_on(name, options = {}) ⇒ Object
- #input_group_class(add_on_content) ⇒ Object
- #prepend_and_append_input(options, &block) ⇒ Object
- #primary(name = nil, options = {}) ⇒ Object
- #static_class ⇒ Object
- #static_control(*args, &block) ⇒ Object
- #submit(name = nil, options = {}) ⇒ Object
Instance Method Details
#alert_message(title, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 14 def (title, = {}) css = [:class] || 'alert alert-danger' if object.respond_to?(:errors) && object.errors..any? content_tag :div, class: css do concat content_tag :p, title concat error_summary unless [:error_summary] == false end end end |
#error_summary ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 25 def error_summary content_tag :ul, class: 'rails-bootstrap-forms-error-summary' do object.errors..each do |error| concat content_tag(:li, error) end end end |
#errors_on(name, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 33 def errors_on(name, = {}) if has_error?(name) hide_attribute_name = [:hide_attribute_name] || false content_tag :div, class: "alert alert-danger" do if hide_attribute_name object.errors[name].join(", ") else object.errors.(name).join(", ") end end end end |
#input_group_class(add_on_content) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 72 def input_group_class(add_on_content) if add_on_content.match /btn/ 'input-group-btn' else 'input-group-addon' end end |
#prepend_and_append_input(options, &block) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 62 def prepend_and_append_input(, &block) = .extract!(:prepend, :append) input = capture(&block) input = content_tag(:span, [:prepend], class: input_group_class([:prepend])) + input if [:prepend] input << content_tag(:span, [:append], class: input_group_class([:append])) if [:append] input = content_tag(:div, input, class: "input-group") unless .empty? input end |
#primary(name = nil, options = {}) ⇒ Object
9 10 11 12 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 9 def primary(name = nil, = {}) .merge! class: 'btn btn-primary' submit(name, ) end |
#static_class ⇒ Object
80 81 82 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 80 def static_class "form-control-static" end |
#static_control(*args, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 47 def static_control(*args, &block) = args. name = args.first html = if block_given? capture(&block) else object.send(name) end form_group_builder(name, ) do content_tag(:p, html, class: static_class) end end |
#submit(name = nil, options = {}) ⇒ Object
4 5 6 7 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 4 def submit(name = nil, = {}) .merge! class: 'btn btn-default' unless .has_key? :class super(name, ) end |