bootstrap-form 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -8
- data/bootsrap-form.gemspec +3 -1
- data/lib/bootstrap-form/form_helper.rb +18 -9
- data/lib/bootstrap-form/version.rb +1 -1
- data/test/lib/action_view/helpers/form_helper_test.rb +14 -5
- metadata +19 -8
data/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# Bootstrap Form
|
2
2
|
|
3
|
-
Helpers to
|
3
|
+
Form Helpers to make your form inputs [look like this](http://twitter.github.com/bootstrap/#forms).
|
4
4
|
|
5
|
-
|
6
|
-
Bootstrap go here](http://twitter.github.com/bootstrap).
|
5
|
+
Helps you to create beautiful mocks really quickly.
|
7
6
|
|
8
7
|
## Usage
|
9
8
|
|
@@ -15,17 +14,21 @@ Bundle install
|
|
15
14
|
|
16
15
|
bundle install
|
17
16
|
|
18
|
-
|
17
|
+
To make them look even better, I recommend you add this to your
|
18
|
+
application.rb
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
ActionView::Base.field_error_proc = proc { |input, instance| input }
|
21
|
+
|
22
|
+
## Example
|
23
|
+
|
24
|
+
You write this:
|
22
25
|
|
23
26
|
form_for @account do |f|
|
24
27
|
f.bootstrap_text_field :name
|
25
28
|
end
|
26
29
|
|
27
30
|
|
28
|
-
|
31
|
+
You get something like this:
|
29
32
|
|
30
33
|
<div class="clearfix">
|
31
34
|
<label for="account_name">Name</label>
|
@@ -34,6 +37,8 @@ Will generate something like:
|
|
34
37
|
</div>
|
35
38
|
</div>
|
36
39
|
|
40
|
+
Pretty straight forward.
|
41
|
+
|
37
42
|
## Other helpers
|
38
43
|
|
39
44
|
So far, I have implemented the following helpers:
|
@@ -41,6 +46,7 @@ So far, I have implemented the following helpers:
|
|
41
46
|
* bootstrap_text_field
|
42
47
|
* bootstrap_password_field
|
43
48
|
* bootstrap_collection_select
|
49
|
+
* bootstrap_file_field
|
44
50
|
|
45
51
|
Expect more in the near future
|
46
52
|
|
@@ -51,5 +57,4 @@ bootstrap styles.
|
|
51
57
|
|
52
58
|
# TODO
|
53
59
|
|
54
|
-
* Refactor the code, there's lots of things that can be done better
|
55
60
|
* More form inputs
|
data/bootsrap-form.gemspec
CHANGED
@@ -18,7 +18,9 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
|
21
|
+
|
22
|
+
s.add_dependency 'railties', '~> 3.0'
|
23
|
+
s.add_dependency 'actionpack', '~> 3.0'
|
22
24
|
|
23
25
|
s.add_development_dependency "minitest"
|
24
26
|
s.add_development_dependency "rr"
|
@@ -2,43 +2,52 @@ module ActionView
|
|
2
2
|
module Helpers
|
3
3
|
module FormHelper
|
4
4
|
def bootstrap_text_field(object_name, method, options={})
|
5
|
-
bootstrap_clearfix_wrap(object_name, method,
|
5
|
+
bootstrap_clearfix_wrap(object_name, method, text_field(object_name, method, options.dup), options)
|
6
6
|
end
|
7
7
|
|
8
8
|
def bootstrap_password_field(object_name, method, options={})
|
9
|
-
bootstrap_clearfix_wrap(object_name, method,
|
9
|
+
bootstrap_clearfix_wrap(object_name, method, password_field(object_name, method, options.dup), options)
|
10
10
|
end
|
11
11
|
|
12
12
|
def bootstrap_collection_select(object_name, method, collection, value_method, text_method, options = {}, html_options = {})
|
13
|
-
bootstrap_clearfix_wrap(object_name, method,
|
13
|
+
bootstrap_clearfix_wrap(object_name, method, collection_select(object_name, method, collection, value_method, text_method, options.dup, html_options), options)
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def bootstrap_file_field(object_name, method, options={})
|
17
|
+
bootstrap_clearfix_wrap(object_name, method, file_field(object_name, method, options.dup), options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def bootstrap_clearfix_wrap(object_name, method, content, options={})
|
17
21
|
error_messages = options[:object].errors[method]
|
18
22
|
clearfix_tag = error_messages.empty? ? 'clearfix' : 'clearfix error'
|
19
23
|
content_tag(:div, label(object_name, method) +
|
20
|
-
content_tag(:div, content + inline_help_tag(error_messages), class
|
21
|
-
class
|
24
|
+
content_tag(:div, content + inline_help_tag(error_messages), :class => 'input'),
|
25
|
+
:class => clearfix_tag)
|
22
26
|
end
|
23
27
|
|
24
28
|
def inline_help_tag(messages)
|
25
29
|
message_span = ActiveSupport::SafeBuffer.new(" #{messages.join(',')}")
|
26
|
-
messages.empty? ? '' : content_tag(:span, message_span, class
|
30
|
+
messages.empty? ? '' : content_tag(:span, message_span, :class => 'help-inline')
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
32
36
|
class ActionView::Helpers::FormBuilder #:nodoc:
|
33
|
-
def bootstrap_text_field(method, options
|
37
|
+
def bootstrap_text_field(method, options={})
|
34
38
|
@template.bootstrap_text_field(@object_name, method, objectify_options(options))
|
35
39
|
end
|
36
40
|
|
37
|
-
def bootstrap_password_field(method, options
|
41
|
+
def bootstrap_password_field(method, options={})
|
38
42
|
@template.bootstrap_password_field(@object_name, method, objectify_options(options))
|
39
43
|
end
|
40
44
|
|
41
45
|
def bootstrap_collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
|
42
46
|
@template.bootstrap_collection_select(@object_name, method, collection, value_method, text_method, objectify_options(options), html_options)
|
43
47
|
end
|
48
|
+
|
49
|
+
def bootstrap_file_field(method, options={})
|
50
|
+
self.multipart = true
|
51
|
+
@template.bootstrap_file_field(@object_name, method, objectify_options(options))
|
52
|
+
end
|
44
53
|
end
|
@@ -10,7 +10,7 @@ class FormHelperTest < ActionView::TestCase
|
|
10
10
|
stub(object).name { 'Object Name' }
|
11
11
|
|
12
12
|
expected_code = %{<div class="clearfix"><label for="post_name">Name</label><div class="input">content</div></div>}
|
13
|
-
assert_equal expected_code, bootstrap_clearfix_wrap(:post, :name,
|
13
|
+
assert_equal expected_code, bootstrap_clearfix_wrap(:post, :name, content, options)
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_bootstrap_clearfix_wrap_with_errors
|
@@ -22,7 +22,7 @@ class FormHelperTest < ActionView::TestCase
|
|
22
22
|
stub(object).name { 'Object Name' }
|
23
23
|
|
24
24
|
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>}
|
25
|
-
assert_equal expected_code, bootstrap_clearfix_wrap(:post, :name,
|
25
|
+
assert_equal expected_code, bootstrap_clearfix_wrap(:post, :name, content, options)
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_bootstrap_text_field
|
@@ -30,7 +30,7 @@ class FormHelperTest < ActionView::TestCase
|
|
30
30
|
options = { :object => mock }
|
31
31
|
|
32
32
|
mock(self).text_field(:post, :name, options) { text_field }
|
33
|
-
mock(self).bootstrap_clearfix_wrap(:post, :name, options.dup
|
33
|
+
mock(self).bootstrap_clearfix_wrap(:post, :name, text_field, options.dup) { html }
|
34
34
|
assert_equal html, bootstrap_text_field(:post, :name, options)
|
35
35
|
end
|
36
36
|
|
@@ -39,7 +39,7 @@ class FormHelperTest < ActionView::TestCase
|
|
39
39
|
options = { :object => mock }
|
40
40
|
|
41
41
|
mock(self).password_field(:post, :password, options) { password_field }
|
42
|
-
mock(self).bootstrap_clearfix_wrap(:post, :password, options.dup
|
42
|
+
mock(self).bootstrap_clearfix_wrap(:post, :password, password_field, options.dup) { html }
|
43
43
|
assert_equal html, bootstrap_password_field(:post, :password, options)
|
44
44
|
end
|
45
45
|
|
@@ -48,8 +48,17 @@ class FormHelperTest < ActionView::TestCase
|
|
48
48
|
options = { :object => mock }
|
49
49
|
|
50
50
|
mock(self).collection_select(:post, :name, collection, :id, :name, options, {}) { collection_select_html }
|
51
|
-
mock(self).bootstrap_clearfix_wrap(:post, :name, options.dup
|
51
|
+
mock(self).bootstrap_clearfix_wrap(:post, :name, collection_select_html, options.dup) { html }
|
52
52
|
|
53
53
|
assert_equal html, bootstrap_collection_select(:post, :name, collection, :id ,:name, options)
|
54
54
|
end
|
55
|
+
|
56
|
+
def test_bootstrap_file_field
|
57
|
+
html, text_field = mock, mock
|
58
|
+
options = { :object => mock }
|
59
|
+
|
60
|
+
mock(self).file_field(:post, :attachment, options) { text_field }
|
61
|
+
mock(self).bootstrap_clearfix_wrap(:post, :attachment, text_field, options.dup) { html }
|
62
|
+
assert_equal html, bootstrap_file_field(:post, :attachment, options)
|
63
|
+
end
|
55
64
|
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.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,8 +12,8 @@ cert_chain: []
|
|
12
12
|
date: 2011-09-09 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: &
|
15
|
+
name: railties
|
16
|
+
requirement: &70208123840560 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,21 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70208123840560
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: actionpack
|
27
|
+
requirement: &70208123840060 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70208123840060
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: minitest
|
27
|
-
requirement: &
|
38
|
+
requirement: &70208123839660 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: '0'
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *70208123839660
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: rr
|
38
|
-
requirement: &
|
49
|
+
requirement: &70208123839060 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,7 +54,7 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *70208123839060
|
47
58
|
description: Twitter Bootstrap Form helpers
|
48
59
|
email:
|
49
60
|
- david@crowdint.com
|