spree_mini_contact 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ SpreeMiniContact
2
+ ================
3
+
4
+ Basically the easiest way to implement a contact form.
5
+
6
+ Installation
7
+ ============
8
+
9
+ Put the following line into your gemfile:
10
+
11
+ gem 'spree_mini_contact'
12
+
13
+ Install it.
14
+
15
+ bundle install
16
+
17
+ Add the migrations.
18
+
19
+ rake spree_mini_contact:install
20
+
21
+ Run the migration.
22
+
23
+ rake db:migrate
24
+
25
+ Done SRLY!
26
+
27
+ It will save the messages in the database so they will also be
28
+ available in the admin interface (/admin/contacts).
29
+
30
+ Set properly the mail method in the admin area (/admin/mail_methods)
31
+
32
+ ## Note on Patches/Pull Requests:
33
+
34
+ * Fork the project.
35
+ * Make your feature addition or bug fix.
36
+ * Send me a pull request. Bonus points for topic branches.
37
+
38
+ ## Copyright:
39
+
40
+ (The MIT License)
41
+
42
+ Copyright 2011 Jose Pablo Barrantes. MIT Licence, so go for it.
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining a
45
+ copy of this software and associated documentation files (the
46
+ 'Software'), to deal in the Software without restriction, including
47
+ without limitation the rights to use, copy, modify, merge, publish,
48
+ distribute, sublicense, an d/or sell copies of the Software, and to
49
+ permit persons to whom the Software is furnished to do so, subject to
50
+ the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be included
53
+ in all copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS
56
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
57
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
58
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
59
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
60
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
61
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ class Admin::ContactsController < Admin::BaseController
2
+
3
+ resource_controller
4
+
5
+ end
@@ -0,0 +1,23 @@
1
+ class ContactsController < Spree::BaseController
2
+
3
+ def new
4
+ @contact = Contact.new
5
+ end
6
+
7
+ def edit
8
+ redirect_to new_contact_path
9
+ end
10
+
11
+ def create
12
+ @contact = Contact.new(params[:contact] || {})
13
+ respond_to do |format|
14
+ if @contact.valid? && @contact.save
15
+ ContactMailer.message_email(@contact).deliver
16
+ format.html { redirect_to(contact_path, :notice => t("message_sent")) }
17
+ else
18
+ format.html { render :action => "new" }
19
+ end
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,7 @@
1
+ module Admin::ContactsHelper
2
+
3
+ def link_to_view(resource)
4
+ link_to_with_icon('view', t('view'), object_url(resource))
5
+ end
6
+
7
+ end
@@ -0,0 +1,10 @@
1
+ class ContactMailer < ActionMailer::Base
2
+ helper "spree/base"
3
+
4
+ def message_email(message)
5
+ subject = "#{Spree::Config[:site_name]} - #{t('message_from')} #{message.email}"
6
+
7
+ @message = message
8
+ mail(:to => message.email, :subject => subject, :reply_to => message.email)
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ class Contact < ActiveRecord::Base
2
+ validates :name, :presence => true
3
+ validates :email, :format => {:with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i}
4
+ end
@@ -0,0 +1,34 @@
1
+ <h1><%= t("contacts")%></h1>
2
+
3
+ <table class="index">
4
+ <tr>
5
+ <%= hook :admin_contact_index_headers do %>
6
+ <th><%= t("name") %></th>
7
+ <th><%= t("email") %></th>
8
+ <th><%= t("phone") %></th>
9
+ <th><%= t("subject") %></th>
10
+ <% end %>
11
+ <th>
12
+ <%= hook :admin_contact_index_header_actions %>
13
+ </th>
14
+ </tr>
15
+ <% @contacts.each do |contact| %>
16
+ <tr id="<%= dom_id contact %>">
17
+ <%- locals = {:contact => contact} %>
18
+ <%= hook :admin_contact_index_rows, locals do %>
19
+ <td><%= contact.name %></td>
20
+ <td><%= contact.email %></td>
21
+ <td><%= contact.phone %></td>
22
+ <td><%= contact.subject %></td>
23
+ <td><%= contact.created_at %></td>
24
+ <% end %>
25
+ <td class="actions">
26
+ <%= hook :admin_contact_index_row_actions, locals do %>
27
+ <%= link_to_view contact %>
28
+ &nbsp;
29
+ <%= link_to_delete contact %>
30
+ <% end %>
31
+ </td>
32
+ </tr>
33
+ <% end %>
34
+ </table>
@@ -0,0 +1,40 @@
1
+ <h1><%= "#{t('contacts')} #{t('from')} #{@contact.name}" %></h1>
2
+
3
+ <%= render :partial => 'admin/shared/contact_tabs', :locals => {:current => "Contact Details"} %>
4
+
5
+ <%= hook :admin_contact_show do %>
6
+ <div class="adr">
7
+ <h4><%= t("name") %></h4>
8
+ <p>
9
+ <%= @contact.name %><br />
10
+ </p>
11
+ </div>
12
+
13
+ <div class="adr">
14
+ <h4><%= t("email") %></h4>
15
+ <p>
16
+ <%= @contact.email %><br />
17
+ </p>
18
+ </div>
19
+
20
+ <div class="adr">
21
+ <h4><%= t("phone") %></h4>
22
+ <p>
23
+ <%= @contact.phone %><br />
24
+ </p>
25
+ </div>
26
+
27
+ <div class="adr">
28
+ <h4><%= t("subject") %></h4>
29
+ <p>
30
+ <%= @contact.subject %><br />
31
+ </p>
32
+ </div>
33
+
34
+ <div class="adr">
35
+ <h4><%= t("message") %></h4>
36
+ <p>
37
+ <%= @contact.message %>
38
+ </p>
39
+ </div>
40
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <% content_for :sidebar do %>
2
+ <ul class="sidebar">
3
+ <%= hook :admin_contact_tabs do %>
4
+ <li<%== ' class="active"' if current == 'Contact List' %>>
5
+ <%= link_to t("contact_list"), collection_url() %>
6
+ </li>
7
+ <li<%== ' class="active"' if current == 'Contact Details' %>>
8
+ <%= link_to t("contact_details"), object_url(@contact) %>
9
+ </li>
10
+ <% end %>
11
+ </ul>
12
+ <% end %>
@@ -0,0 +1,31 @@
1
+ <% @body_id = 'contact' %>
2
+ <div id="contact-us">
3
+ <%= hook :contact do %>
4
+ <%= render "shared/error_messages", :target => @contact %>
5
+ <%= form_for(@contact) do |f| %>
6
+ <%= hook :contact_inside_form do %>
7
+ <div class="field">
8
+ <%= f.label :name, t("name") %><br />
9
+ <%= f.text_field :name %>
10
+ </div>
11
+ <div class="field">
12
+ <%= f.label :email, t("email") %><br />
13
+ <%= f.text_field :email %>
14
+ </div>
15
+ <div class="field">
16
+ <%= f.label :phone, t("phone") %><br />
17
+ <%= f.text_field :phone %>
18
+ </div>
19
+ <div class="field">
20
+ <%= f.label :subject, t("subject") %><br />
21
+ <%= f.text_field :subject %>
22
+ </div>
23
+ <div class="field">
24
+ <%= f.label :message, t("message") %><br />
25
+ <%= f.text_area :message %>
26
+ </div>
27
+ <div class="action"><%= f.submit t("send_message"), :class => "button primary" %></div>
28
+ <% end %>
29
+ <% end %>
30
+ <% end %>
31
+ </div>
@@ -0,0 +1,5 @@
1
+ spree_mini_contact<%= t('name') %>: <%= @message.name %>
2
+ <%= t('email') %>: <%= @message.email %>
3
+ <%= t('phone') %>: <%= @message.phone %>
4
+ <%= t('subject') %>: <%= @message.subject %>
5
+ <%= @message.message %>
@@ -0,0 +1,5 @@
1
+ <%= t('name') %>: <%= @message.name %>
2
+ <%= t('email') %>: <%= @message.email %>
3
+ <%= t('phone') %>: <%= @message.phone %>
4
+ <%= t('subject') %>: <%= @message.subject %>
5
+ <%= @message.message %>
@@ -0,0 +1,20 @@
1
+ en:
2
+ contacts: Contacts
3
+ contact: Contact us
4
+ name: Name
5
+ email: Email
6
+ sent: Sent
7
+ view: View
8
+ message: Message
9
+ order_number: Order number
10
+ optionnal: optional
11
+ name: Name
12
+ email: Email
13
+ phone: Phone
14
+ subject: Subject
15
+ contact_details: Contact details
16
+ contact_list: Contacts list
17
+ send_message: Send message
18
+ message_sent: Thank You - Your email has been sent!
19
+ from: from
20
+ message_from: Message from
data/config/routes.rb ADDED
@@ -0,0 +1,10 @@
1
+ Rails.application.routes.draw do
2
+ match '/contact-us' => 'contacts#new', :as => :contact
3
+
4
+ resources :contacts, :controller => 'contacts'
5
+
6
+ namespace :admin do
7
+ resources :contacts
8
+ end
9
+
10
+ end
@@ -0,0 +1,16 @@
1
+ class CreateContactTable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :contacts do |t|
4
+ t.string :name
5
+ t.string :email
6
+ t.string :subject
7
+ t.string :phone
8
+ t.text :message
9
+ t.timestamps
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :contacts
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ require 'spree_core'
2
+ require 'spree_mini_contact_hooks'
3
+
4
+ module SpreeMiniContact
5
+ class Engine < Rails::Engine
6
+
7
+ config.autoload_paths += %W(#{config.root}/lib)
8
+
9
+ def self.activate
10
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
11
+ Rails.env.production? ? require(c) : load(c)
12
+ end
13
+ end
14
+
15
+ config.to_prepare &method(:activate).to_proc
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ class SpreeMiniContactHooks < Spree::ThemeSupport::HookListener
2
+
3
+ insert_after :admin_tabs do
4
+ %(<%= tab(:contacts) %>)
5
+ end
6
+
7
+ end
@@ -0,0 +1,25 @@
1
+ namespace :spree_mini_contact do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_mini_contact:install:migrations'].invoke
5
+ Rake::Task['spree_mini_contact:install:assets'].invoke
6
+ end
7
+
8
+ namespace :install do
9
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
10
+ task :migrations do
11
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
12
+ destination = File.join(Rails.root, 'db')
13
+ Spree::FileUtilz.mirror_files(source, destination)
14
+ end
15
+
16
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
17
+ task :assets do
18
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
19
+ destination = File.join(Rails.root, 'public')
20
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
21
+ Spree::FileUtilz.mirror_files(source, destination)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1 @@
1
+ # add custom rake tasks here
Binary file
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_mini_contact
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jose Pablo Barrantes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-04 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: spree_core
16
+ requirement: &23530300 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.40.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *23530300
25
+ description: ! " Easy to implement contact form.\n It stores all messages in
26
+ DB for an easy recall of messages.\n"
27
+ email: xjpablobrx@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files:
31
+ - README.md
32
+ files:
33
+ - README.md
34
+ - LICENSE
35
+ - lib/spree_mini_contact.rb
36
+ - lib/spree_mini_contact_hooks.rb
37
+ - lib/tasks/spree_mini_contact.rake
38
+ - lib/tasks/install.rake
39
+ - app/views/admin/contacts/show.html.erb
40
+ - app/views/admin/contacts/index.html.erb
41
+ - app/views/admin/shared/_contact_tabs.html.erb
42
+ - app/views/contacts_mailer/message_email.text.erb
43
+ - app/views/contacts_mailer/#message_email.text.erb#
44
+ - app/views/contacts/new.html.erb
45
+ - app/controllers/admin/contacts_controller.rb
46
+ - app/controllers/contacts_controller.rb
47
+ - app/models/contact.rb
48
+ - app/mailer/contact_mailer.rb
49
+ - app/helpers/admin/contacts_helper.rb
50
+ - public/images/admin/icons/view.png
51
+ - db/migrate/20110203113622_create_contact_table.rb
52
+ - config/routes.rb
53
+ - config/locales/en.yml
54
+ homepage: https://github.com/jpablobr/spree_mini_contact
55
+ licenses:
56
+ - BSD
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: 1.8.7
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements:
74
+ - none
75
+ rubyforge_project:
76
+ rubygems_version: 1.8.10
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Easy to implement contact form.
80
+ test_files: []
81
+ has_rdoc: true