bootstrap-form 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -64,6 +64,7 @@ Then, you get something like this:
64
64
  * bootstrap_collection_select
65
65
  * bootstrap_file_field
66
66
  * bootstrap_text_area
67
+ * bootstrap_email_field
67
68
 
68
69
  ## Error handling
69
70
 
@@ -1,37 +1,54 @@
1
1
  module ActionView
2
2
  module Helpers
3
3
  module FormHelper
4
+
5
+ BOOTSTRAP_OPTIONS = [:label, :hint].freeze
6
+
4
7
  def bootstrap_text_field(object_name, method, options={})
5
- bootstrap_clearfix_wrap(object_name, method, text_field(object_name, method, options.dup), options)
8
+ bootstrap_clearfix_wrap(object_name, method, text_field(object_name, method, extract_input_options(options)), options)
9
+ end
10
+
11
+ def bootstrap_email_field(object_name, method, options={})
12
+ bootstrap_clearfix_wrap(object_name, method, email_field(object_name, method, extract_input_options(options)), options)
6
13
  end
7
14
 
8
15
  def bootstrap_password_field(object_name, method, options={})
9
- bootstrap_clearfix_wrap(object_name, method, password_field(object_name, method, options.dup), options)
16
+ bootstrap_clearfix_wrap(object_name, method, password_field(object_name, method, extract_input_options(options)), options)
10
17
  end
11
18
 
12
19
  def bootstrap_collection_select(object_name, method, collection, value_method, text_method, options = {}, html_options = {})
13
- bootstrap_clearfix_wrap(object_name, method, collection_select(object_name, method, collection, value_method, text_method, options.dup, html_options), options)
20
+ bootstrap_clearfix_wrap(object_name, method, collection_select(object_name, method, collection, value_method, text_method, extract_input_options(options), html_options), options)
14
21
  end
15
22
 
16
23
  def bootstrap_file_field(object_name, method, options={})
17
- bootstrap_clearfix_wrap(object_name, method, file_field(object_name, method, options.dup), options)
24
+ bootstrap_clearfix_wrap(object_name, method, file_field(object_name, method, extract_input_options(options)), options)
18
25
  end
19
26
 
20
27
  def bootstrap_text_area(object_name, method, options={})
21
- bootstrap_clearfix_wrap(object_name, method, text_area(object_name, method, options.dup), options)
28
+ bootstrap_clearfix_wrap(object_name, method, text_area(object_name, method, extract_input_options(options)), options)
22
29
  end
23
30
 
24
31
  def bootstrap_clearfix_wrap(object_name, method, content, options={})
25
32
  error_messages = options[:object].errors[method]
26
- clearfix_tag = error_messages.empty? ? 'clearfix' : 'clearfix error'
33
+ clearfix_tag = error_messages.blank? ? 'clearfix' : 'clearfix error'
34
+ inline_help = inline_help_tag(error_messages.presence || options[:hint])
35
+
27
36
  content_tag(:div, label(object_name, method, options[:label]) +
28
- content_tag(:div, content + inline_help_tag(error_messages), :class => 'input'),
37
+ content_tag(:div, content + inline_help, :class => 'input'),
29
38
  :class => clearfix_tag)
30
39
  end
31
40
 
32
41
  def inline_help_tag(messages)
33
- message_span = ActiveSupport::SafeBuffer.new(" #{messages.join(',')}")
34
- messages.empty? ? '' : content_tag(:span, message_span, :class => 'help-inline')
42
+ messages = Array.wrap(messages)
43
+ return '' if messages.empty?
44
+ message_span = ActiveSupport::SafeBuffer.new(" #{messages.to_sentence}")
45
+ content_tag(:span, message_span, :class => 'help-inline')
46
+ end
47
+
48
+ private
49
+
50
+ def extract_input_options(options)
51
+ options.except(*BOOTSTRAP_OPTIONS)
35
52
  end
36
53
  end
37
54
  end
@@ -42,6 +59,10 @@ class ActionView::Helpers::FormBuilder #:nodoc:
42
59
  @template.bootstrap_text_field(@object_name, method, objectify_options(options))
43
60
  end
44
61
 
62
+ def bootstrap_email_field(method, options={})
63
+ @template.bootstrap_email_field(@object_name, method, objectify_options(options))
64
+ end
65
+
45
66
  def bootstrap_password_field(method, options={})
46
67
  @template.bootstrap_password_field(@object_name, method, objectify_options(options))
47
68
  end
@@ -1,5 +1,5 @@
1
1
  module Bootstrap
2
2
  module Form
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
@@ -37,6 +37,42 @@ class FormHelperTest < ActionView::TestCase
37
37
  assert_equal expected_code, bootstrap_clearfix_wrap(:post, :name, content, options)
38
38
  end
39
39
 
40
+ def test_bootstrap_clearfix_wrap_with_many_errors
41
+ object = mock
42
+ errors = { :name => ["has already been taken", "is reserved", "must be odd"] }
43
+ options = { :object => object }
44
+ content = ::ActiveSupport::SafeBuffer.new('content')
45
+ stub(object).errors { errors }
46
+ stub(object).name { 'Object Name' }
47
+
48
+ expected_code = %{<div class="clearfix error"><label for="post_name">Name</label><div class="input">content<span class="help-inline"> has already been taken, is reserved, and must be odd</span></div></div>}
49
+ assert_equal expected_code, bootstrap_clearfix_wrap(:post, :name, content, options)
50
+ end
51
+
52
+ def test_bootstrap_clearfix_wrap_with_hint
53
+ object = mock
54
+ errors = {}
55
+ options = { :object => object, :hint => "format matters" }
56
+ content = ::ActiveSupport::SafeBuffer.new('content')
57
+ stub(object).errors { errors }
58
+ stub(object).name { 'Object Name' }
59
+
60
+ expected_code = %{<div class="clearfix"><label for="post_name">Name</label><div class="input">content<span class="help-inline"> format matters</span></div></div>}
61
+ assert_equal expected_code, bootstrap_clearfix_wrap(:post, :name, content, options)
62
+ end
63
+
64
+ def test_bootstrap_clearfix_wrap_with_hint_and_errors
65
+ object = mock
66
+ errors = { :name => ["can't be blank"] }
67
+ options = { :object => object, :hint => "format matters" }
68
+ content = ::ActiveSupport::SafeBuffer.new('content')
69
+ stub(object).errors { errors }
70
+ stub(object).name { 'Object Name' }
71
+
72
+ expected_code = %{<div class="clearfix error"><label for="post_name">Name</label><div class="input">content<span class="help-inline"> can't be blank</span></div></div>}
73
+ assert_equal expected_code, bootstrap_clearfix_wrap(:post, :name, content, options)
74
+ end
75
+
40
76
  def test_bootstrap_text_field
41
77
  html, text_field = mock, mock
42
78
  options = { :object => mock }
@@ -46,6 +82,15 @@ class FormHelperTest < ActionView::TestCase
46
82
  assert_equal html, bootstrap_text_field(:post, :name, options)
47
83
  end
48
84
 
85
+ def test_bootstrap_email_field
86
+ html, email_field = mock, mock
87
+ options = { :object => mock }
88
+
89
+ mock(self).email_field(:post, :email, options) { email_field }
90
+ mock(self).bootstrap_clearfix_wrap(:post, :email, email_field, options.dup) { html }
91
+ assert_equal html, bootstrap_email_field(:post, :email, options)
92
+ end
93
+
49
94
  def test_bootstrap_password_field
50
95
  html, password_field = mock, mock
51
96
  options = { :object => mock }
@@ -82,5 +127,14 @@ class FormHelperTest < ActionView::TestCase
82
127
  mock(self).bootstrap_clearfix_wrap(:post, :description, text_area, options.dup) { html }
83
128
  assert_equal html, bootstrap_text_area(:post, :description, options)
84
129
  end
130
+
131
+ def test_ignore_bootstrap_options
132
+ html, text_area = mock, mock
133
+ options = { :object => mock, :label => "Custom", :hint => "be careful" }
134
+
135
+ mock(self).text_area(:post, :description, options.except(:label, :hint)) { text_area }
136
+ mock(self).bootstrap_clearfix_wrap(:post, :description, text_area, options.dup) { html }
137
+ assert_equal html, bootstrap_text_area(:post, :description, options)
138
+ end
85
139
 
86
140
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-15 00:00:00.000000000Z
12
+ date: 2011-10-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70310125359080 !ruby/object:Gem::Requirement
16
+ requirement: &70116894263240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70310125359080
24
+ version_requirements: *70116894263240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: actionpack
27
- requirement: &70310125358580 !ruby/object:Gem::Requirement
27
+ requirement: &70116894262740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70310125358580
35
+ version_requirements: *70116894262740
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: minitest
38
- requirement: &70310125358200 !ruby/object:Gem::Requirement
38
+ requirement: &70116894262360 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70310125358200
46
+ version_requirements: *70116894262360
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rr
49
- requirement: &70310125357740 !ruby/object:Gem::Requirement
49
+ requirement: &70116894261900 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70310125357740
57
+ version_requirements: *70116894261900
58
58
  description: Twitter Bootstrap Form helpers
59
59
  email:
60
60
  - david@crowdint.com