bs_form_builder 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb43b999ee5f0362b1544f99f3b1e442240f57d9
4
- data.tar.gz: 6c86a155cf8abb5a4731a1a932e42f33e2ab4734
3
+ metadata.gz: 004500afba4cd769f5b1c2617bcf5a495298dd80
4
+ data.tar.gz: 850351fd8aec0e70359c3efb60fa3d87c6d5f782
5
5
  SHA512:
6
- metadata.gz: 9427f597d16817ca1669966b6e7861de9ca75dea6901f0c1b55c38727a84be763219105c2009955c2cf6c1a67e0a44d185bf5fae4a474f338e15ef3f6e334a35
7
- data.tar.gz: d4b921c2cce23feea98b32e5500d2c56e8a005280c0d60ec81833a296bbd080308a044139780d7feeb90b740c0da890121563bb6adb8260cf07d5286bca0518a
6
+ metadata.gz: 7c648e99f138a9876a7915d4087aa9ac42b4c4ef18aab73365023fa23a60fe19891b8ce29fe64e8f537b91d786a12761ac77c11783038aca649a9d8cc1fa236d
7
+ data.tar.gz: 4867b1a3bc53223583a536486268f9744bb0f9cfc4376a6e7c49822d11a28f47c4e258467fe41fe69b3b7892083c6e21123ce2c12341001393b683361f69833a
@@ -2,21 +2,21 @@
2
2
  #
3
3
  class BootstrapFormBuilder::HorizontalFormBuilder < ActionView::Helpers::FormBuilder
4
4
  def email_field(name, opts = {})
5
- form_group(name) do
5
+ form_group(name, opts.slice(:label_options, :group_options, :tip_options)) do
6
6
  super(name, opts.reverse_merge(:class => 'form-control',
7
7
  :placeholder => help(name)))
8
8
  end
9
9
  end
10
10
 
11
11
  def text_field(name, opts = {})
12
- form_group(name) do
12
+ form_group(name, opts.slice(:label_options, :group_options, :tip_options)) do
13
13
  super(name, opts.reverse_merge(:class => 'form-control',
14
14
  :placeholder => help(name)))
15
15
  end
16
16
  end
17
17
 
18
18
  def search_field(name, opts = {})
19
- form_group(name) do
19
+ form_group(name, opts.slice(:label_options, :group_options, :tip_options)) do
20
20
  @template.content_tag(:div,
21
21
  super(name, opts.reverse_merge(:class => 'form-control',
22
22
  :placeholder => help(name))) +
@@ -28,28 +28,28 @@ class BootstrapFormBuilder::HorizontalFormBuilder < ActionView::Helpers::FormBui
28
28
  end
29
29
 
30
30
  def password_field(name, opts = {})
31
- form_group(name) do
31
+ form_group(name, opts.slice(:label_options, :group_options, :tip_options)) do
32
32
  super(name, opts.reverse_merge(:class => 'form-control',
33
33
  :placeholder => help(name)))
34
34
  end
35
35
  end
36
36
 
37
37
  def date_field(name, opts = {})
38
- form_group(name) do
38
+ form_group(name, opts.slice(:label_options, :group_options, :tip_options)) do
39
39
  super(name, opts.reverse_merge(:class => 'form-control',
40
40
  :placeholder => help(name)))
41
41
  end
42
42
  end
43
43
 
44
44
  def number_field(name, opts = {})
45
- form_group(name) do
45
+ form_group(name, opts.slice(:label_options, :group_options, :tip_options)) do
46
46
  super(name, opts.reverse_merge(:class => 'form-control',
47
47
  :placeholder => help(name)))
48
48
  end
49
49
  end
50
50
 
51
51
  def check_box(name, opts = {})
52
- form_group(name) do
52
+ form_group(name, opts.slice(:label_options, :group_options, :tip_options)) do
53
53
  @template.content_tag(:div,
54
54
  @template.content_tag(:label, super(name, opts) + (help(name) || "&nbsp;").html_safe),
55
55
  :class => 'checkbox')
@@ -69,7 +69,7 @@ class BootstrapFormBuilder::HorizontalFormBuilder < ActionView::Helpers::FormBui
69
69
  #}
70
70
  #
71
71
  def justified_radio_button_group(name, button_options, opts = {})
72
- form_group(name) do
72
+ form_group(name, opts.slice(:label_options, :group_options, :tip_options)) do
73
73
  buttons = button_options.map do |button|
74
74
  @template.content_tag(:div, radio_button_label(name, button), :class => 'btn-group')
75
75
  end.join("\n").html_safe
@@ -82,7 +82,7 @@ class BootstrapFormBuilder::HorizontalFormBuilder < ActionView::Helpers::FormBui
82
82
  end
83
83
 
84
84
  def radio_button_group(name, button_options, opts = {})
85
- form_group(name) do
85
+ form_group(name, opts.slice(:label_options, :group_options, :tip_options)) do
86
86
  buttons = button_options.map do |button|
87
87
  radio_button_label(name, button)
88
88
  end.join("\n").html_safe
@@ -103,29 +103,31 @@ class BootstrapFormBuilder::HorizontalFormBuilder < ActionView::Helpers::FormBui
103
103
  end
104
104
 
105
105
  def select(name, choices, options = {}, html_options = {})
106
- form_group(name) do
106
+ form_group(name, options.slice(:label_options, :group_options, :tip_options)) do
107
107
  super(name, choices, options, html_options.reverse_merge(:class => 'form-control'))
108
108
  end
109
109
  end
110
110
 
111
111
  def text_area(name, opts = {})
112
- form_group(name) do
112
+ form_group(name, opts.slice(:label_options, :group_options, :tip_options)) do
113
113
  super(name, opts.reverse_merge(:class => 'form-control',
114
114
  :placeholder => help(name)))
115
115
  end
116
116
  end
117
117
 
118
- def form_group(name, &block)
119
- classes = ['form-group']
118
+ def form_group(name, options = {}, &block)
119
+ group_options = options.fetch(:group_options, {})
120
+ classes = Array(group_options[:class]) << 'form-group'
120
121
 
121
122
  if @object.errors.has_key?(name)
122
123
  classes << 'has-error'
123
124
  end
124
125
 
125
126
  @template.content_tag(:div,
126
- label(name) +
127
- col_wrap(block.call + errors(name)),
128
- :class => classes.join(' '))
127
+ label(name, options.fetch(:label_options, {})) +
128
+ col_wrap(block.call + errors(name)) +
129
+ tip(name, options.fetch(:tip_options, {})),
130
+ group_options.merge(:class => classes.join(' ')))
129
131
  end
130
132
 
131
133
  def col_wrap(html)
@@ -133,7 +135,9 @@ class BootstrapFormBuilder::HorizontalFormBuilder < ActionView::Helpers::FormBui
133
135
  end
134
136
 
135
137
  def label(name, opts = {})
136
- super(name, opts.reverse_merge(:class => 'control-label'))
138
+ classes = Array(opts.fetch(:class, ''))
139
+ classes << 'control-label'
140
+ super(name, opts.merge(:class => classes.join(' ')))
137
141
  end
138
142
 
139
143
  def errors(name)
@@ -154,6 +158,14 @@ class BootstrapFormBuilder::HorizontalFormBuilder < ActionView::Helpers::FormBui
154
158
  end
155
159
  end
156
160
 
161
+ def tip(name, options = {})
162
+ i18n_name = "helpers.tips.#{object_name}.#{name}"
163
+ if I18n.exists?(i18n_name)
164
+ options[:class] = (Array(options[:class]) + ['help-block']).join(' ')
165
+ @template.content_tag(:span, I18n.t(i18n_name), options)
166
+ end
167
+ end
168
+
157
169
  def cancel_button(cancel_path)
158
170
  @template.link_to(I18n.t('helpers.button.cancel'),
159
171
  cancel_path,
@@ -1,3 +1,3 @@
1
1
  module BootstrapFormBuilder
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bs_form_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Geoghegan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-24 00:00:00.000000000 Z
11
+ date: 2014-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview