tkh_content 0.1.8 → 0.1.9
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.
- data/CHANGELOG.md +11 -0
- data/README.md +1 -1
- data/app/controllers/contacts_controller.rb +54 -0
- data/app/mailers/contact_mailer.rb +18 -0
- data/app/models/contact.rb +16 -0
- data/app/views/contact_mailer/message_from_contact_form.text.erb +9 -0
- data/app/views/contacts/_form.html.erb +14 -0
- data/app/views/contacts/index.html.erb +29 -0
- data/app/views/pages/_form.html.erb +1 -1
- data/app/views/pages/index.html.erb +1 -1
- data/app/views/pages/show.html.erb +3 -0
- data/config/routes.rb +1 -0
- data/lib/generators/tkh_content/create_or_update_locales/templates/de.yml +13 -1
- data/lib/generators/tkh_content/create_or_update_locales/templates/en.yml +21 -0
- data/lib/generators/tkh_content/create_or_update_locales/templates/es.yml +11 -1
- data/lib/generators/tkh_content/create_or_update_locales/templates/fr.yml +17 -5
- data/lib/generators/tkh_content/create_or_update_migrations/create_or_update_migrations_generator.rb +1 -0
- data/lib/generators/tkh_content/create_or_update_migrations/templates/create_contacts.rb +19 -0
- data/lib/tkh_content/version.rb +1 -1
- metadata +11 -20
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
class ContactsController < ApplicationController
|
2
|
+
|
3
|
+
before_filter :authenticate, :except => 'create'
|
4
|
+
before_filter :authenticate_with_admin, :except => 'create'
|
5
|
+
|
6
|
+
def index
|
7
|
+
@contacts = Contact.by_recent.paginate(:page => params[:page], :per_page => 35)
|
8
|
+
switch_to_admin_layout
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
@contact = Contact.new(params[:contact])
|
13
|
+
saved = @contact.save
|
14
|
+
sent_email = send_message_to_admin(@contact)
|
15
|
+
|
16
|
+
if saved && sent_email == 'success'
|
17
|
+
redirect_to root_path, notice: "Your message has been sent. Thank you very much!"
|
18
|
+
elsif saved && sent_email == 'exception'
|
19
|
+
flash[:error] = 'There was a problem sending this message'
|
20
|
+
redirect_to :back
|
21
|
+
elsif saved && sent_email == 'invalid'
|
22
|
+
flash[:error] = 'There was a problem sending this message. Your email address does not seem to be valid!'
|
23
|
+
redirect_to :back
|
24
|
+
else
|
25
|
+
flash[:error] = 'Something went wrong. Your message did not reach the intended recipient.'
|
26
|
+
redirect_to :back
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid_email?(string)
|
31
|
+
(!string.blank? && string =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) ? true : false
|
32
|
+
end
|
33
|
+
# helper_method :valid_email?
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def send_message_to_admin(contact)
|
38
|
+
# check email validity
|
39
|
+
if valid_email?(contact.sender_email)
|
40
|
+
# Actually send the email to the student
|
41
|
+
begin
|
42
|
+
ContactMailer.message_from_contact_form(contact).deliver
|
43
|
+
return 'success'
|
44
|
+
rescue Exception => e
|
45
|
+
# AdminMailer.rescued_exceptions(e, "Some exception occurred while trying to send a student his confirmation for registering in a course. The email was never sent!").deliver
|
46
|
+
return 'exception'
|
47
|
+
end
|
48
|
+
else # for invalid or blank emails
|
49
|
+
return 'invalid'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class ContactMailer < ActionMailer::Base
|
2
|
+
|
3
|
+
# default :from => "info@yoga.lu"
|
4
|
+
|
5
|
+
# Subject can be set in your I18n file at config/locales/en.yml
|
6
|
+
# with the following lookup:
|
7
|
+
#
|
8
|
+
# en.user_mailer.password_reset.subject
|
9
|
+
#
|
10
|
+
def message_from_contact_form(contact)
|
11
|
+
@contact = contact
|
12
|
+
# FIXME - only the email addresses show up. not the names :-(
|
13
|
+
# TODO - what do to if contact_email is not set?
|
14
|
+
recipient = "#{Setting.first.company_name} <#{Setting.first.contact_email}>"
|
15
|
+
from = "#{@contact.sender_name} <#{@contact.sender_email}>"
|
16
|
+
mail to: recipient, from: from , subject: 'Message from the contact form'
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# this is needed for now to make mass assignment security compatible with the translation of globalize3
|
2
|
+
Globalize::ActiveRecord::Translation.class_eval do
|
3
|
+
attr_accessible :locale
|
4
|
+
end
|
5
|
+
|
6
|
+
class Contact < ActiveRecord::Base
|
7
|
+
|
8
|
+
attr_accessible :sender_name, :sender_email, :body
|
9
|
+
|
10
|
+
validates_presence_of :sender_name
|
11
|
+
validates :sender_email, :presence => true, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :on => :create }
|
12
|
+
validates_presence_of :body
|
13
|
+
|
14
|
+
scope :by_recent, order('updated_at desc')
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%= simple_form_for Contact.new, :html => { class: 'form-horizontal' } do |f| %>
|
2
|
+
<%= f.error_notification %>
|
3
|
+
|
4
|
+
<div class="form-inputs">
|
5
|
+
<%= f.input :sender_name %>
|
6
|
+
<%= f.input :sender_email %>
|
7
|
+
<%= f.input :body, :input_html => { :rows => 10 } %>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<div class="form-actions">
|
11
|
+
<%= f.button :submit, :class => 'btn btn-primary', label: 'send your message' %>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<% end %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<h1><%= t 'contacts.index.title' %></h1>
|
2
|
+
|
3
|
+
<table class='table table-striped'>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th><%= t 'activerecord.attributes.contacts.sender_name' %></th>
|
7
|
+
<th><%= t 'activerecord.attributes.contacts.sender_email' %></th>
|
8
|
+
<th><%= t 'activerecord.attributes.contacts.body' %></th>
|
9
|
+
<th><%= t 'contacts.sent' %></th>
|
10
|
+
<th>Actions</th>
|
11
|
+
</tr>
|
12
|
+
</thead>
|
13
|
+
|
14
|
+
<tbody>
|
15
|
+
<% @contacts.each do |contact| %>
|
16
|
+
<tr>
|
17
|
+
<td><%= contact.sender_name %></td>
|
18
|
+
<td><%= mail_to contact.sender_email, contact.sender_name, subject: 'Response to your message' %></td>
|
19
|
+
<td><%= truncate contact.body, length: 55, separator: ' ...' %></td>
|
20
|
+
<td><%= l contact.created_at, :format => :default %></td>
|
21
|
+
<td>Reply to email: <%= mail_to contact.sender_email, contact.sender_name, subject: 'Response to your message' %></td>
|
22
|
+
</tr>
|
23
|
+
<% end %>
|
24
|
+
</tbody>
|
25
|
+
</table>
|
26
|
+
|
27
|
+
<%= will_paginate @contacts %>
|
28
|
+
|
29
|
+
<%= render 'shared/admin_sidebar' %>
|
@@ -14,7 +14,7 @@
|
|
14
14
|
source: Page.not_for_blog.by_title.map(&:title).to_json }
|
15
15
|
} %>
|
16
16
|
<%= f.input :description, :input_html => { :rows => 3 } %>
|
17
|
-
<%= f.input :body, :input_html => { :rows =>
|
17
|
+
<%= f.input :body, :input_html => { :rows => 35 } %>
|
18
18
|
</div>
|
19
19
|
|
20
20
|
<div class="form-actions">
|
data/config/routes.rb
CHANGED
@@ -14,6 +14,11 @@ de:
|
|
14
14
|
description: "Beschreibung"
|
15
15
|
body: "Haupttext"
|
16
16
|
for_the_blog: 'Für den Blog'
|
17
|
+
|
18
|
+
contacts:
|
19
|
+
sender_name: "sender name"
|
20
|
+
sender_email: 'sender email'
|
21
|
+
body: 'message'
|
17
22
|
|
18
23
|
pages:
|
19
24
|
author: 'Autor'
|
@@ -28,4 +33,11 @@ de:
|
|
28
33
|
warning: 'Beim Speichern der Seite ist ein Problem aufgetreten'
|
29
34
|
destroy:
|
30
35
|
notice: 'Die Seite wurde gelöscht'
|
31
|
-
root_warning: "Du kannst diese Seite nicht löschen, da es die Root-Seite ist. Du kannst sie nur bearbeiten."
|
36
|
+
root_warning: "Du kannst diese Seite nicht löschen, da es die Root-Seite ist. Du kannst sie nur bearbeiten."
|
37
|
+
|
38
|
+
contacts:
|
39
|
+
sent: 'Sent at'
|
40
|
+
|
41
|
+
create:
|
42
|
+
notice: 'Your message has been sent'
|
43
|
+
warning: 'There was a problem sending your message.'
|
@@ -1,5 +1,19 @@
|
|
1
1
|
en:
|
2
2
|
|
3
|
+
activerecord:
|
4
|
+
attributes:
|
5
|
+
pages:
|
6
|
+
title: "title"
|
7
|
+
short_title: 'short title'
|
8
|
+
description: "description"
|
9
|
+
body: "body text"
|
10
|
+
for_the_blog: 'for the blog'
|
11
|
+
|
12
|
+
contacts:
|
13
|
+
sender_name: "sender name"
|
14
|
+
sender_email: 'sender email'
|
15
|
+
body: 'message'
|
16
|
+
|
3
17
|
are_you_sure: 'are you sure?'
|
4
18
|
delete: 'delete'
|
5
19
|
edit: 'edit'
|
@@ -20,3 +34,10 @@ en:
|
|
20
34
|
destroy:
|
21
35
|
notice: 'The page was deleted'
|
22
36
|
root_warning: "You cannot delete this page as this is the root page of the site. You should only modify it."
|
37
|
+
|
38
|
+
contacts:
|
39
|
+
sent: 'Sent at'
|
40
|
+
|
41
|
+
create:
|
42
|
+
notice: 'Your message has been sent'
|
43
|
+
warning: 'There was a problem sending your message.'
|
@@ -14,6 +14,11 @@ es:
|
|
14
14
|
description: "descripción"
|
15
15
|
body: "parte principal"
|
16
16
|
for_the_blog: 'contraseña'
|
17
|
+
|
18
|
+
contacts:
|
19
|
+
sender_name: "nombre del remitente"
|
20
|
+
sender_email: 'correo electrónico del remitente'
|
21
|
+
body: 'mensaje'
|
17
22
|
|
18
23
|
pages:
|
19
24
|
author: 'autor'
|
@@ -30,4 +35,9 @@ es:
|
|
30
35
|
notice: 'la página se ha eliminado'
|
31
36
|
root_warning: "No se puede eliminar la página, ya que es la bienvenida principal. Por favor, cámbialo."
|
32
37
|
|
33
|
-
|
38
|
+
contacts:
|
39
|
+
sent: 'Enviado a las'
|
40
|
+
|
41
|
+
create:
|
42
|
+
notice: 'Tu mensaje ha sido enviado.'
|
43
|
+
warning: 'Hubo un problema al enviar su mensaje.'
|
@@ -14,6 +14,11 @@ fr:
|
|
14
14
|
description: "description"
|
15
15
|
body: "texte principal"
|
16
16
|
for_the_blog: 'pour le blog'
|
17
|
+
|
18
|
+
contacts:
|
19
|
+
sender_name: "nom de l'auteur"
|
20
|
+
sender_email: "email de l'auteur"
|
21
|
+
body: 'contenu du message'
|
17
22
|
|
18
23
|
pages:
|
19
24
|
author: 'auteur'
|
@@ -22,10 +27,17 @@ fr:
|
|
22
27
|
|
23
28
|
create:
|
24
29
|
notice: 'La page a été créée.'
|
25
|
-
warning: "Il y'a eu un probleme et la page n'a pas été sauvegardée"
|
30
|
+
warning: "Il y'a eu un probleme et la page n'a pas été sauvegardée."
|
26
31
|
update:
|
27
|
-
notice: 'Les changements de cette page ont été sauvegardés'
|
28
|
-
warning: "Il y'a eu un probleme et les changements de cette page n'ont pas été sauvegardés"
|
32
|
+
notice: 'Les changements de cette page ont été sauvegardés.'
|
33
|
+
warning: "Il y'a eu un probleme et les changements de cette page n'ont pas été sauvegardés."
|
29
34
|
destroy:
|
30
|
-
notice: 'La page a été supprimée'
|
31
|
-
root_warning: "Vous ne pouvez pas supprimer cette page parce que c'est la page principale de bienvenue. Veuillez la modifier."
|
35
|
+
notice: 'La page a été supprimée.'
|
36
|
+
root_warning: "Vous ne pouvez pas supprimer cette page parce que c'est la page principale de bienvenue. Veuillez la modifier."
|
37
|
+
|
38
|
+
contacts:
|
39
|
+
sent: 'Envoyé le'
|
40
|
+
|
41
|
+
create:
|
42
|
+
notice: 'Votre message a bien été envoyé.'
|
43
|
+
warning: "Il y'a eu un probleme en envoyant votre message."
|
data/lib/generators/tkh_content/create_or_update_migrations/create_or_update_migrations_generator.rb
CHANGED
@@ -22,6 +22,7 @@ module TkhContent
|
|
22
22
|
migration_template "add_parent_id_to_pages.rb", "db/migrate/add_parent_id_to_pages.rb"
|
23
23
|
migration_template "create_tags.rb", "db/migrate/create_tags.rb"
|
24
24
|
migration_template "create_taggings.rb", "db/migrate/create_taggings.rb"
|
25
|
+
migration_template "create_contacts.rb", "db/migrate/create_contacts.rb"
|
25
26
|
end
|
26
27
|
|
27
28
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateContacts < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :contacts do |t|
|
5
|
+
t.string :sender_name
|
6
|
+
t.string :sender_email
|
7
|
+
t.text :body
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
add_index :contacts, :updated_at
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
drop_table :contacts
|
16
|
+
remove_index :pages, :updated_at
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/tkh_content/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tkh_content
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -123,22 +123,6 @@ dependencies:
|
|
123
123
|
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
|
-
- !ruby/object:Gem::Dependency
|
127
|
-
name: tkh_inline_editor
|
128
|
-
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
|
-
requirements:
|
131
|
-
- - ! '>='
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
version: '0'
|
134
|
-
type: :runtime
|
135
|
-
prerelease: false
|
136
|
-
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
|
-
requirements:
|
139
|
-
- - ! '>='
|
140
|
-
- !ruby/object:Gem::Version
|
141
|
-
version: '0'
|
142
126
|
- !ruby/object:Gem::Dependency
|
143
127
|
name: sqlite3
|
144
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,13 +147,19 @@ extensions: []
|
|
163
147
|
extra_rdoc_files: []
|
164
148
|
files:
|
165
149
|
- app/controllers/blog_controller.rb
|
150
|
+
- app/controllers/contacts_controller.rb
|
166
151
|
- app/controllers/pages_controller.rb
|
167
152
|
- app/helpers/blog_helper.rb
|
153
|
+
- app/mailers/contact_mailer.rb
|
154
|
+
- app/models/contact.rb
|
168
155
|
- app/models/page.rb
|
169
156
|
- app/models/tag.rb
|
170
157
|
- app/models/tagging.rb
|
171
158
|
- app/views/blog/index.html.erb
|
172
159
|
- app/views/blog/index.rss.builder
|
160
|
+
- app/views/contact_mailer/message_from_contact_form.text.erb
|
161
|
+
- app/views/contacts/_form.html.erb
|
162
|
+
- app/views/contacts/index.html.erb
|
173
163
|
- app/views/pages/_form.html.erb
|
174
164
|
- app/views/pages/edit.html.erb
|
175
165
|
- app/views/pages/index.html.erb
|
@@ -187,6 +177,7 @@ files:
|
|
187
177
|
- lib/generators/tkh_content/create_or_update_migrations/create_or_update_migrations_generator.rb
|
188
178
|
- lib/generators/tkh_content/create_or_update_migrations/templates/add_author_to_pages.rb
|
189
179
|
- lib/generators/tkh_content/create_or_update_migrations/templates/add_parent_id_to_pages.rb
|
180
|
+
- lib/generators/tkh_content/create_or_update_migrations/templates/create_contacts.rb
|
190
181
|
- lib/generators/tkh_content/create_or_update_migrations/templates/create_pages.rb
|
191
182
|
- lib/generators/tkh_content/create_or_update_migrations/templates/create_taggings.rb
|
192
183
|
- lib/generators/tkh_content/create_or_update_migrations/templates/create_tags.rb
|
@@ -241,7 +232,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
241
232
|
version: '0'
|
242
233
|
segments:
|
243
234
|
- 0
|
244
|
-
hash: -
|
235
|
+
hash: -3307999387978065360
|
245
236
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
246
237
|
none: false
|
247
238
|
requirements:
|
@@ -250,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
250
241
|
version: '0'
|
251
242
|
segments:
|
252
243
|
- 0
|
253
|
-
hash: -
|
244
|
+
hash: -3307999387978065360
|
254
245
|
requirements: []
|
255
246
|
rubyforge_project:
|
256
247
|
rubygems_version: 1.8.23
|