mediatainment-bootstrap-form 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27e04d509a138726a643f04f7a3f6cbbdee8c9d3
4
+ data.tar.gz: 65d8d281a0a6af71294ebf05ee282074fe20b5fb
5
+ SHA512:
6
+ metadata.gz: 534335bfe1b343ad4e31fbf327e3668f80c095c7cf0ad3f1def4eba0e0df7980ce9d58b983312e3baeb47ba05d11dcf9b653748e4fe91bdec42bd9a09a531b36
7
+ data.tar.gz: 16a525b9f8fbc77a3fa2c5ba92c8b629fdee3820d70cc5d944229858dec73eb044881a8d5616afd0972f5deaa5f2d96cb8371b68007a41e9bc54f957cde12fdb
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ gemfile:
5
+ - Gemfile.rails.3.2
6
+ - Gemfile.rails.4.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bootstrap-form.gemspec
4
+ gemspec
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bootstrap-form.gemspec
4
+ gemspec
5
+
6
+ gem 'railties', '~> 3.2'
7
+ gem 'actionpack', '~> 3.2'
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bootstrap-form.gemspec
4
+ gemspec
5
+
6
+ gem 'railties', '4.0.0.beta1'
7
+ gem 'actionpack', '4.0.0.beta1'
@@ -0,0 +1,83 @@
1
+ # Bootstrap Form
2
+
3
+ [![Build Status](https://travis-ci.org/dabit/bootstrap-form.png?branch=master)](https://travis-ci.org/dabit/bootstrap-form)
4
+
5
+ Form Helpers to make your form inputs [look like this](http://twitter.github.com/bootstrap/#forms).
6
+
7
+ Helps you to create beautiful mocks really quickly.
8
+
9
+ Works with Bootstrap 2.3.0 and Rails 3.2+ (including Rails 4)
10
+
11
+ ## Usage
12
+
13
+ Add the gem to your Gemfile
14
+
15
+ gem 'bootstrap-form'
16
+
17
+ Bundle install
18
+
19
+ bundle install
20
+
21
+ To make them look even better, I recommend you add this to your
22
+ application.rb
23
+
24
+ ActionView::Base.field_error_proc = proc { |input, instance| input }
25
+
26
+ ## Example
27
+
28
+ You write this:
29
+
30
+ form_for @account do |f|
31
+ f.bootstrap_text_field :name
32
+ end
33
+
34
+
35
+ You get something like this:
36
+
37
+ <div class="control-group">
38
+ <label class="control-label" for="account_name">Name</label>
39
+ <div class="controls">
40
+ <input id="account_name" name="account_name" size="30" type="text">
41
+ </div>
42
+ </div>
43
+
44
+ Pretty straight forward.
45
+
46
+ ## Custom Label
47
+
48
+ You can specify a custom label for the input by setting the label
49
+ option:
50
+
51
+ form_for @account do |f|
52
+ f.bootstrap_text_field :name, :label => 'A custom label'
53
+ end
54
+
55
+ Then, you get something like this:
56
+
57
+ <div class="control-group">
58
+ <label class="control-label" for="account_name">A custom label</label>
59
+ <div class="controls">
60
+ <input id="account_name" name="account_name" size="30" type="text">
61
+ </div>
62
+ </div>
63
+
64
+ ## Current Helpers List
65
+
66
+ * bootstrap_text_field
67
+ * bootstrap_password_field
68
+ * bootstrap_collection_select
69
+ * bootstrap_select
70
+ * bootstrap_file_field
71
+ * bootstrap_text_area
72
+ * bootstrap_email_field
73
+
74
+ ## Error handling
75
+
76
+ All fields will automatically add the classes to show errors with Twitter
77
+ bootstrap styles.
78
+
79
+ ## TODO
80
+
81
+ Coming soon:
82
+
83
+ * More form inputs
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ task :default => :test
6
+
7
+ Rake::TestTask.new(:test) do |test|
8
+ test.libs << 'lib' << 'test'
9
+ test.pattern = 'test/**/*_test.rb'
10
+ test.verbose = true
11
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bootstrap-form/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mediatainment-bootstrap-form"
7
+ s.version = Bootstrap::Form::VERSION
8
+ s.authors = ["David Padilla"]
9
+ s.email = ["mail@mediatainment-productions.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Twitter Bootstrap Form helpers}
12
+ s.description = %q{Twitter Bootstrap Form helpers}
13
+
14
+ s.rubyforge_project = "bootstrap-form"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+
22
+ s.add_dependency 'railties', '> 3.2'
23
+ s.add_dependency 'actionpack', '> 3.2'
24
+
25
+ s.add_development_dependency "minitest"
26
+ s.add_development_dependency "rr"
27
+ end
@@ -0,0 +1,3 @@
1
+ require "bootstrap-form/version"
2
+ require "bootstrap-form/form_helper"
3
+
@@ -0,0 +1,90 @@
1
+ module ActionView
2
+ module Helpers
3
+ module FormHelper
4
+
5
+ BOOTSTRAP_OPTIONS = [:label, :hint].freeze
6
+
7
+ def bootstrap_text_field(object_name, method, options={})
8
+ bootstrap_control_group_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_control_group_wrap(object_name, method, email_field(object_name, method, extract_input_options(options)), options)
13
+ end
14
+
15
+ def bootstrap_password_field(object_name, method, options={})
16
+ bootstrap_control_group_wrap(object_name, method, password_field(object_name, method, extract_input_options(options)), options)
17
+ end
18
+
19
+ def bootstrap_collection_select(object_name, method, collection, value_method, text_method, options = {}, html_options = {})
20
+ bootstrap_control_group_wrap(object_name, method, collection_select(object_name, method, collection, value_method, text_method, extract_input_options(options), html_options), options)
21
+ end
22
+
23
+ def bootstrap_select(object_name, method, choices, options, html_options)
24
+ bootstrap_control_group_wrap(object_name, method, select(object_name, method, choices, extract_input_options(options), html_options), options)
25
+ end
26
+
27
+ def bootstrap_file_field(object_name, method, options={})
28
+ bootstrap_control_group_wrap(object_name, method, file_field(object_name, method, extract_input_options(options)), options)
29
+ end
30
+
31
+ def bootstrap_text_area(object_name, method, options={})
32
+ bootstrap_control_group_wrap(object_name, method, text_area(object_name, method, extract_input_options(options)), options)
33
+ end
34
+
35
+ def bootstrap_control_group_wrap(object_name, method, content, options={})
36
+ error_messages = options[:object].errors[method]
37
+ control_group_tag = error_messages.blank? ? 'control-group' : 'control-group error'
38
+ inline_help = inline_help_tag(error_messages.presence || options[:hint])
39
+
40
+ content_tag(:div, label(object_name, method, options[:label], :class => 'control-label') +
41
+ content_tag(:div, content + inline_help, :class => 'controls'),
42
+ :class => control_group_tag)
43
+ end
44
+
45
+ def inline_help_tag(messages)
46
+ messages = Array.wrap(messages)
47
+ return '' if messages.empty?
48
+ message_span = ActiveSupport::SafeBuffer.new(" #{messages.to_sentence}")
49
+ content_tag(:span, message_span, :class => 'help-inline')
50
+ end
51
+
52
+ private
53
+
54
+ def extract_input_options(options)
55
+ options.except(*BOOTSTRAP_OPTIONS)
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ class ActionView::Helpers::FormBuilder #:nodoc:
62
+ def bootstrap_text_field(method, options={})
63
+ @template.bootstrap_text_field(@object_name, method, objectify_options(options))
64
+ end
65
+
66
+ def bootstrap_email_field(method, options={})
67
+ @template.bootstrap_email_field(@object_name, method, objectify_options(options))
68
+ end
69
+
70
+ def bootstrap_password_field(method, options={})
71
+ @template.bootstrap_password_field(@object_name, method, objectify_options(options))
72
+ end
73
+
74
+ def bootstrap_collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
75
+ @template.bootstrap_collection_select(@object_name, method, collection, value_method, text_method, objectify_options(options), html_options)
76
+ end
77
+
78
+ def bootstrap_select(method, choices, options={}, html_options={})
79
+ @template.bootstrap_select(@object_name, method, choices, objectify_options(options), html_options)
80
+ end
81
+
82
+ def bootstrap_file_field(method, options={})
83
+ self.multipart = true
84
+ @template.bootstrap_file_field(@object_name, method, objectify_options(options))
85
+ end
86
+
87
+ def bootstrap_text_area(method, options={})
88
+ @template.bootstrap_text_area(@object_name, method, objectify_options(options))
89
+ end
90
+ end
@@ -0,0 +1,5 @@
1
+ module Bootstrap
2
+ module Form
3
+ VERSION = "1.0.2"
4
+ end
5
+ end
@@ -0,0 +1,151 @@
1
+ require 'test_helper'
2
+
3
+ class FormHelperTest < ActionView::TestCase
4
+ def test_bootstrap_control_group_wrap
5
+ object = mock
6
+ errors = { :name => [] }
7
+ options = { :object => object }
8
+ content = ::ActiveSupport::SafeBuffer.new('content')
9
+ stub(object).errors { errors }
10
+ stub(object).name { 'Object Name' }
11
+
12
+ expected_code = %{<div class="control-group"><label class="control-label" for="post_name">Name</label><div class="controls">content</div></div>}
13
+ assert_equal expected_code, bootstrap_control_group_wrap(:post, :name, content, options)
14
+ end
15
+
16
+ def test_bootstrap_control_group_wrap_with_label
17
+ object = mock
18
+ errors = { :name => [] }
19
+ options = { :object => object, :label => "Custom" }
20
+ content = ::ActiveSupport::SafeBuffer.new('content')
21
+ stub(object).errors { errors }
22
+ stub(object).name { 'Object Name' }
23
+
24
+ expected_code = %{<div class="control-group"><label class="control-label" for="post_name">Custom</label><div class="controls">content</div></div>}
25
+ assert_equal expected_code, bootstrap_control_group_wrap(:post, :name, content, options)
26
+ end
27
+
28
+ def test_bootstrap_control_group_wrap_with_errors
29
+ object = mock
30
+ errors = { :name => ["can't be blank"] }
31
+ options = { :object => object }
32
+ content = ::ActiveSupport::SafeBuffer.new('content')
33
+ stub(object).errors { errors }
34
+ stub(object).name { 'Object Name' }
35
+
36
+ expected_code = %{<div class="control-group error"><label class="control-label" for="post_name">Name</label><div class="controls">content<span class="help-inline"> can't be blank</span></div></div>}
37
+ assert_equal expected_code, bootstrap_control_group_wrap(:post, :name, content, options)
38
+ end
39
+
40
+ def test_bootstrap_control_group_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="control-group error"><label class="control-label" for="post_name">Name</label><div class="controls">content<span class="help-inline"> has already been taken, is reserved, and must be odd</span></div></div>}
49
+ assert_equal expected_code, bootstrap_control_group_wrap(:post, :name, content, options)
50
+ end
51
+
52
+ def test_bootstrap_control_group_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="control-group"><label class="control-label" for="post_name">Name</label><div class="controls">content<span class="help-inline"> format matters</span></div></div>}
61
+ assert_equal expected_code, bootstrap_control_group_wrap(:post, :name, content, options)
62
+ end
63
+
64
+ def test_bootstrap_control_group_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="control-group error"><label class="control-label" for="post_name">Name</label><div class="controls">content<span class="help-inline"> can't be blank</span></div></div>}
73
+ assert_equal expected_code, bootstrap_control_group_wrap(:post, :name, content, options)
74
+ end
75
+
76
+ def test_bootstrap_text_field
77
+ html, text_field = mock, mock
78
+ options = { :object => mock }
79
+
80
+ mock(self).text_field(:post, :name, options) { text_field }
81
+ mock(self).bootstrap_control_group_wrap(:post, :name, text_field, options.dup) { html }
82
+ assert_equal html, bootstrap_text_field(:post, :name, options)
83
+ end
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_control_group_wrap(:post, :email, email_field, options.dup) { html }
91
+ assert_equal html, bootstrap_email_field(:post, :email, options)
92
+ end
93
+
94
+ def test_bootstrap_password_field
95
+ html, password_field = mock, mock
96
+ options = { :object => mock }
97
+
98
+ mock(self).password_field(:post, :password, options) { password_field }
99
+ mock(self).bootstrap_control_group_wrap(:post, :password, password_field, options.dup) { html }
100
+ assert_equal html, bootstrap_password_field(:post, :password, options)
101
+ end
102
+
103
+ def test_bootstrap_collection_select
104
+ html, collection_select_html, collection, object = mock, mock, mock, mock
105
+ options = { :object => mock }
106
+
107
+ mock(self).collection_select(:post, :name, collection, :id, :name, options, {}) { collection_select_html }
108
+ mock(self).bootstrap_control_group_wrap(:post, :name, collection_select_html, options.dup) { html }
109
+
110
+ assert_equal html, bootstrap_collection_select(:post, :name, collection, :id ,:name, options)
111
+ end
112
+
113
+ def test_bootstrap_select
114
+ choices, select_html, html = mock, mock, mock
115
+ options = { :object => mock }
116
+
117
+ mock(self).select(:post, :name, choices, options, {}) { select_html }
118
+ mock(self).bootstrap_control_group_wrap(:post, :name, select_html, options.dup) { html }
119
+
120
+ assert_equal html, bootstrap_select(:post, :name, choices, options, {})
121
+ end
122
+
123
+ def test_bootstrap_file_field
124
+ html, text_field = mock, mock
125
+ options = { :object => mock }
126
+
127
+ mock(self).file_field(:post, :attachment, options) { text_field }
128
+ mock(self).bootstrap_control_group_wrap(:post, :attachment, text_field, options.dup) { html }
129
+ assert_equal html, bootstrap_file_field(:post, :attachment, options)
130
+ end
131
+
132
+ def test_bootstrap_text_area
133
+ html, text_area = mock, mock
134
+ options = { :object => mock }
135
+
136
+ mock(self).text_area(:post, :description, options) { text_area }
137
+ mock(self).bootstrap_control_group_wrap(:post, :description, text_area, options.dup) { html }
138
+ assert_equal html, bootstrap_text_area(:post, :description, options)
139
+ end
140
+
141
+ def test_ignore_bootstrap_options
142
+ html, text_area = mock, mock
143
+ options = { :object => mock, :label => "Custom", :hint => "be careful" }
144
+
145
+ mock(self).text_area(:post, :description, options.except(:label, :hint)) { text_area }
146
+ mock(self).bootstrap_control_group_wrap(:post, :description, text_area, options.dup) { html }
147
+ assert_equal html, bootstrap_text_area(:post, :description, options)
148
+ end
149
+
150
+
151
+ end
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+
7
+ ENV["RAILS_ENV"] = "test"
8
+
9
+ require 'minitest/autorun'
10
+ require 'rails'
11
+ require 'action_controller'
12
+ require 'action_view'
13
+ require 'rails/test_help'
14
+ require 'bootstrap-form'
15
+ require 'rr'
16
+
17
+ module BootstrapForm
18
+ class Application < Rails::Application ; end
19
+ end
20
+
21
+ BootstrapForm::Application.routes.draw do
22
+ get '/:controller(/:action(/:id))'
23
+ end
24
+ BootstrapForm::Application.config.secret_key_base = 'bootstrap'
25
+
26
+ ActionController::Base.send :include, BootstrapForm::Application.routes.url_helpers
27
+
28
+ class MiniTest::Unit::TestCase
29
+ include RR::Adapters::TestUnit
30
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mediatainment-bootstrap-form
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - David Padilla
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>'
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>'
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionpack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>'
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>'
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Twitter Bootstrap Form helpers
70
+ email:
71
+ - mail@mediatainment-productions.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - Gemfile
79
+ - Gemfile.rails.3.2
80
+ - Gemfile.rails.4.0
81
+ - README.md
82
+ - Rakefile
83
+ - bootsrap-form.gemspec
84
+ - lib/bootstrap-form.rb
85
+ - lib/bootstrap-form/form_helper.rb
86
+ - lib/bootstrap-form/version.rb
87
+ - test/lib/action_view/helpers/form_helper_test.rb
88
+ - test/test_helper.rb
89
+ homepage: ''
90
+ licenses: []
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project: bootstrap-form
108
+ rubygems_version: 2.0.3
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Twitter Bootstrap Form helpers
112
+ test_files:
113
+ - test/lib/action_view/helpers/form_helper_test.rb
114
+ - test/test_helper.rb
115
+ has_rdoc: