simple_bootstrap_form 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +74 -0
  8. data/Rakefile +1 -0
  9. data/lib/simple_bootstrap_form/action_view_extensions.rb +31 -0
  10. data/lib/simple_bootstrap_form/css_class_list.rb +32 -0
  11. data/lib/simple_bootstrap_form/fields/base_field.rb +103 -0
  12. data/lib/simple_bootstrap_form/fields/boolean_field.rb +14 -0
  13. data/lib/simple_bootstrap_form/fields/datetime_field.rb +53 -0
  14. data/lib/simple_bootstrap_form/fields/email_field.rb +8 -0
  15. data/lib/simple_bootstrap_form/fields/password_field.rb +8 -0
  16. data/lib/simple_bootstrap_form/fields/text_field.rb +8 -0
  17. data/lib/simple_bootstrap_form/fields/textarea_field.rb +12 -0
  18. data/lib/simple_bootstrap_form/form_builder.rb +51 -0
  19. data/lib/simple_bootstrap_form/version.rb +3 -0
  20. data/lib/simple_bootstrap_form.rb +13 -0
  21. data/simple_bootstrap_form.gemspec +27 -0
  22. data/spec/dummy/.rspec +1 -0
  23. data/spec/dummy/README.rdoc +28 -0
  24. data/spec/dummy/Rakefile +6 -0
  25. data/spec/dummy/app/assets/images/.keep +0 -0
  26. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  27. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  28. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  29. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  30. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  31. data/spec/dummy/app/mailers/.keep +0 -0
  32. data/spec/dummy/app/models/.keep +0 -0
  33. data/spec/dummy/app/models/account.rb +6 -0
  34. data/spec/dummy/app/models/article.rb +2 -0
  35. data/spec/dummy/app/models/concerns/.keep +0 -0
  36. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  37. data/spec/dummy/bin/bundle +3 -0
  38. data/spec/dummy/bin/rails +4 -0
  39. data/spec/dummy/bin/rake +4 -0
  40. data/spec/dummy/config/application.rb +23 -0
  41. data/spec/dummy/config/boot.rb +5 -0
  42. data/spec/dummy/config/database.yml +25 -0
  43. data/spec/dummy/config/environment.rb +5 -0
  44. data/spec/dummy/config/environments/development.rb +29 -0
  45. data/spec/dummy/config/environments/production.rb +80 -0
  46. data/spec/dummy/config/environments/test.rb +36 -0
  47. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  48. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  49. data/spec/dummy/config/initializers/inflections.rb +16 -0
  50. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  51. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  52. data/spec/dummy/config/initializers/session_store.rb +3 -0
  53. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  54. data/spec/dummy/config/locales/en.yml +23 -0
  55. data/spec/dummy/config/routes.rb +60 -0
  56. data/spec/dummy/config.ru +4 -0
  57. data/spec/dummy/db/migrate/20131210035839_create_accounts.rb +14 -0
  58. data/spec/dummy/db/migrate/20140214204510_create_articles.rb +14 -0
  59. data/spec/dummy/db/schema.rb +38 -0
  60. data/spec/dummy/lib/assets/.keep +0 -0
  61. data/spec/dummy/public/404.html +58 -0
  62. data/spec/dummy/public/422.html +58 -0
  63. data/spec/dummy/public/500.html +57 -0
  64. data/spec/dummy/public/favicon.ico +0 -0
  65. data/spec/simple_bootstrap_form_spec.rb +156 -0
  66. data/spec/spec_helper.rb +47 -0
  67. data/spec/support/input_matchers.rb +72 -0
  68. metadata +241 -0
@@ -0,0 +1,156 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleBootstrapForm, type: :helper do
4
+
5
+ def account_form
6
+ helper.bootstrap_form_for model do |f|
7
+ f.input(:email) +
8
+ f.input(:first_name) +
9
+ f.input(:password)
10
+ end
11
+ end
12
+
13
+ def article_form
14
+ helper.bootstrap_form_for model do |f|
15
+ f.input(:title) +
16
+ f.input(:published_at) +
17
+ f.input(:visible) +
18
+ f.input(:body)
19
+ end
20
+ end
21
+
22
+ describe "#bootstrap_form_for" do
23
+ let(:model) { Account.new }
24
+ let(:form_id) { 'new_account' }
25
+
26
+ subject do
27
+ account_form
28
+ end
29
+
30
+ #it "should generate a form" do
31
+ # expect(subject).to eq(
32
+ # '<form accept-charset="UTF-8" action="/accounts" class="form-horizontal" id="new_account" method="post">' +
33
+ # '<div style="margin:0;padding:0;display:inline">'+
34
+ # '<input name="utf8" type="hidden" value="&#x2713;" />'+
35
+ # '</div>'+
36
+ # '<div class="form-group">'+
37
+ # '<label class="control-label col-sm-3" for="account_email"><abbr title="required">*</abbr> Email</label>'+
38
+ # '<div class="col-sm-6">'+
39
+ # '<input class="form-control" id="account_email" name="account[email]" placeholder="Email" required="required" type="email" />'+
40
+ # '</div>'+
41
+ # '</div>'+
42
+ # '</form>'
43
+ # )
44
+ #end
45
+
46
+ describe "the form" do
47
+ it "should have and ID" do
48
+ should have_selector %(form##{form_id}[action="/accounts"])
49
+ end
50
+
51
+ it "should be a horizontal form" do
52
+ should have_selector "form##{form_id}.form-horizontal"
53
+ end
54
+
55
+ it "should have role 'form'" do
56
+ should have_selector "form##{form_id}[role=form]"
57
+ end
58
+ end
59
+
60
+ describe "f.input" do
61
+ let(:field_id) { "account_email" }
62
+
63
+ describe "form-group" do
64
+ it "should add a class describing the form group" do
65
+ should have_selector ".form-group.account_email_group"
66
+ end
67
+ end
68
+
69
+ describe "label" do
70
+ it { should have_selector "form##{form_id} > .form-group > label.control-label[for=#{field_id}]" }
71
+
72
+ it "should make the label 3 columns wide" do
73
+ should have_selector "label.col-sm-3[for=#{field_id}]"
74
+ end
75
+ end
76
+
77
+ describe "string field" do
78
+ let(:field_id) { 'account_first_name' }
79
+
80
+ it "should give the input an ID, and class form-control" do
81
+ should have_selector %(input##{field_id}.form-control[name="account[first_name]"])
82
+ end
83
+
84
+ it "should place the input inside a 6 column div" do
85
+ should have_selector "form##{form_id} > .form-group > .col-sm-6 > input##{field_id}"
86
+ end
87
+
88
+ it { should have_input("##{field_id}").with_type('text') }
89
+ it { should have_input("##{field_id}").with_placeholder('First name') }
90
+ end
91
+
92
+ describe "integer field" do
93
+ let(:field_id) { "account_id" }
94
+ subject do
95
+ helper.bootstrap_form_for model do |f|
96
+ f.input :id
97
+ end
98
+ end
99
+ it { should have_input("##{field_id}").with_type('text') }
100
+ end
101
+
102
+ describe "email field (required)" do
103
+ let(:field_id) { "account_email" }
104
+
105
+ it { should have_input("##{field_id}").with_type('email') }
106
+ it { should have_input("##{field_id}").with_placeholder('Email') }
107
+ it { should have_input("##{field_id}").with_attr_value(:required, 'required') }
108
+ end
109
+
110
+ describe "option :as =>" do
111
+ let(:field_id) { "account_email" }
112
+ subject do
113
+ helper.bootstrap_form_for model do |f|
114
+ f.input :email, as: :text
115
+ end
116
+ end
117
+ it "should override the type" do
118
+ should have_input("##{field_id}").with_type('text')
119
+ end
120
+ end
121
+
122
+ describe "password field" do
123
+ let(:field_id) { "account_password" }
124
+
125
+ it { should have_input("##{field_id}").with_type('password') }
126
+ end
127
+
128
+ context "Using the Article form" do
129
+ let(:model) { Article.new }
130
+ subject { article_form }
131
+
132
+ describe "text field (optional)" do
133
+ let(:field_id) { 'article_body' }
134
+
135
+ it { should have_tag(:textarea).with_id(field_id) }
136
+ it { should have_tag(:textarea).with_id(field_id)
137
+ .with_placeholder('Body') }
138
+ it { should_not have_tag(:textarea).with_id(field_id)
139
+ .with_attr_value(:required, 'required') }
140
+ end
141
+
142
+ describe "datetime field" do
143
+ let(:field_id) { "article_published_at" }
144
+
145
+ it { should have_input("##{field_id}").with_type('datetime') }
146
+ end
147
+
148
+ describe "boolean field" do
149
+ let(:field_id) { 'article_visible' }
150
+
151
+ it { should have_input("##{field_id}").with_type('checkbox') }
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,47 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../dummy/config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'rspec/autorun'
6
+
7
+ # Requires supporting ruby files with custom matchers and macros, etc, in
8
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
9
+ # run as spec files by default. This means that files in spec/support that end
10
+ # in _spec.rb will both be required and run as specs, causing the specs to be
11
+ # run twice. It is recommended that you do not name files matching this glob to
12
+ # end with _spec.rb. You can configure this pattern with with the --pattern
13
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
14
+ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
15
+
16
+ # Checks for pending migrations before tests are run.
17
+ # If you are not using ActiveRecord, you can remove this line.
18
+ ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
19
+
20
+ RSpec.configure do |config|
21
+ # ## Mock Framework
22
+ #
23
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
24
+ #
25
+ # config.mock_with :mocha
26
+ # config.mock_with :flexmock
27
+ # config.mock_with :rr
28
+
29
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
30
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
31
+
32
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
33
+ # examples within a transaction, remove the following line or assign false
34
+ # instead of true.
35
+ config.use_transactional_fixtures = true
36
+
37
+ # If true, the base class of anonymous controllers will be inferred
38
+ # automatically. This will be the default behavior in future versions of
39
+ # rspec-rails.
40
+ config.infer_base_class_for_anonymous_controllers = false
41
+
42
+ # Run specs in random order to surface order dependencies. If you find an
43
+ # order dependency and want to debug it, you can fix the order by providing
44
+ # the seed, which is printed after each run.
45
+ # --seed 1234
46
+ config.order = "random"
47
+ end
@@ -0,0 +1,72 @@
1
+ RSpec::Matchers.define :have_input do |input_id|
2
+ match_for_should do |markup|
3
+ expect(markup).to have_selector selector(input_id)
4
+ end
5
+
6
+ match_for_should_not do |markup|
7
+ !(expect(markup).not_to have_selector selector(input_id))
8
+ end
9
+
10
+ chain :with_attr_value do |attr, value|
11
+ attrs[attr] = value
12
+ end
13
+
14
+ chain :with_type do |type|
15
+ attrs['type'] = type
16
+ end
17
+
18
+ chain :with_placeholder do |placeholder|
19
+ attrs['placeholder'] = placeholder
20
+ end
21
+
22
+ def attrs
23
+ @attrs ||= {}
24
+ end
25
+
26
+ def selector(input_id)
27
+ s = "input#{input_id}"
28
+ attrs.each do |attr, value|
29
+ s << %([#{attr}="#{value}"])
30
+ end
31
+ s
32
+ end
33
+ end
34
+
35
+ RSpec::Matchers.define :have_tag do |tag|
36
+ match_for_should do |markup|
37
+ expect(markup).to have_selector selector(tag)
38
+ end
39
+
40
+ match_for_should_not do |markup|
41
+ !(expect(markup).not_to have_selector selector(tag))
42
+ end
43
+
44
+ chain :with_id do |id|
45
+ @id = id
46
+ end
47
+
48
+ chain :with_attr_value do |attr, value|
49
+ attrs[attr] = value
50
+ end
51
+
52
+ chain :with_type do |type|
53
+ attrs['type'] = type
54
+ end
55
+
56
+ chain :with_placeholder do |placeholder|
57
+ attrs['placeholder'] = placeholder
58
+ end
59
+
60
+ def attrs
61
+ @attrs ||= {}
62
+ end
63
+
64
+ def selector(tag)
65
+ s = tag.to_s
66
+ s << "##{@id}" if @id
67
+ attrs.each do |attr, value|
68
+ s << "[#{attr}=#{value}]"
69
+ end
70
+ s
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,241 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_bootstrap_form
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sam Pierson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0.beta1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0.beta1
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
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
+ - !ruby/object:Gem::Dependency
70
+ name: capybara
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '4'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '4'
97
+ description: A form helper with a 'Simple Form'-like interface, that supports Bootstrap
98
+ 3
99
+ email:
100
+ - gems@sampierson.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".ruby-gemset"
107
+ - ".ruby-version"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - lib/simple_bootstrap_form.rb
113
+ - lib/simple_bootstrap_form/action_view_extensions.rb
114
+ - lib/simple_bootstrap_form/css_class_list.rb
115
+ - lib/simple_bootstrap_form/fields/base_field.rb
116
+ - lib/simple_bootstrap_form/fields/boolean_field.rb
117
+ - lib/simple_bootstrap_form/fields/datetime_field.rb
118
+ - lib/simple_bootstrap_form/fields/email_field.rb
119
+ - lib/simple_bootstrap_form/fields/password_field.rb
120
+ - lib/simple_bootstrap_form/fields/text_field.rb
121
+ - lib/simple_bootstrap_form/fields/textarea_field.rb
122
+ - lib/simple_bootstrap_form/form_builder.rb
123
+ - lib/simple_bootstrap_form/version.rb
124
+ - simple_bootstrap_form.gemspec
125
+ - spec/dummy/.rspec
126
+ - spec/dummy/README.rdoc
127
+ - spec/dummy/Rakefile
128
+ - spec/dummy/app/assets/images/.keep
129
+ - spec/dummy/app/assets/javascripts/application.js
130
+ - spec/dummy/app/assets/stylesheets/application.css
131
+ - spec/dummy/app/controllers/application_controller.rb
132
+ - spec/dummy/app/controllers/concerns/.keep
133
+ - spec/dummy/app/helpers/application_helper.rb
134
+ - spec/dummy/app/mailers/.keep
135
+ - spec/dummy/app/models/.keep
136
+ - spec/dummy/app/models/account.rb
137
+ - spec/dummy/app/models/article.rb
138
+ - spec/dummy/app/models/concerns/.keep
139
+ - spec/dummy/app/views/layouts/application.html.erb
140
+ - spec/dummy/bin/bundle
141
+ - spec/dummy/bin/rails
142
+ - spec/dummy/bin/rake
143
+ - spec/dummy/config.ru
144
+ - spec/dummy/config/application.rb
145
+ - spec/dummy/config/boot.rb
146
+ - spec/dummy/config/database.yml
147
+ - spec/dummy/config/environment.rb
148
+ - spec/dummy/config/environments/development.rb
149
+ - spec/dummy/config/environments/production.rb
150
+ - spec/dummy/config/environments/test.rb
151
+ - spec/dummy/config/initializers/backtrace_silencers.rb
152
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
153
+ - spec/dummy/config/initializers/inflections.rb
154
+ - spec/dummy/config/initializers/mime_types.rb
155
+ - spec/dummy/config/initializers/secret_token.rb
156
+ - spec/dummy/config/initializers/session_store.rb
157
+ - spec/dummy/config/initializers/wrap_parameters.rb
158
+ - spec/dummy/config/locales/en.yml
159
+ - spec/dummy/config/routes.rb
160
+ - spec/dummy/db/migrate/20131210035839_create_accounts.rb
161
+ - spec/dummy/db/migrate/20140214204510_create_articles.rb
162
+ - spec/dummy/db/schema.rb
163
+ - spec/dummy/lib/assets/.keep
164
+ - spec/dummy/public/404.html
165
+ - spec/dummy/public/422.html
166
+ - spec/dummy/public/500.html
167
+ - spec/dummy/public/favicon.ico
168
+ - spec/simple_bootstrap_form_spec.rb
169
+ - spec/spec_helper.rb
170
+ - spec/support/input_matchers.rb
171
+ homepage: ''
172
+ licenses:
173
+ - MIT
174
+ metadata: {}
175
+ post_install_message:
176
+ rdoc_options: []
177
+ require_paths:
178
+ - lib
179
+ required_ruby_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ requirements: []
190
+ rubyforge_project:
191
+ rubygems_version: 2.2.0
192
+ signing_key:
193
+ specification_version: 4
194
+ summary: Bootstrap 3 Form Helper
195
+ test_files:
196
+ - spec/dummy/.rspec
197
+ - spec/dummy/README.rdoc
198
+ - spec/dummy/Rakefile
199
+ - spec/dummy/app/assets/images/.keep
200
+ - spec/dummy/app/assets/javascripts/application.js
201
+ - spec/dummy/app/assets/stylesheets/application.css
202
+ - spec/dummy/app/controllers/application_controller.rb
203
+ - spec/dummy/app/controllers/concerns/.keep
204
+ - spec/dummy/app/helpers/application_helper.rb
205
+ - spec/dummy/app/mailers/.keep
206
+ - spec/dummy/app/models/.keep
207
+ - spec/dummy/app/models/account.rb
208
+ - spec/dummy/app/models/article.rb
209
+ - spec/dummy/app/models/concerns/.keep
210
+ - spec/dummy/app/views/layouts/application.html.erb
211
+ - spec/dummy/bin/bundle
212
+ - spec/dummy/bin/rails
213
+ - spec/dummy/bin/rake
214
+ - spec/dummy/config.ru
215
+ - spec/dummy/config/application.rb
216
+ - spec/dummy/config/boot.rb
217
+ - spec/dummy/config/database.yml
218
+ - spec/dummy/config/environment.rb
219
+ - spec/dummy/config/environments/development.rb
220
+ - spec/dummy/config/environments/production.rb
221
+ - spec/dummy/config/environments/test.rb
222
+ - spec/dummy/config/initializers/backtrace_silencers.rb
223
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
224
+ - spec/dummy/config/initializers/inflections.rb
225
+ - spec/dummy/config/initializers/mime_types.rb
226
+ - spec/dummy/config/initializers/secret_token.rb
227
+ - spec/dummy/config/initializers/session_store.rb
228
+ - spec/dummy/config/initializers/wrap_parameters.rb
229
+ - spec/dummy/config/locales/en.yml
230
+ - spec/dummy/config/routes.rb
231
+ - spec/dummy/db/migrate/20131210035839_create_accounts.rb
232
+ - spec/dummy/db/migrate/20140214204510_create_articles.rb
233
+ - spec/dummy/db/schema.rb
234
+ - spec/dummy/lib/assets/.keep
235
+ - spec/dummy/public/404.html
236
+ - spec/dummy/public/422.html
237
+ - spec/dummy/public/500.html
238
+ - spec/dummy/public/favicon.ico
239
+ - spec/simple_bootstrap_form_spec.rb
240
+ - spec/spec_helper.rb
241
+ - spec/support/input_matchers.rb