-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add small fixes for bootstrap 3. Add tests. #85
base: master
Are you sure you want to change the base?
Changes from 1 commit
d862498
0f5c8a2
847cace
e61a7f6
de298e9
0712888
e6d0b5c
4370845
25ca7bf
5100190
dec35c9
ecd7bff
476d7e8
4f58e04
ac4ce58
5524cec
82d838d
757eac8
78de96a
94b8064
48bd22c
790a01a
2801e5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.DS_Store | ||
*.rbc | ||
*.sassc | ||
.sass-cache | ||
capybara-*.html | ||
.rspec | ||
.rvmrc | ||
Gemfile.lock | ||
/.bundle | ||
/vendor/bundle | ||
/log/* | ||
/tmp/* | ||
/db/*.sqlite3 | ||
/public/system/* | ||
/coverage/ | ||
/spec/tmp/* | ||
**.orig | ||
rerun.txt | ||
pickle-email-*.html | ||
.project | ||
config/initializers/secret_token.rb | ||
test/dummy/db/*.sqlite3 | ||
test/dummy/db/*.sqlite3-journal | ||
test/dummy/log/* | ||
test/dummy/tmp/* | ||
test/dummy/.sass-cache | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
source "https://rubygems.org" | ||
|
||
# Declare your gem's dependencies in hive.gemspec. | ||
# Bundler will treat runtime dependencies like base dependencies, and | ||
# development dependencies will be added by default to the :development group. | ||
gemspec | ||
|
||
# Declare any dependencies that are still in development here instead of in | ||
# your gemspec. These might include edge Rails or gems from your path or | ||
# Git. Remember to move these dependencies to your gemspec before releasing | ||
# your gem to rubygems.org. | ||
|
||
# To use debugger | ||
# gem 'debugger' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
Twitter Bootstrap Form For | ||
========================== | ||
|
||
*_WARNING! This is for Rails 4 and Bootstrap 3 (current in RC)._* | ||
|
||
`twitter_bootstrap_form_for` is a Rails FormBuilder DSL that, like Formtastic, | ||
makes it easier to create semantically awesome, readily-stylable, and | ||
wonderfully accessible HTML forms in your Rails applications. It abides by | ||
|
@@ -16,60 +14,56 @@ Formtastic does), it only lightly wraps the existing Rails form tag helpers. | |
## Dependencies ## | ||
|
||
* Rails 4 | ||
* Bootstrap-sass, pull from branch 3 off github | ||
|
||
` | ||
gem 'bootstrap-sass', :git => 'git://github.com/thomas-mcdonald/bootstrap-sass.git', :branch => '3' | ||
` | ||
* Bootstrap 3 (Checkout the [bootstrap-rails] gem.) | ||
|
||
## Syntax ## | ||
|
||
```haml | ||
= twitter_bootstrap_form_for @user, layout: 'vertical (default) OR horizontal OR inline', default_div_class: 'col-lg-10 (default)', role: 'form (default)' do |user| | ||
= twitter_bootstrap_form_for @user, layout: [:vertical (default) OR :horizontal OR :inline], default_div_class: 'col-lg-10 (default)', role: 'form (default)' do |f| | ||
|
||
/ wraps a section in a fieldset with the provided legend text | ||
= user.inputs 'Sign up', :class => 'sign_up' do | ||
= f.inputs 'Sign up', class: 'sign_up' do | ||
|
||
/ generates a standard email field | ||
/ also showing overriding the div_class around the input element on a horizontal form | ||
= f.email_field :email | ||
|
||
/ generates a standard email field; also showing overriding the div_class around the input element on a horizontal form | ||
= user.email_field :email, :placeholder => '[email protected]', div_class: 'col-md-6' | ||
/ generates a field for the user name with a custom label, a placeholder text, | ||
/ a bootstrap class to make the form field larger and overwrites the | ||
/ default class on the input element wrapper in horizontal forms. | ||
= f.text_field :name, 'Username', placeholder: 'Choose your user name.', class: 'input-lg', div_class: 'col-md-6' | ||
|
||
/ generates a password field with a descriptive aside | ||
= user.password_field :password do | ||
= f.password_field :password do | ||
%span.help-block | ||
Must be no larger than 6 characters<br/> | ||
Must contain only the letters 'x' or 'p' | ||
|
||
/ a field with a custom label | ||
= user.password_field :password_confirmation, 'Confirm Password' | ||
= f.password_field :password_confirmation, 'Confirm Password' | ||
|
||
/ input fields with custom add-ons | ||
= user.text_field :twitter_id, 'Twitter', :class => 'medium', :add_on => :prepend do | ||
%span.add-on @ | ||
= f.text_field :twitter_id, 'Twitter', add_on: :prepend do | ||
%span.input-group-addon @ | ||
|
||
/ select fields now have the second parameter as a label | ||
= user.date_select :born_on, 'Born on', {}, :class => 'small' | ||
|
||
/ inline inputs are not automatically labeled | ||
= user.inline 'Interests' do |inline| | ||
#{inline.text_field :interest_1, :class => 'small'}, | ||
#{inline.text_field :interest_2, :class => 'small'}, and | ||
#{inline.text_field :interest_3, :class => 'small'} | ||
= f.date_select :born_on, 'Born on' | ||
|
||
/ group of radio buttons | ||
= user.toggles 'Email Preferences' do | ||
= user.radio_button :email, 'HTML Email', :html, :checked => true | ||
= user.radio_button :email, 'Plain Text', :plain | ||
= f.toggles 'Email Preferences' do | ||
= f.radio_button :email, 'HTML Email', :html, checked: true | ||
= f.radio_button :email, 'Plain Text', :plain | ||
|
||
/ group of checkboxes | ||
= user.toggles 'Agreements' do | ||
= user.check_box :agree, 'I agree to the abusive Terms and Conditions' | ||
= user.check_box :spam, 'I agree to receive all sorts of spam' | ||
= user.check_box :spammer, 'I agree to let the site spam others through my Twitter account' | ||
= f.toggles 'Agreements' do | ||
= f.check_box :agree, 'I agree to the abusive Terms and Conditions' | ||
= f.check_box :spam, 'I agree to receive all sorts of spam' | ||
= f.check_box :spammer, 'I agree to let the site spam others through my Twitter account' | ||
|
||
/ wraps buttons in a distinctive style | ||
= user.actions do | ||
= user.submit 'Sign up' | ||
= button_tag 'Cancel', :type => 'reset', :class => 'btn' | ||
= f.actions do | ||
= f.submit 'Sign up' | ||
= button_tag 'Cancel', type: 'reset', class: 'btn' | ||
``` | ||
|
||
That code produces the following output, with no custom stylesheets. | ||
|
@@ -80,18 +74,5 @@ That's it. All of the Rails field helpers you know and love work just like | |
their normal FormBuilder counterparts, but with minor extensions to expose | ||
the functionality anticipated by Twitter Bootstrap. | ||
|
||
## Form Helper Changes ## | ||
|
||
The changes this `FormBuilder` effects to the existing Rails form helpers is | ||
simple: | ||
|
||
* the second parameter becomes the label (pass false to disable, nil for default) | ||
* the last options hash accepts an `:add_on` key | ||
* if a block is passed, the HTML it outputs is placed immediately after the input | ||
|
||
## Known Bugs ## | ||
|
||
- inline fields don't receive error markup ([issue #28]) | ||
|
||
[Twitter Bootstrap]: http://twitter.github.com/bootstrap/ | ||
[issue #28]: https://github.com/stouset/twitter_bootstrap_form_for/issues/28 | ||
[bootstrap-rails]: https://github.com/anjlab/bootstrap-rails |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
begin | ||
require 'bundler/setup' | ||
rescue LoadError | ||
puts 'You must `gem install bundler` and `bundle install` to run rake tasks' | ||
end | ||
|
||
require 'rdoc/task' | ||
|
||
RDoc::Task.new(:rdoc) do |rdoc| | ||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = 'TwitterBootstrapFormFor' | ||
rdoc.options << '--line-numbers' | ||
rdoc.rdoc_files.include('README.rdoc') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end | ||
|
||
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This constant isn't used anywhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the default Rake file you get when you do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see. Thanks. |
||
load 'rails/tasks/engine.rake' | ||
|
||
|
||
|
||
Bundler::GemHelper.install_tasks | ||
|
||
require 'rake/testtask' | ||
|
||
Rake::TestTask.new(:test) do |t| | ||
t.libs << 'lib' | ||
t.libs << 'test' | ||
t.pattern = 'test/**/*_test.rb' | ||
t.verbose = false | ||
end | ||
|
||
|
||
task default: :test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a project-specific
.gitignore
. Most of the entries in this seem to be specific to your development environment, and should be in~/.gitignore
.