fullstack-contacts 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails'
4
+
5
+ group :development do
6
+ gem "bundler"
7
+ gem "jeweler", "~> 1.8.4"
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,94 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.11)
5
+ actionpack (= 3.2.11)
6
+ mail (~> 2.4.4)
7
+ actionpack (3.2.11)
8
+ activemodel (= 3.2.11)
9
+ activesupport (= 3.2.11)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.4)
13
+ rack (~> 1.4.0)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.2.1)
17
+ activemodel (3.2.11)
18
+ activesupport (= 3.2.11)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.11)
21
+ activemodel (= 3.2.11)
22
+ activesupport (= 3.2.11)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.11)
26
+ activemodel (= 3.2.11)
27
+ activesupport (= 3.2.11)
28
+ activesupport (3.2.11)
29
+ i18n (~> 0.6)
30
+ multi_json (~> 1.0)
31
+ arel (3.0.2)
32
+ builder (3.0.4)
33
+ erubis (2.7.0)
34
+ git (1.2.5)
35
+ hike (1.2.1)
36
+ i18n (0.6.1)
37
+ jeweler (1.8.4)
38
+ bundler (~> 1.0)
39
+ git (>= 1.2.5)
40
+ rake
41
+ rdoc
42
+ journey (1.0.4)
43
+ json (1.7.6)
44
+ mail (2.4.4)
45
+ i18n (>= 0.4.0)
46
+ mime-types (~> 1.16)
47
+ treetop (~> 1.4.8)
48
+ mime-types (1.19)
49
+ multi_json (1.5.0)
50
+ polyglot (0.3.3)
51
+ rack (1.4.4)
52
+ rack-cache (1.2)
53
+ rack (>= 0.4)
54
+ rack-ssl (1.3.3)
55
+ rack
56
+ rack-test (0.6.2)
57
+ rack (>= 1.0)
58
+ rails (3.2.11)
59
+ actionmailer (= 3.2.11)
60
+ actionpack (= 3.2.11)
61
+ activerecord (= 3.2.11)
62
+ activeresource (= 3.2.11)
63
+ activesupport (= 3.2.11)
64
+ bundler (~> 1.0)
65
+ railties (= 3.2.11)
66
+ railties (3.2.11)
67
+ actionpack (= 3.2.11)
68
+ activesupport (= 3.2.11)
69
+ rack-ssl (~> 1.3.2)
70
+ rake (>= 0.8.7)
71
+ rdoc (~> 3.4)
72
+ thor (>= 0.14.6, < 2.0)
73
+ rake (10.0.3)
74
+ rdoc (3.12)
75
+ json (~> 1.4)
76
+ sprockets (2.2.2)
77
+ hike (~> 1.2)
78
+ multi_json (~> 1.0)
79
+ rack (~> 1.0)
80
+ tilt (~> 1.1, != 1.3.0)
81
+ thor (0.17.0)
82
+ tilt (1.3.3)
83
+ treetop (1.4.12)
84
+ polyglot
85
+ polyglot (>= 0.3.1)
86
+ tzinfo (0.3.35)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ bundler
93
+ jeweler (~> 1.8.4)
94
+ rails
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # Fullstack-contacts
2
+
3
+ Contact form and backend for fullstack-cms
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ``` rb
10
+ gem 'fullstack-contacts'
11
+ ```
12
+
13
+ ``` sh
14
+ rails g fullstack:contacts:install
15
+ ```
16
+
17
+ Edit `app/models/contact.rb` to customize `Contact` model and then run:
18
+
19
+ ``` rb
20
+ rails g migration:from contact && rake db:migrate
21
+ ```
22
+
23
+ You may also wish to customize front-end views editing:
24
+
25
+ - `app/views/contacts_mailer/confirmation.html.erb`
26
+ - `app/views/contacts_mailer/notify.html.erb`
27
+ - `app/views/fullstack/contacts/_form.html.erb`
28
+ - `app/views/fullstack/contacts/_success.html.erb`
29
+
30
+
31
+ ## Administration
32
+
33
+ Enable contacts back-end in config/initializers/fullstack.rb:
34
+
35
+ ``` rb
36
+ # ...
37
+ admin.group :contacts do |g|
38
+ g.icon= "user"
39
+ g.resource :contacts
40
+ end
41
+
42
+ ```
43
+
44
+ Install a widget inside your admin/dashboard to view the latest contacts:
45
+
46
+ ``` erb
47
+ <%= contacts_dashboard_widget %>
48
+ ```
49
+
50
+ ## Usage
51
+
52
+ ``` rb
53
+ class Site::SiteController < Site::BaseController
54
+ include Fullstack::Contacts::Actions
55
+
56
+ page :home, "/" do
57
+ end
58
+
59
+ page :contacts, "/contacts", :parent => :home do
60
+ @contact = Contact.new
61
+ end
62
+
63
+ action :contact, "/contact", :via => :post do
64
+ create_contact!(:success => polymorphic_path([:site, :contacts], :success => true))
65
+ end
66
+ # ...
67
+
68
+ end
69
+ ```
70
+
71
+ ``` rhtml
72
+ <!-- site/site/contacts.html.erb -->
73
+
74
+ <% if params[:success] %>
75
+ <%= contact_success %>
76
+ <% else %>
77
+ <%= contact_form %>
78
+ <% end %>
79
+
80
+ ```
81
+
82
+ Copyright (c) 2012 mcasimir
83
+
84
+ MIT License
85
+
86
+ Permission is hereby granted, free of charge, to any person obtaining
87
+ a copy of this software and associated documentation files (the
88
+ "Software"), to deal in the Software without restriction, including
89
+ without limitation the rights to use, copy, modify, merge, publish,
90
+ distribute, sublicense, and/or sell copies of the Software, and to
91
+ permit persons to whom the Software is furnished to do so, subject to
92
+ the following conditions:
93
+
94
+ The above copyright notice and this permission notice shall be
95
+ included in all copies or substantial portions of the Software.
96
+
97
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
98
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
99
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
100
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
101
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
102
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
103
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "fullstack-contacts"
18
+ gem.homepage = "http://github.com/mcasimir/kaminari-bootstrap"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Contact form and backend for fullstack-cms}
21
+ gem.description = %Q{Contact form and backend for fullstack-cms}
22
+ gem.email = "maurizio.cas@gmail.com"
23
+ gem.authors = ["mcasimir"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+
29
+ task :push do
30
+ message = ENV["message"] || "commit #{Time.now}"
31
+ `git add . && git commit -a -m '#{message}' && git push`
32
+ end
33
+
34
+ task "release:patch" do
35
+ Rake::Task["gemspec"].invoke
36
+ Rake::Task["version:bump:patch"]
37
+ Rake::Task["push"].invoke
38
+ Rake::Task["release"].invoke
39
+ end
40
+
41
+ task "release:minor" do
42
+ Rake::Task["gemspec"].invoke
43
+ Rake::Task["version:bump:minor"]
44
+ Rake::Task["push"].invoke
45
+ Rake::Task["release"].invoke
46
+ end
47
+
48
+ task "release:major" do
49
+ Rake::Task["gemspec"].invoke
50
+ Rake::Task["version:bump:major"]
51
+ Rake::Task["push"].invoke
52
+ Rake::Task["release"].invoke
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.3
@@ -0,0 +1,11 @@
1
+ class Admin::ContactsController < Admin::BaseController
2
+ def show
3
+ @contact ||= Contact.find(params[:id])
4
+ @contact.read!
5
+ render :layout => false
6
+ end
7
+
8
+ def index
9
+ @contacts = Contact.order("created_at DESC").page(params[:page])
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ module ContactsHelper
2
+
3
+ def contact_success
4
+ render :partial => "fullstack/contacts/success"
5
+ end
6
+
7
+ def contact_form
8
+ render :partial => "fullstack/contacts/form"
9
+ end
10
+
11
+ def contacts_dashboard_widget
12
+ contacts = Contact.order("created_at DESC").limit(5)
13
+ render :partial => "admin/contacts/contacts_dashboard_widget", :locals => { :contacts => contacts }
14
+ end
15
+
16
+ end
File without changes
@@ -0,0 +1,15 @@
1
+ class ContactsMailer < ActionMailer::Base
2
+ default from: "#{Settings.app.title} <no-reply@#{Settings.app.domain}>"
3
+
4
+ def confirmation(contact)
5
+ @contact = contact
6
+ mail(:to => @contact.email, :subject => I18n.t("contacts.confirmation.subject"))
7
+ end
8
+
9
+ def notify(contact)
10
+ @contact = contact
11
+ recipient = Setting.where(:key => "notifies_recipient", :group => "contacts").first.try(:value) || Settings.app.notifies_recipient
12
+ mail(:to => recipient, :subject => "#{Settings.app.domain}: #{I18n.t('contacts.contact_request_from', :from => @contact.name)}")
13
+ end
14
+
15
+ end
@@ -0,0 +1,9 @@
1
+ <div class="box">
2
+ <div class="box-header"><%= t("contacts.latest_contact_requests", :default => "Latest Contact Requests") %></div>
3
+ <div class="box-content">
4
+ <%= render :partial => "admin/contacts/contacts_table", :locals => { :contacts => contacts } %>
5
+ </div>
6
+ <div class="box-footer">
7
+ <%= link_to t("contacts.display_all", :default => "Display All"), admin_contacts_path %>
8
+ </div>
9
+ </div>
@@ -0,0 +1,41 @@
1
+ <table class="table table-striped table-bordered">
2
+ <tr>
3
+ <th><%= t("helpers.label.subject", :default => "Subject") %></th>
4
+ <th><%= t("helpers.label.sent_by", :default => "Sent by") %></th>
5
+ <th><%= t("helpers.label.sent_at", :default => "Sent at") %></th>
6
+ <th></th>
7
+ </tr>
8
+
9
+ <% contacts.each do |contact| %>
10
+ <% if contact.unread? %>
11
+ <tr class="info">
12
+ <% else %>
13
+ <tr>
14
+ <% end %>
15
+ <td>
16
+ <% if contact.text.present? %>
17
+ <%= truncate(contact.text, :limit => 30) %>
18
+ <% else %>
19
+ <i>(<%= t("contacts.subject_empty", :default => "Subject empty") %>)</i>
20
+ <% end %>
21
+ </td>
22
+ <td><%= contact.name %> <i>(<%= contact.email %>)</i></td><td><%= l(contact.created_at, :format => :pubdate) %></td>
23
+ <td><%= link_to t("contacts.read", :default => "Read"), admin_contact_path(contact), :rel => "facebox", :class => "read-contact-link" %></td>
24
+ </tr>
25
+ <% end %>
26
+ </table>
27
+
28
+
29
+
30
+ <% content_for :javascripts do -%>
31
+ <script type="text/javascript" charset="utf-8">
32
+ $(document).ready(function(){
33
+
34
+ $(".read-contact-link").click(function(){
35
+ $(this).closest("tr").removeClass("info");
36
+ });
37
+
38
+ });
39
+ </script>
40
+
41
+ <% end -%>
@@ -0,0 +1,6 @@
1
+ <h1 class="page-header">
2
+ Richieste di contatto
3
+ </h1>
4
+
5
+ <%= render :partial => "admin/contacts/contacts_table", :locals => { :contacts => @contacts } %>
6
+ <%= paginate(@contacts) %>
@@ -0,0 +1,20 @@
1
+ <div class="modal-header">
2
+ <h3><%= t("contacts.contact_request_from", :from => @contact.name) %></h3>
3
+ </div>
4
+ <div class="modal-body">
5
+ <dl class="dl-horizontal">
6
+ <dt><%= t("helpers.label.sent_at", :default => "Sent at") %></dt>
7
+ <dd><%= l(@contact.created_at, :format => :long) %></dd>
8
+
9
+
10
+ <dt><%= t("helpers.label.first_name", :default => "First name") %></dt>
11
+ <dd><%= @contact.first_name || "-" %></dd>
12
+ <dt><%= t("helpers.label.second_name", :default => "Second name") %></dt>
13
+ <dd><%= @contact.second_name || "-" %></dd>
14
+ <dt><%= t("helpers.label.email", :default => "Email") %></dt>
15
+ <dd><%= @contact.email || "-" %></dd>
16
+ <dt><%= t("helpers.label.subject", :default => "Subject") %></dt>
17
+ <dd><%= @contact.text || "-" %></dd>
18
+
19
+ </dl>
20
+ </div>
@@ -0,0 +1,19 @@
1
+ en:
2
+ contacts:
3
+ subject_empty: "Subject is empty"
4
+ read: "Read"
5
+ latest_contact_requests: "Latest contact requests"
6
+ display_all: "Display all"
7
+ success: "Thank you for contacting us. We will get back to you as soon as possible."
8
+ contact_request_from: "New contact request from %{from}"
9
+ send: "Send"
10
+
11
+ confirmation:
12
+ subject: "Thank you for contacting us"
13
+ body: |
14
+ Dear %{first_name},
15
+
16
+ Thank you for contacting us through our website %{site_name}
17
+ We will get back to you as soon as possible.
18
+
19
+ If you think that you have received this email by mistake, please contact us at %{reply_to}
@@ -0,0 +1,18 @@
1
+ it:
2
+ contacts:
3
+ subject_empty: "Senza oggetto"
4
+ read: "Leggi"
5
+ latest_contact_requests: "Ultime richieste di contatto"
6
+ display_all: "Mostra tutte"
7
+ success: "Grazie per averci contattato, la ricontatteremo al più presto!"
8
+ contact_request_from: "Nuova richesta di contatto da %{from}"
9
+ send: "Invia"
10
+
11
+ confirmation:
12
+ subject: "Conferma richesta di contatto"
13
+ body: |
14
+ Gentile %{first_name} la ringraziamo per averci contattato presso il sito %{site_name}.
15
+
16
+ La ricontatteremo al più presto
17
+
18
+ Se non è stato lei ad aver effettuato la richesta, o se pensa di aver ricevuto questa mail per errore la preghiamo di contattarci all'indirizzo %{reply_to}
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ namespace :admin do
3
+ resources :contacts, :only => [:index, :show]
4
+ end
5
+ end
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "fullstack-contacts"
8
+ s.version = "0.1.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["mcasimir"]
12
+ s.date = "2013-02-02"
13
+ s.description = "Contact form and backend for fullstack-cms"
14
+ s.email = "maurizio.cas@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "Gemfile",
20
+ "Gemfile.lock",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "app/controllers/admin/contacts_controller.rb",
25
+ "app/helpers/contacts_helper.rb",
26
+ "app/mailers/.gitkeep",
27
+ "app/mailers/contacts_mailer.rb",
28
+ "app/views/admin/contacts/_contacts_dashboard_widget.html.erb",
29
+ "app/views/admin/contacts/_contacts_table.html.erb",
30
+ "app/views/admin/contacts/index.html.erb",
31
+ "app/views/admin/contacts/show.html.erb",
32
+ "config/locales/en.yml",
33
+ "config/locales/it.yml",
34
+ "config/routes.rb",
35
+ "fullstack-contacts.gemspec",
36
+ "lib/fullstack-contacts.rb",
37
+ "lib/fullstack/contacts.rb",
38
+ "lib/fullstack/contacts/actions.rb",
39
+ "lib/fullstack/contacts/engine.rb",
40
+ "lib/generators/fullstack/contacts/install_generator.rb",
41
+ "lib/generators/fullstack/contacts/templates/app/models/contact.rb",
42
+ "lib/generators/fullstack/contacts/templates/app/views/contacts_mailer/confirmation.html.erb",
43
+ "lib/generators/fullstack/contacts/templates/app/views/contacts_mailer/notify.html.erb",
44
+ "lib/generators/fullstack/contacts/templates/app/views/fullstack/contacts/_form.html.erb",
45
+ "lib/generators/fullstack/contacts/templates/app/views/fullstack/contacts/_success.html.erb"
46
+ ]
47
+ s.homepage = "http://github.com/mcasimir/kaminari-bootstrap"
48
+ s.licenses = ["MIT"]
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = "1.8.25"
51
+ s.summary = "Contact form and backend for fullstack-cms"
52
+
53
+ if s.respond_to? :specification_version then
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
+ s.add_runtime_dependency(%q<rails>, [">= 0"])
58
+ s.add_development_dependency(%q<bundler>, [">= 0"])
59
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
60
+ else
61
+ s.add_dependency(%q<rails>, [">= 0"])
62
+ s.add_dependency(%q<bundler>, [">= 0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<rails>, [">= 0"])
67
+ s.add_dependency(%q<bundler>, [">= 0"])
68
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
69
+ end
70
+ end
71
+
@@ -0,0 +1,24 @@
1
+ # Author:: Maurizio Casimirri (mailto:maurizio.cas@gmail.com)
2
+ # Copyright:: Copyright (c) 2012 Maurizio Casimirri
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+
24
+ require 'fullstack/contacts'
@@ -0,0 +1,8 @@
1
+ require 'fullstack/contacts/actions'
2
+ require 'fullstack/contacts/engine'
3
+
4
+ module Fullstack
5
+ module Contacts
6
+
7
+ end
8
+ end
@@ -0,0 +1,28 @@
1
+ module Fullstack
2
+ module Contacts
3
+ module Actions
4
+
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ end
9
+
10
+ protected
11
+
12
+ def create_contact!(options = {})
13
+
14
+ options = {
15
+ :failure => "contacts"
16
+ }.merge(options)
17
+
18
+ @contact = Contact.new(params[:contact])
19
+ if @contact.save
20
+ redirect_to options[:success], :flash => {:notice => t("contacts.success", :default => "Thank you for contacting us")}
21
+ else
22
+ render options[:new]
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails'
2
+
3
+ module Fullstack
4
+ module Contacts
5
+ class Engine < ::Rails::Engine
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,63 @@
1
+ module Fullstack
2
+ module Contacts
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ def install_templates
7
+ directory "app", Rails.root.join("app")
8
+ end
9
+
10
+ def banner
11
+ puts <<-eos
12
+
13
+ # =========================================================
14
+ # = Take the following steps to complete the installation =
15
+ # =========================================================
16
+
17
+ Edit 'app/models/contact.rb' to customize 'Contact' model and then run:
18
+ rails g migration:from contact && rake db:migrate
19
+
20
+ You may also wish to customize front-end views editing:
21
+ - app/views/contacts_mailer/confirmation.html.erb
22
+ - app/views/contacts_mailer/notify.html.erb
23
+ - app/views/fullstack/contacts/_form.html.erb
24
+ - app/views/fullstack/contacts/_success.html.erb
25
+
26
+ Enable contacts back-end in config/initializers/fullstack.rb:
27
+
28
+ admin.group :contacts do |g|
29
+ g.icon= "user"
30
+ g.resource :contacts
31
+ end
32
+
33
+ Install a widget in your admin/dashboard:
34
+
35
+ <%= contacts_dashboard_widget %>
36
+
37
+ Add actions to your controller:
38
+
39
+ include Fullstack::Contacts::Actions
40
+
41
+ page :contacts, "/contacts", :parent => :home do
42
+ @contact = Contact.new
43
+ end
44
+
45
+ action :contact, "/contact", :via => :post do
46
+ create_contact!(:success => polymorphic_path([:site, :contacts], :success => true))
47
+ end
48
+
49
+ Render a contact_form inside your views:
50
+
51
+ <% if params[:success] %>
52
+ <%= contact_success %>
53
+ <% else %>
54
+ <%= contact_form %>
55
+ <% end %>
56
+
57
+ eos
58
+
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,47 @@
1
+ class Contact < ActiveRecord::Base
2
+ include Localized
3
+ inheritable
4
+ timestamps
5
+
6
+ field :first_name
7
+ field :second_name
8
+ field :email
9
+ field :text, :text
10
+ field :read, :boolean, :default => false
11
+
12
+ scope :unread, where("read IS NOT true")
13
+
14
+ def name
15
+ [first_name, second_name].compact.join(" ")
16
+ end
17
+
18
+ def unread?
19
+ !read?
20
+ end
21
+
22
+ field :agreed_to_privacy, :boolean, :default => false
23
+ validates_acceptance_of :agreed_to_privacy, :on => :create, :accept => true, :allow_nil => false
24
+ validates_presence_of :locale, :email, :first_name
25
+
26
+ before_validation do |contact|
27
+ contact.locale = I18n.locale.to_s
28
+ end
29
+
30
+ after_create do |contact|
31
+ ContactsMailer.confirmation(contact).deliver
32
+ ContactsMailer.notify(contact).deliver
33
+ end
34
+
35
+ def read!
36
+ unless read?
37
+ update_attributes!(:read => true)
38
+ end
39
+ end
40
+
41
+ def unread!
42
+ unless unread?
43
+ update_attributes!(:read => false)
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1 @@
1
+ <%= simple_format t("contacts.confirmation.body", :first_name => @contact.first_name, :reply_to => Settings.app.email, :site_name => Settings.app.domain) %>
@@ -0,0 +1,8 @@
1
+ <ul>
2
+ <li><b><%= t("helpers.label.locale", :default => "Locale") %></b>: <%= @contact.locale %></li>
3
+ <li><b><%= t("helpers.label.first_name", :default => "First Name") %></b>: <%= @contact.first_name %></li>
4
+ <li><b><%= t("helpers.label.second_name", :default => "Second Name") %></b>: <%= @contact.second_name %></li>
5
+ <li><b><%= t("helpers.label.email", :default => "Email") %></b>: <%= @contact.email %></li>
6
+ <li><b><%= t("helpers.label.message", :default => "Message") %></b>: <br/>
7
+ <%= simple_format h(@contact.text) %></li>
8
+ </ul>
@@ -0,0 +1,13 @@
1
+ <%= site_form_for( @contact, :url => [:site, :contact] ) do |f| %>
2
+
3
+ <%= f.inputs do %>
4
+ <%= f.input :first_name %>
5
+ <%= f.input :email %>
6
+ <%= f.input :text %>
7
+ <%= f.input :agreed_to_privacy %>
8
+ <% end %>
9
+ <div>
10
+ <input name="commit" type="submit" value="<%= t('contacts.send', :default => 'Send') %>" class="contact-submit btn btn-primary">
11
+ </div>
12
+
13
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <div class="alert alert-success">
2
+ <%= t("contacts.success", :default => "Thank you for contacting us.") %>
3
+ </div>
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fullstack-contacts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - mcasimir
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: jeweler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.8.4
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.4
62
+ description: Contact form and backend for fullstack-cms
63
+ email: maurizio.cas@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files:
67
+ - README.md
68
+ files:
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - README.md
72
+ - Rakefile
73
+ - VERSION
74
+ - app/controllers/admin/contacts_controller.rb
75
+ - app/helpers/contacts_helper.rb
76
+ - app/mailers/.gitkeep
77
+ - app/mailers/contacts_mailer.rb
78
+ - app/views/admin/contacts/_contacts_dashboard_widget.html.erb
79
+ - app/views/admin/contacts/_contacts_table.html.erb
80
+ - app/views/admin/contacts/index.html.erb
81
+ - app/views/admin/contacts/show.html.erb
82
+ - config/locales/en.yml
83
+ - config/locales/it.yml
84
+ - config/routes.rb
85
+ - fullstack-contacts.gemspec
86
+ - lib/fullstack-contacts.rb
87
+ - lib/fullstack/contacts.rb
88
+ - lib/fullstack/contacts/actions.rb
89
+ - lib/fullstack/contacts/engine.rb
90
+ - lib/generators/fullstack/contacts/install_generator.rb
91
+ - lib/generators/fullstack/contacts/templates/app/models/contact.rb
92
+ - lib/generators/fullstack/contacts/templates/app/views/contacts_mailer/confirmation.html.erb
93
+ - lib/generators/fullstack/contacts/templates/app/views/contacts_mailer/notify.html.erb
94
+ - lib/generators/fullstack/contacts/templates/app/views/fullstack/contacts/_form.html.erb
95
+ - lib/generators/fullstack/contacts/templates/app/views/fullstack/contacts/_success.html.erb
96
+ homepage: http://github.com/mcasimir/kaminari-bootstrap
97
+ licenses:
98
+ - MIT
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ segments:
110
+ - 0
111
+ hash: -7703580069063085
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 1.8.25
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: Contact form and backend for fullstack-cms
124
+ test_files: []