contact_us_website 0.4.4.beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -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
+ pt-BR:
5
+ contact_us:
6
+ contact_mailer:
7
+ contact_email:
8
+ sent_by_contact_form: "Enviado pelo formulário de contato. %{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: "Contate-nos"
14
+ email: "Email"
15
+ message: "Messagem"
16
+ name: "Name"
17
+ subject: "Subject"
18
+ submit: "Enviar"
19
+ new_formtastic:
20
+ <<: *new
21
+ new_simple_form:
22
+ <<: *new
23
+ notices:
24
+ error: "Você deve preencher os campos."
25
+ success: "Email de contato foi enviado com sucesso."
@@ -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
+ zh:
5
+ contact_us:
6
+ contact_mailer:
7
+ contact_email:
8
+ sent_by_contact_form: "由contact form发送。 %{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: "联系我们"
14
+ email: "邮箱"
15
+ message: "消息"
16
+ name: "Name"
17
+ subject: "Subject"
18
+ submit: "发送"
19
+ new_formtastic:
20
+ <<: *new
21
+ new_simple_form:
22
+ <<: *new
23
+ notices:
24
+ error: "请正确输入邮箱与信息。"
25
+ success: "邮件已成功发送。"
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+ resources :contacts,
3
+ :controller => 'contact_us/contacts',
4
+ :only => [:new, :create]
5
+ match 'contact-us' => 'contact_us/contacts#new', :as => :contact_us
6
+ end
data/lib/contact_us.rb ADDED
@@ -0,0 +1,25 @@
1
+ module ContactUsWebsite
2
+ require 'contact_us/engine'
3
+
4
+ # Address ContactUsWebsite email notifications are sent from.
5
+ mattr_accessor :mailer_from
6
+
7
+ # Address to send ContactUsWebsite email notifications to.
8
+ mattr_accessor :mailer_to
9
+
10
+ # Enable or Disable name field.
11
+ mattr_accessor :require_name
12
+
13
+ # Enable or Disable subject field.
14
+ mattr_accessor :require_subject
15
+
16
+ # Formtastic or SimpleForm
17
+ mattr_accessor :form_gem
18
+
19
+ # Default way to setup ContactUsWebsite. Run rake contact_us:install to create
20
+ # a fresh initializer with all configuration values.
21
+ def self.setup
22
+ yield self
23
+ end
24
+
25
+ end
@@ -0,0 +1,7 @@
1
+ require "contact_us"
2
+ require "rails"
3
+
4
+ module ContactUsWebsite
5
+ class Engine < Rails::Engine
6
+ end
7
+ end
@@ -0,0 +1,74 @@
1
+ require 'rails/generators'
2
+
3
+ module ContactUsWebsite
4
+ module Tasks
5
+ class Install
6
+ class << self
7
+
8
+ def run
9
+ copy_initializer_file
10
+ copy_locales_files
11
+ copy_view_files
12
+ puts "Done!"
13
+ end
14
+
15
+ def copy_initializer_file
16
+ print "Copying initializer file...\n"
17
+ app_path = Rails.root.join("config/initializers")
18
+ copier.copy_file File.join(gem_path, 'lib/templates/contact_us.rb'), File.join(app_path, 'contact_us.rb')
19
+ end
20
+
21
+ def copy_locales_files
22
+ print "Copying locales files...\n"
23
+ locales_path = gem_path + "/config/locales/*.yml"
24
+ app_path = Rails.root.join("config/locales")
25
+
26
+ unless File.directory?(app_path)
27
+ app_path.mkdir
28
+ end
29
+
30
+ Dir.glob(locales_path).each do |file|
31
+ copier.copy_file file, File.join(app_path, File.basename(file))
32
+ end
33
+ end
34
+
35
+ def copy_view_files
36
+ print "Copying view files...\n"
37
+ origin = File.join(gem_path, 'app/views')
38
+ destination = Rails.root.join('app/views')
39
+ copy_files(['.'], origin, destination)
40
+ end
41
+
42
+ private
43
+
44
+ def copy_files(directories, origin, destination)
45
+ directories.each do |directory|
46
+ Dir[File.join(origin, directory, 'contact_us', '**/*')].each do |file|
47
+ relative = file.gsub(/^#{origin}\//, '')
48
+ dest_file = File.join(destination, relative)
49
+ dest_dir = File.dirname(dest_file)
50
+
51
+ if !File.exist?(dest_dir)
52
+ FileUtils.mkdir_p(dest_dir)
53
+ end
54
+
55
+ copier.copy_file(file, dest_file) unless File.directory?(file)
56
+ end
57
+ end
58
+ end
59
+
60
+ def gem_path
61
+ File.expand_path('../../..', File.dirname(__FILE__))
62
+ end
63
+
64
+ def copier
65
+ unless @copier
66
+ Rails::Generators::Base.source_root(gem_path)
67
+ @copier = Rails::Generators::Base.new
68
+ end
69
+ @copier
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ module ContactUsWebsite
2
+ VERSION = "0.4.4.beta"
3
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path('../../contact_us/tasks/install', __FILE__)
2
+
3
+ namespace :contact_us do
4
+ desc "Install contact_us"
5
+ task :install do
6
+ ContactUsWebsite::Tasks::Install.run
7
+ end
8
+
9
+ desc "Copy only locale files (part of install, but useful for updates when only assets are needed)"
10
+ task :copy_locales do
11
+ ContactUsWebsite::Tasks::Install.copy_locales_files
12
+ end
13
+
14
+ desc "Copy only view files (part of install, but useful for updates when only assets are needed)"
15
+ task :copy_views do
16
+ ContactUsWebsite::Tasks::Install.copy_view_files
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ # Use this hook to configure contact mailer.
2
+ ContactUsWebsite.setup do |config|
3
+
4
+ # ==> Mailer Configuration
5
+
6
+ # Configure the e-mail address which email notifications should be sent from. If emails must be sent from a verified email address you may set it here.
7
+ # Example:
8
+ # config.mailer_from = "contact@please-change-me.com"
9
+ config.mailer_from = nil
10
+
11
+ # Configure the e-mail address which should receive the contact form email notifications.
12
+ config.mailer_to = "contact@please-change-me.com"
13
+
14
+ # ==> Form Configuration
15
+
16
+ # Configure the form to ask for the users name.
17
+ config.require_name = false
18
+
19
+ # Configure the form to ask for a subject.
20
+ config.require_subject = false
21
+
22
+ # Configure the form gem to use.
23
+ # Example:
24
+ # config.form_gem = 'formtastic
25
+ config.form_gem = nil
26
+
27
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe ContactUs::ContactsController do
4
+
5
+ describe 'create' do
6
+
7
+ it 'should redirect with success message if valid contact' do
8
+ post :create, :contact_us_contact => { :email => 'test@test.com', :message => 'test' }
9
+ assigns(:contact).valid?.should eql(true)
10
+ flash[:notice].should eql('Contact email was successfully sent.')
11
+ response.should redirect_to('/')
12
+ end
13
+
14
+ it 'should render new with error message if invalid contact' do
15
+ post :create, :contact_us_contact => { :email => 'test@test.com', :message => '' }
16
+ assigns(:contact).valid?.should eql(false)
17
+ flash[:error].should eql('You must enter both fields.')
18
+ response.should render_template('new')
19
+ end
20
+
21
+ end
22
+
23
+ describe 'new' do
24
+
25
+ it 'should assign contact for form and render page successfully' do
26
+ get :new
27
+ assigns(:contact).should be_an_instance_of(ContactUs::Contact)
28
+ response.should be_success
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '3.0.9'
4
+ gem 'contact_us', :path => '../../'
5
+ gem "formtastic", ">= 1.2.0"
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,43 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+ require 'formtastic'
5
+
6
+ # If you have a Gemfile, require the gems listed there, including any gems
7
+ # you've limited to :test, :development, or :production.
8
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
9
+
10
+ module Dummy
11
+ class Application < Rails::Application
12
+ # Settings in config/environments/* take precedence over those specified here.
13
+ # Application configuration should go into files in config/initializers
14
+ # -- all .rb files in that directory are automatically loaded.
15
+
16
+ # Custom directories with classes and modules you want to be autoloadable.
17
+ # config.autoload_paths += %W(#{config.root}/extras)
18
+
19
+ # Only load the plugins named here, in the order given (default is alphabetical).
20
+ # :all can be used as a placeholder for all plugins not explicitly named.
21
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
22
+
23
+ # Activate observers that should always be running.
24
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
25
+
26
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
27
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
28
+ # config.time_zone = 'Central Time (US & Canada)'
29
+
30
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
31
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
32
+ # config.i18n.default_locale = :de
33
+
34
+ # JavaScript files you want as :defaults (application.js is always included).
35
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
36
+
37
+ # Configure the default encoding used in templates for Ruby 1.9.
38
+ config.encoding = "utf-8"
39
+
40
+ # Configure sensitive parameters which will be filtered from the log file.
41
+ config.filter_parameters += [:password]
42
+ end
43
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,11 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+
4
+ # Warning: The database defined as "test" will be erased and
5
+ # re-generated from your development database when you run "rake".
6
+ # Do not set this db to the same as development or production.
7
+
8
+ test:
9
+ adapter: sqlite3
10
+ database: ":memory:"
11
+ timeout: 500
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,26 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the webserver when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_view.debug_rjs = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Don't care if the mailer can't send
18
+ config.action_mailer.raise_delivery_errors = false
19
+
20
+ # Print deprecation notices to the Rails logger
21
+ config.active_support.deprecation = :log
22
+
23
+ # Only use best-standards-support built into browsers
24
+ config.action_dispatch.best_standards_support = :builtin
25
+ end
26
+
@@ -0,0 +1,49 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The production environment is meant for finished, "live" apps.
5
+ # Code is not reloaded between requests
6
+ config.cache_classes = true
7
+
8
+ # Full error reports are disabled and caching is turned on
9
+ config.consider_all_requests_local = false
10
+ config.action_controller.perform_caching = true
11
+
12
+ # Specifies the header that your server uses for sending files
13
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
+
15
+ # For nginx:
16
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
17
+
18
+ # If you have no front-end server that supports something like X-Sendfile,
19
+ # just comment this out and Rails will serve the files
20
+
21
+ # See everything in the log (default is :info)
22
+ # config.log_level = :debug
23
+
24
+ # Use a different logger for distributed setups
25
+ # config.logger = SyslogLogger.new
26
+
27
+ # Use a different cache store in production
28
+ # config.cache_store = :mem_cache_store
29
+
30
+ # Disable Rails's static asset server
31
+ # In production, Apache or nginx will already do this
32
+ config.serve_static_assets = false
33
+
34
+ # Enable serving of images, stylesheets, and javascripts from an asset server
35
+ # config.action_controller.asset_host = "http://assets.example.com"
36
+
37
+ # Disable delivery errors, bad email addresses will be ignored
38
+ # config.action_mailer.raise_delivery_errors = false
39
+
40
+ # Enable threaded mode
41
+ # config.threadsafe!
42
+
43
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44
+ # the I18n.default_locale when a translation can not be found)
45
+ config.i18n.fallbacks = true
46
+
47
+ # Send deprecation notices to registered listeners
48
+ config.active_support.deprecation = :notify
49
+ end