contact_us_website 0.4.4.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/Gemfile +4 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +117 -0
  4. data/Rakefile +2 -0
  5. data/app/controllers/contact_us/contacts_controller.rb +30 -0
  6. data/app/helpers/contact_us/contacts_helper.rb +2 -0
  7. data/app/mailers/contact_us/contact_mailer.rb +10 -0
  8. data/app/models/contact_us/contact.rb +32 -0
  9. data/app/views/contact_us/contact_mailer/contact_email.html.erb +3 -0
  10. data/app/views/contact_us/contact_mailer/contact_email.text.plain.erb +4 -0
  11. data/app/views/contact_us/contacts/new.html.erb +47 -0
  12. data/app/views/contact_us/contacts/new_formtastic.html.erb +9 -0
  13. data/app/views/contact_us/contacts/new_simple_form.html.erb +9 -0
  14. data/config/locales/contact_us.de.yml +25 -0
  15. data/config/locales/contact_us.en.yml +25 -0
  16. data/config/locales/contact_us.es.yml +25 -0
  17. data/config/locales/contact_us.it.yml +25 -0
  18. data/config/locales/contact_us.ja.yml +25 -0
  19. data/config/locales/contact_us.pt-BR.yml +25 -0
  20. data/config/locales/contact_us.zh.yml +25 -0
  21. data/config/routes.rb +6 -0
  22. data/lib/contact_us.rb +25 -0
  23. data/lib/contact_us/engine.rb +7 -0
  24. data/lib/contact_us/tasks/install.rb +74 -0
  25. data/lib/contact_us/version.rb +3 -0
  26. data/lib/tasks/install.rake +18 -0
  27. data/lib/templates/contact_us.rb +27 -0
  28. data/spec/controllers/contact_us/contact_controller_spec.rb +33 -0
  29. data/spec/dummy/Gemfile +5 -0
  30. data/spec/dummy/Rakefile +7 -0
  31. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  32. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  33. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  34. data/spec/dummy/config.ru +4 -0
  35. data/spec/dummy/config/application.rb +43 -0
  36. data/spec/dummy/config/boot.rb +6 -0
  37. data/spec/dummy/config/database.yml +11 -0
  38. data/spec/dummy/config/environment.rb +5 -0
  39. data/spec/dummy/config/environments/development.rb +26 -0
  40. data/spec/dummy/config/environments/production.rb +49 -0
  41. data/spec/dummy/config/environments/test.rb +35 -0
  42. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  43. data/spec/dummy/config/initializers/inflections.rb +10 -0
  44. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  45. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  46. data/spec/dummy/config/initializers/session_store.rb +8 -0
  47. data/spec/dummy/config/routes.rb +58 -0
  48. data/spec/dummy/public/404.html +26 -0
  49. data/spec/dummy/public/422.html +26 -0
  50. data/spec/dummy/public/500.html +26 -0
  51. data/spec/dummy/public/favicon.ico +0 -0
  52. data/spec/dummy/public/javascripts/application.js +2 -0
  53. data/spec/dummy/public/javascripts/controls.js +965 -0
  54. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  55. data/spec/dummy/public/javascripts/effects.js +1123 -0
  56. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  57. data/spec/dummy/public/javascripts/rails.js +191 -0
  58. data/spec/dummy/script/rails +6 -0
  59. data/spec/integration/contact_us_lint_spec.rb +144 -0
  60. data/spec/lib/contact_us_spec.rb +52 -0
  61. data/spec/lib/install_spec.rb +42 -0
  62. data/spec/mailers/contact_us/contact_mailer_spec.rb +65 -0
  63. data/spec/models/contact_us/contact_spec.rb +66 -0
  64. data/spec/spec_helper.rb +44 -0
  65. data/spec/support/active_model_lint.rb +17 -0
  66. metadata +276 -0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in contact_us.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Jeff Dutil
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # Contact Us [![Build Status](https://secure.travis-ci.org/jdutil/contact_us.png)](http://travis-ci.org/jdutil/contact_us) [![Dependency Status](https://gemnasium.com/jdutil/contact_us.png?travis)](https://gemnasium.com/jdutil/contact_us) [![Click here to lend your support to: ContactUs and make a donation at www.pledgie.com !](https://www.pledgie.com/campaigns/16807.png?skin_name=chrome)][pledgie]
2
+ A Rails 3+ Engine providing a basic contact form.
3
+
4
+ [travis]: http://travis-ci.org/jdutil/contact_us
5
+ [gemnasium]: https://gemnasium.com/jdutil/contact_us
6
+ [pledgie]: http://www.pledgie.com/campaigns/16807
7
+
8
+ There is also a demo application showing how the ContactUs form works:
9
+
10
+ * [View Demo Form In Action](http://contact-us-demo.heroku.com)
11
+ * [View Demo Applications Source Code](http://github.com/jdutil/contact_us_demo)
12
+
13
+ ## REQUIREMENTS
14
+
15
+ Contact Us requires:
16
+
17
+ * Ruby >= 1.8.7 (will soon only support > 1.9.2)
18
+ * Rails >= 3.0.0
19
+
20
+ It is also recommended to use Formtastic or SimpleForm (see configuration) in order to hook into your apps custom form builders.
21
+
22
+ ## INSTALLATION
23
+
24
+ In your `Gemfile`, add the following dependencies:
25
+
26
+ gem 'contact_us', '~> 0.4.0.beta'
27
+
28
+ From `Rails.root` run:
29
+
30
+ $ bundle
31
+ $ bundle exec rake contact_us:install
32
+
33
+ In `config/initializers/contact_us.rb` modify:
34
+
35
+ config.mailer_to = "contact@please-change-me.com"
36
+
37
+ Change to the email address you would like to receive the form submissions at for example:
38
+
39
+ config.mailer_to = "contact@yourdomain.com"
40
+
41
+ By default the emails from field will be the email entered by the user to easily reply, but this may not be allowed if your required to verify your sending email addresses.
42
+ You may also specify an email address for the notification emails from field:
43
+
44
+ config.mailer_from = "dontreply@yourdomain.com"
45
+
46
+ ## CONFIGURATION
47
+
48
+ 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
49
+ set the options to true within the contact_us initializer located at `config/initializers/contact_us.rb`:
50
+
51
+ config.require_name = true
52
+ config.require_subject = true
53
+
54
+ 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.
55
+
56
+ ### Formtastic
57
+
58
+ In order to use a Formtastic compatible template to hook into your custom form styles configure `config/initializers/contact_us.rb`:
59
+
60
+ config.form_gem = 'formtastic'
61
+
62
+ * By default the HTML should match that produced by Formtastic, but to ensure it is up to date you should set Formtastic.
63
+
64
+ ### SimpleForm
65
+
66
+ In order to use a SimpleForm compatible template to hook into your custom form styles configure `config/initializers/contact_us.rb`:
67
+
68
+ config.form_gem = 'simple_form'
69
+
70
+ ## UPGRADING
71
+
72
+ 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:
73
+
74
+ $ bundle exec rake contact_us:install
75
+
76
+ Or you may run the generators for each specific component you would like to update, which is quite useful when upgrading during patch releases for example from 0.2.0 to 0.2.1:
77
+
78
+ $ bundle exec rake contact_us:copy_locales
79
+ $ bundle exec rake contact_us:copy_views
80
+
81
+ ## USAGE
82
+
83
+ Visit your website and navigate to `/contact-us` to see the form in action.
84
+
85
+ ## INTEGRATION TESTS
86
+
87
+ Contact Us has 100% test coverage, and provides simple integration specs you can drop directly into your apps test suite if you use RSpec & Capybara.
88
+
89
+ Simply copy the `spec/integration/contact_us_lint_spec.rb` file, and add it to your integration specs.
90
+
91
+ ## ISSUES
92
+
93
+ Please report any bugs or feature requests to the Github issues page @ https://github.com/jdutil/contact_us/issues
94
+
95
+ ## CONTRIBUTING
96
+
97
+ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
98
+
99
+ Here are some ways *you* can contribute:
100
+
101
+ * by using prerelease versions
102
+ * by reporting bugs
103
+ * by suggesting new features
104
+ * by [translating to a new language](https://github.com/jdutil/contact_us/tree/master/config/locales)
105
+ * by writing or editing documentation
106
+ * by writing specifications
107
+ * by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
108
+ * by refactoring code
109
+ * by resolving [issues](https://github.com/jdutil/contact_us/issues)
110
+ * by reviewing patches
111
+
112
+ ## TODO
113
+
114
+ * Add new language translations.
115
+ * Stop copying views/locales by default.
116
+
117
+ Copyright (c) 2011 Jeff Dutil, released under the [MIT license](https://github.com/jdutil/contact_us/tree/master/MIT-LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,30 @@
1
+ class ContactUsWebsite::ContactsController < ApplicationController
2
+
3
+ def create
4
+ @contact = ContactUsWebsite::Contact.new(params[:contact_us_contact])
5
+
6
+ if @contact.save
7
+ redirect_to('/', :notice => t('contact_us.notices.success'))
8
+ else
9
+ flash[:error] = t('contact_us.notices.error')
10
+ render_new_page
11
+ end
12
+ end
13
+
14
+ def new
15
+ @contact = ContactUsWebsite::Contact.new
16
+ render_new_page
17
+ end
18
+
19
+ protected
20
+
21
+ def render_new_page
22
+ case ContactUsWebsite.form_gem
23
+ when 'formtastic' then render 'new_formtastic'
24
+ when 'simple_form' then render 'new_simple_form'
25
+ else
26
+ render 'new'
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,2 @@
1
+ module ContactUs::ContactsHelper
2
+ end
@@ -0,0 +1,10 @@
1
+ class ContactUs::ContactMailer < ActionMailer::Base
2
+ def contact_email(contact)
3
+ @contact = contact
4
+
5
+ mail :from => (ContactUs.mailer_from || @contact.email),
6
+ :reply_to => @contact.email,
7
+ :subject => (ContactUs.require_subject ? @contact.subject : t('contact_us.contact_mailer.contact_email.subject', :email => @contact.email)),
8
+ :to => ContactUs.mailer_to
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ class ContactUsWebsite::Contact
2
+ include ActiveModel::Conversion
3
+ include ActiveModel::Validations
4
+
5
+ attr_accessor :email, :message, :name, :subject, :website
6
+
7
+ validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i },
8
+ :presence => true
9
+ validates :message, :presence => true
10
+ validates :name, :presence => {:if => Proc.new{ContactUsWebsite.require_name}}
11
+ validates :subject, :presence => {:if => Proc.new{ContactUsWebsite.require_subject}}
12
+ validates :website, :presence => {:if => Proc.new{ContactUsWebsite.require_website}}
13
+
14
+ def initialize(attributes = {})
15
+ attributes.each do |key, value|
16
+ self.send("#{key}=", value)
17
+ end
18
+ end
19
+
20
+ def save
21
+ if self.valid?
22
+ ContactUsWebsite::ContactMailer.contact_email(self).deliver
23
+ return true
24
+ end
25
+ return false
26
+ end
27
+
28
+ def persisted?
29
+ false
30
+ end
31
+
32
+ end
@@ -0,0 +1,3 @@
1
+ <p><%= @contact.message %></p>
2
+ <p>---------------------</p>
3
+ <p><%= ContactUsWebsite.require_name ? t('.sent_by_name', :email => @contact.email, :name => @contact.name) : t('.sent_by_contact_form', :email => @contact.email) %></p>
@@ -0,0 +1,4 @@
1
+ <%= @contact.message %>
2
+
3
+ -------------------------------------
4
+ <%= ContactUsWebsite.require_name ? t('.sent_by_name', :email => @contact.email, :name => @contact.name) : t('.sent_by_contact_form', :email => @contact.email) %>
@@ -0,0 +1,47 @@
1
+ <h2><%= t('.contact_us') %></h2>
2
+ <%= form_for @contact, :url => contacts_path, :html => {:class => 'formtastic'} do |f| %>
3
+ <% if ContactUs.require_name %>
4
+ <li class='string required' id='contact_us_contact_name_input'>
5
+ <%= f.label :name, (t('.name') + content_tag(:abbr, '*', :class => 'required')).html_safe %>
6
+ <%= f.text_field :name %>
7
+ <% if f.object.errors[:name].present? %>
8
+ <p class='inline-error'><%= f.object.errors[:name].join(' and ') %></p>
9
+ <% end %>
10
+ </li>
11
+ <% end %>
12
+ <li class='string required' id='contact_us_contact_email_input'>
13
+ <%= f.label :email, (t('.email') + content_tag(:abbr, '*', :class => 'required')).html_safe %>
14
+ <%= f.text_field :email %>
15
+ <% if f.object.errors[:email].present? %>
16
+ <p class='inline-error'><%= f.object.errors[:email].join(' and ') %></p>
17
+ <% end %>
18
+ </li>
19
+ <% if ContactUs.require_website %>
20
+ <li class='string' id='contact_us_contact_website_input'>
21
+ <%= f.label :website, (t('.website') + content_tag(:abbr, '*', :class => 'contactleft')).html_safe %>
22
+ <%= f.text_field :website %>
23
+ <% if f.object.errors[:website].present? %>
24
+ <p class='inline-error'><%= f.object.errors[:website].join(' and ') %></p>
25
+ <% end %>
26
+ </li>
27
+ <% end %>
28
+ <% if ContactUs.require_subject %>
29
+ <li class='string required' id='contact_us_contact_subject_input'>
30
+ <%= f.label :subject, (t('.subject') + content_tag(:abbr, '*', :class => 'required')).html_safe %>
31
+ <%= f.text_field :subject %>
32
+ <% if f.object.errors[:subject].present? %>
33
+ <p class='inline-error'><%= f.object.errors[:subject].join(' and ') %></p>
34
+ <% end %>
35
+ </li>
36
+ <% end %>
37
+ <li class='text required' id='contact_us_contact_message_input'>
38
+ <%= f.label :message, (t('.message') + content_tag(:abbr, '*', :class => 'required')).html_safe %>
39
+ <%= f.text_area :message %>
40
+ <% if f.object.errors[:message].present? %>
41
+ <p class='inline-error'><%= f.object.errors[:message].join(' and ') %></p>
42
+ <% end %>
43
+ </li>
44
+ <li class='commit'>
45
+ <%= f.submit :submit, :alt => t('.submit'), :class => 'submit create', :label => t('.submit'), :title => t('.submit') %>
46
+ </li>
47
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <h2><%= t('.contact_us') %></h2>
2
+ <%= semantic_form_for @contact, :url => contacts_path do |f| %>
3
+ <%= f.input :name, :label => t('.name') if ContactUs.require_name %>
4
+ <%= f.input :email, :label => t('.email') %>
5
+ <%= f.input :website, :label => t('.website') %>
6
+ <%= f.input :subject, :label => t('.subject') if ContactUs.require_subject %>
7
+ <%= f.input :message, :as => :text, :label => t('.message') %>
8
+ <%= f.action :submit, :label => t('.submit'), :button_html => { :alt => t('.submit'), :id => 'contact_us_contact_submit', :title => t('.submit') } %>
9
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <h2><%= t('.contact_us') %></h2>
2
+ <%= simple_form_for @contact, :url => contacts_path do |f| %>
3
+ <%= f.input :name, :label => t('.name') if ContactUs.require_name %>
4
+ <%= f.input :email, :label => t('.email') %>
5
+ <%= f.input :website, :label => t('.website') %>
6
+ <%= f.input :subject, :label => t('.subject') if ContactUs.require_subject %>
7
+ <%= f.input :message, :as => :text, :label => t('.message') %>
8
+ <%= f.button :submit, :label => t('.submit'), :button_html => { :alt => t('.submit'), :id => 'contact_us_contact_submit', :title => t('.submit') } %>
9
+ <% end %>
@@ -0,0 +1,25 @@
1
+ # Sample localization file for German. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ de:
5
+ contact_us:
6
+ contact_mailer:
7
+ contact_email:
8
+ sent_by_contact_form: "Gesendet durch das Kontaktformular. %{email}"
9
+ sent_by_name: "Sent by %{name} from %{email}"
10
+ subject: "Contact Us message from %{email}"
11
+ contacts:
12
+ new: &new
13
+ contact_us: "Kontaktiere Uns"
14
+ email: "Email"
15
+ message: "Nachricht"
16
+ name: "Name"
17
+ subject: "Subject"
18
+ submit: "Abschicken"
19
+ new_formtastic:
20
+ <<: *new
21
+ new_simple_form:
22
+ <<: *new
23
+ notices:
24
+ error: "Beide Felder müssen ausgefüllt werden."
25
+ success: "Die Nachricht wurde erfolgreich versendet."
@@ -0,0 +1,25 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ contact_us:
6
+ contact_mailer:
7
+ contact_email:
8
+ sent_by_contact_form: "Sent by contact form from %{email}"
9
+ sent_by_name: "Sent by %{name} from %{email}"
10
+ subject: "Contact Us message from %{email}"
11
+ contacts:
12
+ new: &new
13
+ contact_us: "Contact Us"
14
+ email: "Email"
15
+ message: "Message"
16
+ name: "Name"
17
+ subject: "Subject"
18
+ submit: "Submit"
19
+ new_formtastic:
20
+ <<: *new
21
+ new_simple_form:
22
+ <<: *new
23
+ notices:
24
+ error: "You must enter both fields."
25
+ success: "Contact email was successfully sent."
@@ -0,0 +1,25 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ es:
5
+ contact_us:
6
+ contact_mailer:
7
+ contact_email:
8
+ sent_by_contact_form: "Enviado por el formulario de contacto. %{email}"
9
+ sent_by_name: "Sent by %{name} from %{email}"
10
+ subject: "Contact Us message from %{email}"
11
+ contacts:
12
+ new: &new
13
+ contact_us: "Contactanos"
14
+ email: "Email"
15
+ message: "Mensaje"
16
+ name: "Name"
17
+ subject: "Subject"
18
+ submit: "Enviar"
19
+ new_formtastic:
20
+ <<: *new
21
+ new_simple_form:
22
+ <<: *new
23
+ notices:
24
+ error: "Debes de ingresar ambos campos."
25
+ success: "El correo electrónico de contacto fue enviado con éxito."
@@ -0,0 +1,25 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ it:
5
+ contact_us:
6
+ contact_mailer:
7
+ contact_email:
8
+ sent_by_contact_form: "Inviato dal formato di contatto. %{email}"
9
+ sent_by_name: "Sent by %{name} from %{email}"
10
+ subject: "Contact Us message from %{email}"
11
+ contacts:
12
+ new: &new
13
+ contact_us: "Contattaci"
14
+ email: "Email"
15
+ message: "Messaggio"
16
+ name: "Name"
17
+ subject: "Subject"
18
+ submit: "Inviare"
19
+ new_formtastic:
20
+ <<: *new
21
+ new_simple_form:
22
+ <<: *new
23
+ notices:
24
+ error: "Devi inserire entrambi i campi."
25
+ success: "La mail di contatto è stata inviata."
@@ -0,0 +1,25 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ contact_us:
6
+ contact_mailer:
7
+ contact_email:
8
+ sent_by_contact_form: "お問い合せメールを送信しました : %{email}"
9
+ sent_by_name: "%{name} さんがお問い合せメールを送信しました : %{email}"
10
+ subject: "お問い合わせメール : %{email}"
11
+ contacts:
12
+ new: &new
13
+ contact_us: "お問い合わせ"
14
+ email: "メールアドレス"
15
+ message: "お問い合せ内容"
16
+ name: "お名前"
17
+ subject: "件名"
18
+ submit: "送信する"
19
+ new_formtastic:
20
+ <<: *new
21
+ new_simple_form:
22
+ <<: *new
23
+ notices:
24
+ error: "すべての項目を入力してください。"
25
+ success: "お問い合わせを送信しました。"