Skip to content
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

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d862498
Add small fixes for bootstrap 3. Add tests.
schneikai Nov 19, 2013
0f5c8a2
Fix typo in FormBuilder.
schneikai Nov 20, 2013
847cace
Use relative path for screenshot.
schneikai Nov 20, 2013
e61a7f6
use a project-specific .gitignore
schneikai Nov 21, 2013
de298e9
remove unused variable
schneikai Nov 26, 2013
0712888
use html_options for helpers that use this instead of just options
schneikai Nov 26, 2013
e6d0b5c
Update readme. Use official Twitter bootstrap-sass gem. Allow to add …
schneikai Feb 8, 2014
4370845
Make it more clear how to pass html attributes to the input type
schneikai Feb 8, 2014
25ca7bf
add a way to display error messages from base or hidden fields
schneikai Feb 11, 2014
5100190
use I18n to translate error messages; allow html options for errors h…
schneikai Feb 11, 2014
dec35c9
do not escape html_safe labels
schneikai Feb 27, 2014
ecd7bff
do not escape html_safe labels
schneikai Feb 27, 2014
476d7e8
fix checkbox options rendered as label if label is not given
schneikai Mar 1, 2014
4f58e04
make labels work the same for checkboxes and fields. use I18n transla…
schneikai Mar 3, 2014
ac4ce58
allow HTML in I18n attribute translations.
schneikai Mar 3, 2014
5524cec
use bootstrap-sass in dummy app. fix input-groups
schneikai Mar 5, 2014
82d838d
update readme. update screenshot. add documentation about checkboxes.
schneikai Mar 5, 2014
757eac8
highlight required fields. update readme and screenshots.
schneikai Mar 5, 2014
78de96a
fix error messages markup on check boxes and radio buttons
schneikai Mar 5, 2014
94b8064
use default Rails engine setup for the Gem. add datepicker for date i…
schneikai Mar 8, 2014
48bd22c
update example screenshot
schneikai Mar 8, 2014
790a01a
reorganize engine code so it's more like the Rails default.
schneikai Mar 18, 2014
2801e5e
update gitignore
schneikai Apr 6, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .gitignore
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
Copy link
Owner

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.

14 changes: 14 additions & 0 deletions Gemfile
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'
73 changes: 27 additions & 46 deletions README.markdown
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
Expand All @@ -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.
Expand All @@ -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
34 changes: 34 additions & 0 deletions Rakefile
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__)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constant isn't used anywhere.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the default Rake file you get when you do rails plugin new --full to get the dummy app and test directories. I could remove stuff in there but maybe it is good for something? :)

Copy link
Owner

Choose a reason for hiding this comment

The 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
Binary file modified examples/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading