Skip to content

Commit

Permalink
Add a default template to remove Formtastic dependency. [Fixes JDutil#12
Browse files Browse the repository at this point in the history
]
  • Loading branch information
JDutil committed Jun 5, 2012
1 parent 45fe888 commit 04b8154
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 21 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
*ContactUs 0.4.0 (Unreleased)*

* Add default rails form helper support and remove Formtastic dependency. [Jeff Dutil]

* Added support for SimpleForm. [flyerhzm]

*ContactUs 0.3.0 (May 15th 2012)*

* Changed route to /contact-us from /contract_us for seo. [Jeff Dutil]
Expand Down
45 changes: 29 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ There is also a demo application showing how the ContactUs form works:

## REQUIREMENTS

Contact Us requires the Formtastic Gem. Read more about Formtastic @ https://github.com/justinfrench/formtastic
Contact Us requires:

I used Formtastic as a dependency to keep things simple, and hook into your apps custom Formtastic stylesheets.
People have different tastes for their html / css markup, and I find Formtastic to be a great standardized and reusable way to build forms across apps.
* Ruby >= 1.8.7 (will soon only support > 1.9.2)
* Rails >= 3.0.0

If you don't want to have Formtastic as a dependency there is a fork of this project without it [here](https://github.com/sch1zo/contact_us).
It is also recommended to use Formtastic or SimpleForm (see configuration) in order to hook into your apps custom form builders.

## INSTALLATION

In your `Gemfile`, add the following dependencies:

gem 'contact_us', '~> 0.3.0'
gem 'contact_us', '~> 0.4.0.beta'

From `Rails.root` run:

Expand All @@ -43,6 +43,28 @@ You may also specify an email address for the notification emails from field:

config.mailer_from = "dontreply@yourdomain.com"

## CONFIGURATION

The generator copies the view files to `app/views/contact_us`, and you can customize them to suit your needs. If you would like to add a name or subject field to the form you may simply
set the options to true within the contact_us initializer located at `config/initializers/contact_us.rb`:

config.require_name = true
config.require_subject = true

You may also update your locales under `config/locales/contact_us.en.yml` or create your own. Please feel free to submit your own locales so that other users will hopefully find this gem more useful.

### Formtastic

In order to use a Formtastic compatible template to hook into your custom form styles configure `config/initializers/contact_us.rb`:

config.form_gem = 'formtastic'

### SimpleForm

In order to use a SimpleForm compatible template to hook into your custom form styles configure `config/initializers/contact_us.rb`:

config.form_gem = 'simple_form'

## UPGRADING

When upgrading from 0.1.x to 0.2.x you should rerun the install generator to install the new settings, views, and locale updates:
Expand All @@ -54,16 +76,6 @@ Or you may run the generators for each specific component you would like to upda
$ bundle exec rake contact_us:copy_locales
$ bundle exec rake contact_us:copy_views

## CONFIGURATION

The generator copies the view files to `app/views/contact_us`, and you can customize them to suit your needs. If you would like to add a name or subject field to the form you may simply
set the options to true within the contact_us initializer located at `config/initializers/contact_us.rb`:

config.require_name = true
config.require_subject = true

You may also update your locales under `config/locales/contact_us.en.yml` or create your own. Please feel free to submit your own locales so that other users will hopefully find this gem more useful.

## USAGE

Visit your website and navigate to `/contact-us` to see the form in action.
Expand Down Expand Up @@ -97,6 +109,7 @@ Here are some ways *you* can contribute:

## TODO

* Add new language translations
* Add new language translations.
* Stop copying views/locales by default.

Copyright (c) 2011 Jeff Dutil, released under the [MIT license](https://github.com/jdutil/contact_us/tree/master/MIT-LICENSE).
8 changes: 5 additions & 3 deletions app/controllers/contact_us/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ def new
end

protected

def render_new_page
if "simple_form" == ContactUs.form_gem
render 'new_simple_form'
case ContactUs.form_gem
when 'formtastic' then render 'new_formtastic'
when 'simple_form' then render 'new_simple_form'
else
render "new_formtastic"
render 'new'
end
end

Expand Down
26 changes: 26 additions & 0 deletions app/views/contact_us/contacts/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<h2><%= t('.contact_us') %></h2>
<%= form_for @contact, :url => contacts_path, :html => {:class => 'formtastic'} do |f| %>
<% if ContactUs.require_name %>
<li class='string required' id='contact_us_contact_name_input'>
<%= f.label :name, (t('.name') + content_tag(:abbr, '*', :class => 'required')).html_safe %>
<%= f.text_field :name %>
</li>
<% end %>
<li class='string required' id='contact_us_contact_email_input'>
<%= f.label :email, (t('.email') + content_tag(:abbr, '*', :class => 'required')).html_safe %>
<%= f.text_field :email %>
</li>
<% if ContactUs.require_subject %>
<li class='string required' id='contact_us_contact_subject_input'>
<%= f.label :subject, (t('.subject') + content_tag(:abbr, '*', :class => 'required')).html_safe %>
<%= f.text_field :subject %>
</li>
<% end %>
<li class='text required' id='contact_us_contact_message_input'>
<%= f.label :message, (t('.message') + content_tag(:abbr, '*', :class => 'required')).html_safe %>
<%= f.text_area :message %>
</li>
<li class='commit'>
<%= f.submit :submit, :alt => t('.submit'), :class => 'submit create', :label => t('.submit'), :title => t('.submit') %>
</li>
<% end %>
2 changes: 1 addition & 1 deletion lib/contact_us/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ContactUs
VERSION = "0.3.0"
VERSION = "0.4.0.beta"
end
4 changes: 3 additions & 1 deletion lib/templates/contact_us.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
config.require_subject = false

# Configure the form gem to use.
config.form_gem = "formtastic"
# Example:
# config.form_gem = 'formtastic
config.form_gem = nil

end
1 change: 1 addition & 0 deletions spec/integration/contact_us_lint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

after do
ActionMailer::Base.deliveries = []
ContactUs.form_gem = 'formtastic'
ContactUs.mailer_from = nil
ContactUs.mailer_to = nil
ContactUs.require_name = false
Expand Down

0 comments on commit 04b8154

Please sign in to comment.