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.
@@ -1,8 +1,3 @@
1
1
  require "bootstrap-form/version"
2
2
  require "bootstrap-form/form_helper"
3
3
 
4
- module Bootstrap
5
- module Form
6
- # Your code goes here...
7
- end
8
- end
@@ -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
- error_messages = options[:object].errors[method]
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
- content_tag(:div,
22
- label(object_name, method) +
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
- messages.empty? ? '' : content_tag(:span, messages.join(','), class: 'help-inline')
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,5 +1,5 @@
1
1
  module Bootstrap
2
2
  module Form
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -1,47 +1,44 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class FormHelperTest < ActionView::TestCase
4
- def test_bootstrap_text_field
4
+ def test_bootstrap_clearfix_wrap
5
5
  object = mock
6
- errors = { :name => [] }
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"><input id="post_name" name="post[name]" size="30" type="text" value="Object Name" /></div></div>}
12
- assert_equal(expected_code, bootstrap_text_field(:post, :name, options))
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 test_bootstrap_text_field_with_errors
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"><input id="post_name" name="post[name]" size="30" type="text" value="Object Name" /><span class="help-inline">can't be blank</span></div></div>}
23
- assert_equal(expected_code, bootstrap_text_field(:post, :name, options))
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 test_bootstrap_password_field
27
- object = mock
28
- errors = { :name => [] }
29
- stub(object).errors { errors }
30
- stub(object).name { 'Object Name' }
31
- options = { :object => object }
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 test_bootstrap_password_field_with_errors
38
- object = mock
39
- errors = {:name => ["can't be blank"]}
40
- stub(object).errors { errors }
41
- stub(object).name { 'Object Name' }
42
- options = { :object => object }
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.1
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: &70143631856780 !ruby/object:Gem::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: *70143631856780
24
+ version_requirements: *70319989305380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: minitest
27
- requirement: &70143631856360 !ruby/object:Gem::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: *70143631856360
35
+ version_requirements: *70319989286820
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rr
38
- requirement: &70143631855900 !ruby/object:Gem::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: *70143631855900
46
+ version_requirements: *70319985555820
47
47
  description: Twitter Bootstrap Form helpers
48
48
  email:
49
49
  - david@crowdint.com