Module: BootstrapForms::Helpers::FormTagHelper

Includes:
Wrappers
Defined in:
lib/bootstrap_forms/helpers/form_tag_helper.rb

Instance Method Summary collapse

Instance Method Details

#bootstrap_actions(&block) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/bootstrap_forms/helpers/form_tag_helper.rb', line 71

def bootstrap_actions(&block)
  # This somethat redundant arrangement is necessary (according to the test cases) to make this call work with  Slim, ERB, and HAML. 
  # Though oddly enough this Slim block test still fails yet works in production. Not sure why this is but, nevertheless
  # we keep this in place.
  if block_given?
    (:div, :class => 'form-actions', &block)
  else
    content = [bootstrap_submit_tag, bootstrap_cancel_tag].join(' ').html_safe
    (:div, content, :class => 'form-actions')
  end
end

#bootstrap_button_tag(*args) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/bootstrap_forms/helpers/form_tag_helper.rb', line 45

def bootstrap_button_tag(*args)
  options = args.extract_options!
  options[:class] ||= 'btn btn-primary'

  name = args.shift || 'Submit'
  # button_tag() renders <input type="button">
  (:button, name, options).html_safe
end

#bootstrap_cancel_tag(*args) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/bootstrap_forms/helpers/form_tag_helper.rb', line 62

def bootstrap_cancel_tag(*args)
  options = args.extract_options!
  options[:class] ||= 'btn cancel'
  options[:back] ||= 'javascript:history.go(-1)'

  name = args.shift || 'Cancel'
  link_to(name, options[:back], options.except(:back)).html_safe
end

#bootstrap_submit_tag(*args) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/bootstrap_forms/helpers/form_tag_helper.rb', line 54

def bootstrap_submit_tag(*args)
  options = args.extract_options!
  options[:class] ||= 'btn btn-primary'

  name = args.shift || 'Submit'
  submit_tag(name, options).html_safe
end

#uneditable_input_tag(name, *args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bootstrap_forms/helpers/form_tag_helper.rb', line 24

def uneditable_input_tag(name, *args)
  @name = name
  @field_options = args.extract_options!
  @args = args

  # Padrino will always generate a label's for attribute, this results in invalid HTML.
  # label_field will use :id as the for attribute if present.
  @field_options[:id] = nil unless @field_options[:id]

  control_group_div do
    label_field << input_div do
      # Due to how Padrino implements ERB this block (and others) will be called many (4?) times.
      # To avoid string accumulation under :class -and to keep option passing somewhat straightforward- we just dup()
      options = @field_options.dup
      options[:class] = [options[:class], 'uneditable-input'].compact.join " "

      (:span,  escape_html(options[:value]), objectify_options(options.except(:value)))
    end
  end.html_safe
end