This repository has been archived by the owner on Oct 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 217
/
wrapping.rb
76 lines (65 loc) · 2.02 KB
/
wrapping.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
module FormtasticBootstrap
module Inputs
module Base
module Wrapping
include Formtastic::Inputs::Base::Wrapping
def bootstrap_wrapping(&block)
input_content = [
add_on_content(options[:prepend]),
options[:prepend_content],
yield,
add_on_content(options[:append]),
options[:append_content],
hint_html
].compact.join("\n").html_safe
form_group_wrapping do
control_label_html <<
controls_wrapping do
if prepended_or_appended?(options)
template.content_tag(:div, :class => add_on_wrapper_classes(options).join(" ")) do
input_content
end
else
input_content
end
end
end
end
def prepended_or_appended?(options)
options[:prepend] || options[:prepend_content] || options[:append] || options[:append_content]
end
def add_on_content(content)
return nil unless content
template.content_tag(:span, content, :class => 'add-on')
end
def form_group_wrapping(&block)
template.content_tag(:div,
template.capture(&block).html_safe,
wrapper_html_options
)
end
def controls_wrapping(&block)
template.content_tag(:div,
[template.capture(&block), error_html].join("\n").html_safe,
controls_wrapper_html_options
)
end
def controls_wrapper_html_options
{
:class => "controls"
}
end
def wrapper_html_options
super.tap do |options|
options[:class] << " form-group"
end
end
def add_on_wrapper_classes(options)
[:prepend, :append, :prepend_content, :append_content].map do |key|
"input-#{key.to_s.gsub('_content', '')}" if options[key]
end
end
end
end
end
end