Skip to content

Commit

Permalink
updating to a Rails Engine
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo committed Jan 16, 2012
1 parent d2a19b3 commit 53da669
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 266 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source "http://rubygems.org"

# Specify your gem's dependencies in bootstrap-forms.gemspec
gemspec
gemspec
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2011 Seth Vargo
Copyright (c) 2012 Seth Vargo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
132 changes: 78 additions & 54 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,63 @@ Bootstrap Forms is a nice Rails generator that makes working with [Bootstrap (by

Forms with Bootstrap are crowded with additional layout markup. While it's necessary, you shouldn't have to type it every time you create a form! That's why I created Bootstrap Forms.

Note/Caution/Warning
--------------------
There were **major** changes in the release of version `0.1.0`:

1. The gem name has officially changed from `bootstrap-forms` to `bootstrap_forms` to match gem naming conventions. The old gem still exists on rubygems for legacy applications, however, you should update to the new gem as quickly as possible. It's faster and more stable. The old gem is no longer maintained.
2. `form_for` is no longer overridden by default. There were multiple users who were concerned that this behavior was ill advised. Instead, a new form helper, `bootstrap_form_for` has been created. This is in line with other form building libraries.
3. The gem is now a Rails 3 Engine. As such, **Bootstrap Forms will not work in < Rails 3.0**. The engine is automatically mounted when including the gem in your `Gemfile`.

Installation
------------
Add it to your `Gemfile`:

gem 'bootstrap-forms'

Don't forget to run the `bundle` command. Run the generator:

rails g bootstrap_forms:install
gem 'bootstrap_forms'

This will create 2 files in your project.
Don't forget to run the `bundle` command. The gem will add 2 methods `bootstrap_form_for` and `bootstrap_fields_for` for use in your project. This is different from `bootstrap_forms < 0.1.0`. In previous versions, the default form builders were overridden by default. With backlash from various community members, this is no longer the default.

Restart your Rails server.
Be sure to restart your Rails server after installing the gem.

Why?
----
With Bootstrap, you would need the following code for a form:

# using HAML
= form_for @model do |f|
.clearfix
%label MyLabel
.input
= f.text_area :field, :opts => {...}

# using ERB
<%= form_for @model do |f| %>
<div class="clearfix">
<label>MyLabel</label>
<div class="input">
<%= f.text_area :field, :opts => {...} %>
</div>
</div>
<% end %>
```haml
/ using haml
= form_for @model do |f|
.clearfix
%label MyLabel
.input
= f.text_area :field, :opts => {...}
```

```erb
<!-- using ERB -->
<%= form_for @model do |f| %>
<div class="clearfix">
<label>MyLabel</label>
<div class="input">
<%= f.text_area :field, :opts => {...} %>
</div>
</div>
<% end %>
```

Using Bootstrap Forms, this is **much** simpler:

# using HAML
= form_for @model do |f|
= f.text_area :field, :opts => {...}

# using ERB
<%= form_for @model do |f| %>
<%= f.text_area :field, :opts => {...} %>
<% end %>
```haml
/ using HAML
= bootstrap_form_for @model do |f|
= f.text_area :field, :opts => {...}
```

```erb
<!-- using ERB -->
<%= bootstrap_form_for @model do |f| %>
<%= f.text_area :field, :opts => {...} %>
<% end %>
```

The custom form builder will automatically wrap everything for you. This helps clean up your view layer significantly!

Expand All @@ -59,40 +71,52 @@ Just when you thought you were done... Bootstrap Forms includes additional form
### collection_check_boxes
`collection_check_boxes` behaves very similarly to `collection_select`:

= f.collection_check_boxes :category_ids, Category.all, :id, :name
```haml
= f.collection_check_boxes :category_ids, Category.all, :id, :name
```

### collection_radio_buttons
See description above...

= f.collection_radio_buttons :primary_category_id, Category.all, :id, :name
```haml
= f.collection_radio_buttons :primary_category_id, Category.all, :id, :name
```

Uneditable Field
----------------
Bootstrap Forms adds another helper method that generates the necessary markup for uneditable fields:

= f.uneditable_field :name
```haml
= f.uneditable_field :name
```

generates:
yields:

<div class="clearfix">
<label for="organization_name">Organization Name</label>
<div class="input">
<span class="uneditable-input">The Variety Hour</span>
</div>
</div>
```html
<div class="clearfix">
<label for="organization_name">Organization Name</label>
<div class="input">
<span class="uneditable-input">The Variety Hour</span>
</div>
</div>
```

Submit Tag
----------
Bootstrap Forms also adds a default actions panel when you call `f.submit`:

= f.submit
```haml
= f.submit
```

generates:

<div class="actions">
<input type="submit" value="..." class="btn primary" />
<a href="..." class="btn">Cancel</a>
</div>
```html
<div class="actions">
<input type="submit" value="..." class="btn primary" />
<a href="..." class="btn">Cancel</a>
</div>
```

Pretty swell if you ask me.

Expand All @@ -111,43 +135,43 @@ You can add as many options to any form helper tag. If they are interpreted by B
<tr>
<th>help_inline</th>
<td>Add inline help text</td>
<td>`= f.text_field :name, :help_inline => 'help me!'`</td>
<td>= f.text_field :name, :help_inline => 'help me!'</td>
</tr>
<tr>
<th>help_block</th>
<td>Add block help text (below)</td>
<td>`= f.text_field :name, :help_block => 'help me!'`</td>
<td>= f.text_field :name, :help_block => 'help me!'</td>
</tr>
<tr>
<th>error</th>
<td>Styles the field as error (red)</td>
<td>`= f.text_field :name, :error => 'This is an error!'`</td>
<td>= f.text_field :name, :error => 'This is an error!'</td>
</tr>
<tr>
<th>success</th>
<td>Styles the field as success (green)</td>
<td>`= f.text_field :name, :success => 'This checked out OK'`</td>
<td>= f.text_field :name, :success => 'This checked out OK'</td>
</tr>
<tr>
<th>warning</th>
<td>Styles the field as warning (yellow)</td>
<td>`= f.text_field :name, :warning => 'Take a look at this...'`</td>
<td>= f.text_field :name, :warning => 'Take a look at this...'</td>
</tr>
<tr>
<th>prepend</th>
<td>Adds special text to the front of the input</td>
<td>`= f.text_field :name, :prepend => '@'`</td>
<td>= f.text_field :name, :prepend => '@'</td>
</tr>
<tr>
<th>append</th>
<td>Adds special text at the end of the input</td>
<td>`= f.text_field :name, :append => '@'`</td>
<td>= f.text_field :name, :append => '@'</td>
</tr>
</table>

License
-------
Copyright (c) 2011 Seth Vargo
Copyright (c) 2012 Seth Vargo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require "bundler/gem_tasks"
require 'bundler/gem_tasks'
14 changes: 4 additions & 10 deletions bootstrap-forms.gemspec → bootstrap_forms.gemspec
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
# -*- encoding: utf-8 -*-
# encoding: utf-8
$:.push File.expand_path("../lib", __FILE__)

Gem::Specification.new do |s|
s.name = "bootstrap-forms"
s.version = "0.0.4"
s.name = "bootstrap_forms"
s.version = "0.1.0"
s.author = "Seth Vargo"
s.email = "[email protected]"
s.homepage = "https://github.com/sethvargo/bootstrap-forms"
s.homepage = "https://github.com/sethvargo/bootstrap_forms"
s.summary = %q{Bootstrap Forms makes Twitter's Bootstrap on Rails easy!}
s.description = %q{Bootstrap Forms makes Twitter's Bootstrap on Rails easy to use by creating helpful form builders that minimize markup in your views.}

s.rubyforge_project = "bootstrap-forms"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

# specify any dependencies here; for example:
# s.add_development_dependency "rspec"
# s.add_runtime_dependency "rest-client"
end
4 changes: 1 addition & 3 deletions lib/bootstrap_forms.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
module BootstrapForms
# Your code goes here...
end
require 'bootstrap_forms/railtie' if defined?(Rails)
Loading

0 comments on commit 53da669

Please sign in to comment.