Module: BootstrapForm::Helpers::Bootstrap

Included in:
FormBuilder
Defined in:
lib/bootstrap_form/helpers/bootstrap.rb

Instance Method Summary collapse

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 alert_message(title, options = {})
  css = options[:class] || 'alert alert-danger'

  if object.respond_to?(:errors) && object.errors.full_messages.any?
     :div, class: css do
      concat  :p, title
      concat error_summary unless options[:error_summary] == false
    end
  end
end

#error_summaryObject



25
26
27
28
29
30
31
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 25

def error_summary
   :ul, class: 'rails-bootstrap-forms-error-summary' do
    object.errors.full_messages.each do |error|
      concat (: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, options = {})
  if has_error?(name)
    hide_attribute_name = options[:hide_attribute_name] || false

     :div, class: "alert alert-danger" do
      if hide_attribute_name
        object.errors[name].join(", ")
      else
        object.errors.full_messages_for(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(options, &block)
  options = options.extract!(:prepend, :append)
  input = capture(&block)

  input = (:span, options[:prepend], class: input_group_class(options[:prepend])) + input if options[:prepend]
  input << (:span, options[:append], class: input_group_class(options[:append])) if options[:append]
  input = (:div, input, class: "input-group") unless options.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, options = {})
  options.merge! class: 'btn btn-primary'
  submit(name, options)
end

#static_classObject



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)
  options = args.extract_options!
  name = args.first

  html = if block_given?
    capture(&block)
  else
    object.send(name)
  end

  form_group_builder(name, options) do
    (: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, options = {})
  options.merge! class: 'btn btn-default' unless options.has_key? :class
  super(name, options)
end