bootstrap-form 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
data/lib/bootstrap-form.rb
CHANGED
@@ -2,33 +2,24 @@ module ActionView
|
|
2
2
|
module Helpers
|
3
3
|
module FormHelper
|
4
4
|
def bootstrap_text_field(object_name, method, options={})
|
5
|
-
|
6
|
-
clearfix_tag = error_messages.empty? ? 'clearfix' : 'clearfix error'
|
7
|
-
|
8
|
-
content_tag(:div,
|
9
|
-
label(object_name, method) +
|
10
|
-
content_tag(:div,
|
11
|
-
text_field(object_name, method, options) +
|
12
|
-
inline_help_tag(error_messages),
|
13
|
-
class: 'input'),
|
14
|
-
class: clearfix_tag)
|
5
|
+
bootstrap_clearfix_wrap(object_name, method, options.dup, text_field(object_name, method, options))
|
15
6
|
end
|
16
7
|
|
17
8
|
def bootstrap_password_field(object_name, method, options={})
|
9
|
+
bootstrap_clearfix_wrap(object_name, method, options.dup, password_field(object_name, method, options))
|
10
|
+
end
|
11
|
+
|
12
|
+
def bootstrap_clearfix_wrap(object_name, method, options={}, content)
|
18
13
|
error_messages = options[:object].errors[method]
|
19
14
|
clearfix_tag = error_messages.empty? ? 'clearfix' : 'clearfix error'
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
content_tag(:div,
|
24
|
-
password_field(object_name, method, options) +
|
25
|
-
inline_help_tag(error_messages),
|
26
|
-
class: 'input'),
|
27
|
-
class: clearfix_tag)
|
15
|
+
content_tag(:div, label(object_name, method) +
|
16
|
+
content_tag(:div, content + inline_help_tag(error_messages), class: 'input'),
|
17
|
+
class: clearfix_tag)
|
28
18
|
end
|
29
19
|
|
30
20
|
def inline_help_tag(messages)
|
31
|
-
|
21
|
+
message_span = ActiveSupport::SafeBuffer.new(" #{messages.join(',')}")
|
22
|
+
messages.empty? ? '' : content_tag(:span, message_span, class: 'help-inline')
|
32
23
|
end
|
33
24
|
end
|
34
25
|
end
|
@@ -1,47 +1,44 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class FormHelperTest < ActionView::TestCase
|
4
|
-
def
|
4
|
+
def test_bootstrap_clearfix_wrap
|
5
5
|
object = mock
|
6
|
-
errors = {
|
6
|
+
errors = {:name => []}
|
7
7
|
stub(object).errors { errors }
|
8
8
|
stub(object).name { 'Object Name' }
|
9
9
|
options = { :object => object }
|
10
|
+
content = ::ActiveSupport::SafeBuffer.new('content')
|
11
|
+
# content = ''
|
10
12
|
|
11
|
-
expected_code = %{<div class="clearfix"><label for="post_name">Name</label><div class="input"
|
12
|
-
assert_equal
|
13
|
+
expected_code = %{<div class="clearfix"><label for="post_name">Name</label><div class="input">content</div></div>}
|
14
|
+
assert_equal expected_code, bootstrap_clearfix_wrap(:post, :name, options, content)
|
13
15
|
end
|
14
16
|
|
15
|
-
def
|
17
|
+
def test_bootstrap_clearfix_wrap_with_errors
|
16
18
|
object = mock
|
17
19
|
errors = {:name => ["can't be blank"]}
|
18
20
|
stub(object).errors { errors }
|
19
21
|
stub(object).name { 'Object Name' }
|
20
22
|
options = { :object => object }
|
23
|
+
content = ::ActiveSupport::SafeBuffer.new('content')
|
21
24
|
|
22
|
-
expected_code = %{<div class="clearfix error"><label for="post_name">Name</label><div class="input"
|
23
|
-
assert_equal
|
25
|
+
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>}
|
26
|
+
assert_equal expected_code, bootstrap_clearfix_wrap(:post, :name, options, content)
|
24
27
|
end
|
25
28
|
|
26
|
-
def
|
27
|
-
object
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
expected_code = %{<div class="clearfix"><label for="post_name">Name</label><div class="input"><input id="post_name" name="post[name]" size="30" type="password" /></div></div>}
|
34
|
-
assert_equal(expected_code, bootstrap_password_field(:post, :name, options))
|
29
|
+
def test_bootstrap_text_field
|
30
|
+
options = { :object => mock }
|
31
|
+
html, text_field = mock, mock
|
32
|
+
mock(self).text_field(:post, :name, options) { text_field }
|
33
|
+
mock(self).bootstrap_clearfix_wrap(:post, :name, options.dup, text_field) { html }
|
34
|
+
assert_equal html, bootstrap_text_field(:post, :name, options)
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
object
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
expected_code = %{<div class="clearfix error"><label for="post_name">Name</label><div class="input"><input id="post_name" name="post[name]" size="30" type="password" /><span class="help-inline">can't be blank</span></div></div>}
|
45
|
-
assert_equal(expected_code, bootstrap_password_field(:post, :name, options))
|
37
|
+
def test_bootstrap_password_field
|
38
|
+
options = { :object => mock }
|
39
|
+
html, password_field = mock, mock
|
40
|
+
mock(self).password_field(:post, :name, options) { password_field }
|
41
|
+
mock(self).bootstrap_clearfix_wrap(:post, :name, options.dup, password_field) { html }
|
42
|
+
assert_equal html, bootstrap_password_field(:post, :name, options)
|
46
43
|
end
|
47
44
|
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.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-07 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70319989305380 !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: *
|
24
|
+
version_requirements: *70319989305380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: minitest
|
27
|
-
requirement: &
|
27
|
+
requirement: &70319989286820 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70319989286820
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rr
|
38
|
-
requirement: &
|
38
|
+
requirement: &70319985555820 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70319985555820
|
47
47
|
description: Twitter Bootstrap Form helpers
|
48
48
|
email:
|
49
49
|
- david@crowdint.com
|