refinerycms-contacts 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/Gemfile +73 -0
  2. data/Guardfile +27 -0
  3. data/LICENSE.md +8 -0
  4. data/Rakefile +20 -0
  5. data/app/assets/javascripts/refinery/contacts/admin/contacts.js +17 -0
  6. data/app/assets/javascripts/refinery/contacts/admin/jquery.chosen.min.js +10 -0
  7. data/app/assets/javascripts/refinery/contacts/contacts.js +23 -0
  8. data/app/assets/stylesheets/refinery/contacts/admin/chosen.css.scss +396 -0
  9. data/app/assets/stylesheets/refinery/contacts/contacts.css.scss +79 -0
  10. data/app/controllers/refinery/contacts/admin/contacts_controller.rb +14 -0
  11. data/app/controllers/refinery/contacts/mail_messages_controller.rb +26 -0
  12. data/app/helpers/refinery/contacts/admin/contacts_helper.rb +18 -0
  13. data/app/mailers/refinery/contacts/contact_mailer.rb +15 -0
  14. data/app/models/refinery/contact_page.rb +11 -0
  15. data/app/models/refinery/contacts/contact.rb +18 -0
  16. data/app/models/refinery/contacts/mail.rb +13 -0
  17. data/app/models/refinery/contacts/mail_message.rb +15 -0
  18. data/app/models/refinery/contacts/table_less_model.rb +23 -0
  19. data/app/sweepers/refinery/contacts/admin/contact_sweeper.rb +22 -0
  20. data/app/views/refinery/admin/pages/tabs/contacts/_contacts.html.erb +12 -0
  21. data/app/views/refinery/admin/pages/tabs/contacts/_contacts_bar.html.erb +4 -0
  22. data/app/views/refinery/admin/pages/tabs/contacts/_form.html.erb +24 -0
  23. data/app/views/refinery/contacts/admin/contacts/_actions.html.erb +25 -0
  24. data/app/views/refinery/contacts/admin/contacts/_contact.html.erb +17 -0
  25. data/app/views/refinery/contacts/admin/contacts/_contacts.html.erb +2 -0
  26. data/app/views/refinery/contacts/admin/contacts/_form.html.erb +93 -0
  27. data/app/views/refinery/contacts/admin/contacts/_mail_fields.html.erb +7 -0
  28. data/app/views/refinery/contacts/admin/contacts/_records.html.erb +18 -0
  29. data/app/views/refinery/contacts/admin/contacts/_sortable_list.html.erb +5 -0
  30. data/app/views/refinery/contacts/admin/contacts/edit.html.erb +1 -0
  31. data/app/views/refinery/contacts/admin/contacts/index.html.erb +7 -0
  32. data/app/views/refinery/contacts/admin/contacts/new.html.erb +1 -0
  33. data/app/views/refinery/contacts/contact_mailer/contact_form.html.erb +1 -0
  34. data/app/views/refinery/contacts/contact_mailer/contact_form.text.erb +1 -0
  35. data/app/views/refinery/contacts/contacts/_error_info.html.erb +15 -0
  36. data/app/views/refinery/contacts/contacts/_form.html.erb +47 -0
  37. data/app/views/refinery/contacts/contacts/_show.html.erb +50 -0
  38. data/app/views/refinery/contacts/contacts/_success_info.html.erb +8 -0
  39. data/changelog.md +2 -0
  40. data/config/initializers/recaptcha.rb +5 -0
  41. data/config/initializers/refinery/core.rb +4 -0
  42. data/config/locales/en.yml +80 -0
  43. data/config/locales/sk.yml +80 -0
  44. data/config/routes.rb +23 -0
  45. data/db/migrate/1_create_contacts_contacts.rb +36 -0
  46. data/db/migrate/2_create_contacts_mails.rb +17 -0
  47. data/db/migrate/3_create_contact_pages.rb +20 -0
  48. data/db/migrate/4_add_homepage_to_contacts.rb +11 -0
  49. data/db/seeds.rb +13 -0
  50. data/lib/generators/refinery/contacts_generator.rb +28 -0
  51. data/lib/generators/refinery/templates/config/initializers/recaptcha.rb.erb +7 -0
  52. data/lib/generators/refinery/templates/config/initializers/refinery/contacts.rb.erb +4 -0
  53. data/lib/refinery/contacts.rb +23 -0
  54. data/lib/refinery/contacts/configuration.rb +10 -0
  55. data/lib/refinery/contacts/engine.rb +44 -0
  56. data/lib/refinery/contacts/extensions/pages_extension.rb +40 -0
  57. data/lib/refinery/contacts/version.rb +17 -0
  58. data/lib/refinerycms-contacts.rb +1 -0
  59. data/lib/tasks/refinery/contacts.rake +13 -0
  60. data/readme.md +170 -0
  61. data/refinerycms-contacts.gemspec +27 -0
  62. data/script/rails +10 -0
  63. data/spec/models/refinery/contacts/contact_spec.rb +18 -0
  64. data/spec/models/refinery/contacts/mail_spec.rb +18 -0
  65. data/spec/requests/refinery/contacts/admin/contacts_spec.rb +101 -0
  66. data/spec/requests/refinery/contacts/admin/mails_spec.rb +101 -0
  67. data/spec/spec_helper.rb +55 -0
  68. data/spec/support/factories/refinery/contacts.rb +7 -0
  69. data/spec/support/factories/refinery/mails.rb +7 -0
  70. data/tasks/rspec.rake +6 -0
  71. data/tasks/testing.rake +8 -0
  72. metadata +147 -0
@@ -0,0 +1,20 @@
1
+ class CreateContactPages < ActiveRecord::Migration
2
+
3
+ def up
4
+ create_table :refinery_contact_pages do |t|
5
+ t.integer :contact_id
6
+ t.integer :page_id
7
+ t.string :page_type, :default => "Refinery::Page"
8
+ t.boolean :contact_info, :default=> false
9
+ end
10
+
11
+ add_index :refinery_contact_pages, :contact_id
12
+ add_index :refinery_contact_pages, :page_id
13
+
14
+ end
15
+
16
+ def down
17
+ drop_table :refinery_contact_pages
18
+ end
19
+
20
+ end
@@ -0,0 +1,11 @@
1
+ class AddHomepageToContacts < ActiveRecord::Migration
2
+
3
+ def up
4
+ add_column :refinery_contacts, :homepage, :string
5
+ end
6
+
7
+ def down
8
+ remove_column :refinery_contacts, :homepage, :string
9
+ end
10
+
11
+ end
data/db/seeds.rb ADDED
@@ -0,0 +1,13 @@
1
+ (Refinery.i18n_enabled? ? Refinery::I18n.frontend_locales : [:en]).each do |lang|
2
+ I18n.locale = lang
3
+
4
+ if defined?(Refinery::User)
5
+ Refinery::User.all.each do |user|
6
+ if user.plugins.where(:name => 'refinerycms-contacts').blank?
7
+ user.plugins.create(:name => 'refinerycms-contacts',
8
+ :position => (user.plugins.maximum(:position) || -1) +1)
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,28 @@
1
+ module Refinery
2
+ class ContactsGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def generate_recaptcha_template
6
+ template 'config/initializers/recaptcha.rb.erb', File.join(destination_root, 'config', 'initializers', 'recaptcha.rb')
7
+ end
8
+
9
+ def generate_contacts_template
10
+ template 'config/initializers/refinery/contacts.rb.erb', File.join(destination_root, 'config', 'initializers', 'refinery', 'contacts.rb')
11
+ end
12
+
13
+ def rake_db
14
+ rake("refinery_contacts:install:migrations")
15
+ end
16
+
17
+ def append_load_seed_data
18
+ create_file 'db/seeds.rb' unless File.exists?(File.join(destination_root, 'db', 'seeds.rb'))
19
+ append_file 'db/seeds.rb', :verbose => true do
20
+ <<-EOH
21
+
22
+ # Added by Refinery CMS Contacts extension
23
+ Refinery::Contacts::Engine.load_seed
24
+ EOH
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ # Register your key at http://www.google.com/recaptcha/whyrecaptcha
2
+
3
+ Recaptcha.configure do |config|
4
+ config.public_key = ''
5
+ config.private_key = ''
6
+ config.proxy = ''
7
+ end
@@ -0,0 +1,4 @@
1
+ Refinery::Contacts.configure do |config|
2
+ # Set to true, if you want to use gem client_side_validations. After that you need to correctly setup gem client_side_validations as it is written in Readme of this gem
3
+ # config.client_side_validations = <%= Refinery::Contacts.client_side_validations.inspect %>
4
+ end
@@ -0,0 +1,23 @@
1
+ require 'refinerycms-core'
2
+
3
+ module Refinery
4
+ autoload :ContactsGenerator, 'generators/refinery/contacts_generator'
5
+
6
+ module Contacts
7
+ class << self
8
+ attr_writer :root
9
+
10
+ def root
11
+ @root ||= Pathname.new(File.expand_path('../../../', __FILE__))
12
+ end
13
+
14
+ def factory_paths
15
+ @factory_paths ||= [ root.join('spec', 'factories').to_s ]
16
+ end
17
+ end
18
+
19
+ require 'refinery/contacts/engine'
20
+ require 'refinery/contacts/configuration'
21
+ require 'refinery/contacts/extensions/pages_extension'
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ module Refinery
2
+ module Contacts
3
+ include ActiveSupport::Configurable
4
+
5
+ config_accessor :client_side_validations
6
+
7
+
8
+ self.client_side_validations = false
9
+ end
10
+ end
@@ -0,0 +1,44 @@
1
+ module Refinery
2
+ module Contacts
3
+ class Engine < Rails::Engine
4
+ include Refinery::Engine
5
+ isolate_namespace Refinery::Contacts
6
+
7
+ engine_name :refinery_contacts
8
+
9
+ def self.register(tab)
10
+ tab.name = tab.name = ::I18n.t(:'refinery.plugins.contacts.tab_name')
11
+ tab.partial = "/refinery/admin/pages/tabs/contacts/contacts"
12
+ end
13
+
14
+ initializer "register refinerycms_contacts plugin" do
15
+ Refinery::Plugin.register do |plugin|
16
+ plugin.name = "contacts"
17
+ plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.contacts_admin_contacts_path }
18
+ plugin.pathname = root
19
+ plugin.activity = {
20
+ :class_name => :'refinery/contacts/contact'
21
+ }
22
+
23
+ end
24
+ end
25
+
26
+ config.to_prepare do
27
+ require 'refinerycms-pages'
28
+ Refinery::Page.send :has_one_contact
29
+ end
30
+
31
+ config.before_initialize do
32
+ require 'recaptcha/rails'
33
+ end
34
+
35
+ config.after_initialize do
36
+ Refinery::Pages::Tab.register do |tab|
37
+ register tab
38
+ end
39
+ Refinery.register_extension(Refinery::Contacts)
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,40 @@
1
+ module Refinery
2
+ module Contacts
3
+ module Extensions
4
+ module Pages
5
+ def has_one_contact
6
+ has_one :contact_page, :as => :page, :dependent=> :destroy
7
+ has_one :contact, :through => :contact_page
8
+ has_many :mails, :class_name => Refinery::Contacts::Mail, :through => :contact
9
+
10
+
11
+ accepts_nested_attributes_for :contact_page
12
+
13
+ module_eval do
14
+ def contact_page=(contact_page_params)
15
+ # new
16
+ if self.contact_page.nil?
17
+ self.build_contact_page
18
+ end
19
+
20
+ # destroy
21
+ if contact_page_params[:contact_id].blank?
22
+ self.contact_page.destroy
23
+
24
+ # create or update if changed
25
+ elsif (self.contact_page.contact_id.to_s != contact_page_params[:contact_id]) || (self.contact_page.contact_info != contact_page_params[:contact_info] )
26
+ self.contact_page.update_attributes( contact_page_params)
27
+ self.contact_page.save
28
+ end
29
+
30
+ end
31
+ end
32
+
33
+ attr_accessible :contact_page
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ ActiveRecord::Base.send(:extend, Refinery::Contacts::Extensions::Pages)
@@ -0,0 +1,17 @@
1
+ module Refinery
2
+ module Contacts
3
+ class Version
4
+ @major = 0
5
+ @minor = 1
6
+ @tiny = '0'
7
+
8
+ class << self
9
+ attr_reader :major, :minor, :tiny
10
+
11
+ def to_s
12
+ [@major, @minor, @tiny].compact.join('.')
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ require 'refinery/contacts'
@@ -0,0 +1,13 @@
1
+ namespace :refinery do
2
+
3
+ namespace :contacts do
4
+
5
+ # call this task by running: rake refinery:contacts:my_task
6
+ # desc "Description of my task below"
7
+ # task :my_task => :environment do
8
+ # # add your logic here
9
+ # end
10
+
11
+ end
12
+
13
+ end
data/readme.md ADDED
@@ -0,0 +1,170 @@
1
+ # Refinery CMS Contacts
2
+
3
+ __Contacts engine for Refinery CMS.__
4
+
5
+ Attach contact form to any page with contact information
6
+
7
+ ## Requirements
8
+
9
+ This version supports Rails 3.2.x and Refinery CMS ~> 2.0.9. (Should work with ~> 2.0.0, not tested)
10
+
11
+ ## Features
12
+
13
+ * create contact, contact has many email address
14
+ * contact can be attached to many pages
15
+ * rendering contact form with contact info ( optional )
16
+ * send email
17
+ * server side validation, client side validation ( optional )
18
+ * recaptcha
19
+
20
+
21
+ ## Screenshots
22
+
23
+ All screenshots are in [branch screenshots](https://github.com/Matho/refinerycms-contacts/tree/screenshots)
24
+
25
+ ![Edit contact](https://raw.github.com/Matho/refinerycms-contacts/screenshots/0.1.x/01_edit_contact.png)
26
+ ![Attach contact to page](https://raw.github.com/Matho/refinerycms-contacts/screenshots/0.1.x/03_attach_contact_to_page.png)
27
+ ![Frontend show](https://raw.github.com/Matho/refinerycms-contacts/screenshots/0.1.x/06_frontend_client_side_validation.png)
28
+
29
+ ## Language
30
+
31
+ Gem is translated to slovak and english.
32
+
33
+
34
+ ## Installation
35
+ ### Gem + migrations
36
+
37
+ Open up your ``Gemfile`` and add at the bottom this line:
38
+
39
+ ```ruby
40
+ gem 'refinerycms-contacts', '~> 0.1.0'
41
+ ```
42
+
43
+ Now, run
44
+
45
+ ```ruby
46
+ bundle install
47
+ ```
48
+
49
+ Next, to install run:
50
+
51
+ ```ruby
52
+ rails g refinery:contacts
53
+ ```
54
+
55
+ Run database migrations:
56
+
57
+ ```ruby
58
+ rake db:migrate
59
+ ```
60
+
61
+ Seed your database:
62
+
63
+ ```ruby
64
+ rake db:seed
65
+ ```
66
+
67
+ ### Assets + views
68
+
69
+ If you don't have Chosen JS included in your backend yet, append this code to your_app/config/initializers/refinery/core.rb
70
+
71
+ ```ruby
72
+ config.register_javascript "refinery/contacts/admin/jquery.chosen.min.js"
73
+ config.register_stylesheet "refinery/contacts/admin/chosen.css"
74
+ ```
75
+
76
+ To ``view/refinery/pages/show.html.erb`` add ``<%= render "/refinery/contacts/contacts/show" %>``
77
+
78
+ To your app stylesheet manifest add ``*= require refinery/contacts/contacts``
79
+ To your app javascript manifest add ``//= require refinery/contacts/contacts``
80
+
81
+ ### reCaptcha
82
+
83
+ Register your reCaptcha code at http://www.google.com/recaptcha/whyrecaptcha and set-up it in ``config/initializers/recaptcha.rb``
84
+ If you want, add that initializer file to .gitignore or rewrite it to use ENV variables from gitignored YAML file
85
+
86
+ ### Send mail testing
87
+
88
+ If you want to test mail sending in development I recommend to use gem letter_opener.
89
+ In ``app/config/environments/development.rb`` add these lines:
90
+
91
+ ```ruby
92
+ config.action_mailer.delivery_method = :letter_opener
93
+ config.action_mailer.raise_delivery_errors = true
94
+ ```
95
+ If you have set-up ActionMailer::Base.smtp_settings block for development mode, comment it.
96
+
97
+ ### Configure mailers
98
+
99
+ You can override mailer views from folder ``views/refinery/contacts/contact_mailer`` and edit.
100
+
101
+ ### Client side validations
102
+
103
+ Client side validations gem is not installed by default by refinerycms-contacts gem! You need to install it:
104
+
105
+ Include ClientSideValidations in your Gemfile
106
+ ```ruby
107
+ gem 'client_side_validations', '~> 3.2.1'
108
+ ```
109
+
110
+ Then run the install generator
111
+ ```ruby
112
+ rails g client_side_validations:install
113
+ ```
114
+
115
+ This will install the initializer:
116
+ ```
117
+ config/initializers/client_side_validations.rb
118
+ ```
119
+ **ATTENTION!!!**
120
+
121
+ Because of [some issues](https://github.com/refinery/refinerycms/issues/961#issuecomment-4594545) we must
122
+ delete that initializer and write this code into file ``config/application.rb`` :
123
+ ```ruby
124
+ config.to_prepare do
125
+ ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
126
+ unless html_tag =~ /^<label/
127
+ %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
128
+ else
129
+ %{<div class="field_with_errors">#{html_tag}</div>}.html_safe
130
+ end
131
+ end
132
+ end
133
+ ```
134
+
135
+ Add JS to your manifest:
136
+ ```ruby
137
+ //= require rails.validations
138
+ ```
139
+ In file ``config/initializers/refinery/contacts.rb `` set client_side_validations to true to don't show server-side validation error in errorExplanations div
140
+ ```ruby
141
+ config.client_side_validations = true
142
+ ```
143
+ ### Precompile assets
144
+
145
+ Before production, don't forget to precompile assets by:
146
+
147
+ ```ruby
148
+ rake assets:precompile
149
+ ```
150
+
151
+ ## Todo list
152
+
153
+ * add js pop-up in page's tab to allow create contact "in-place" instead of clicking through menu
154
+ * tests :(
155
+
156
+ ## Code
157
+
158
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/Matho/refinerycms-contacts)
159
+
160
+ ## Known bugs
161
+
162
+ * WymEditor tab name don't show title in correct current_locale
163
+ * reCaptcha validation shows errors both for incorrect-captcha-sol and verification_failed key
164
+
165
+ ## Testing
166
+ TODO
167
+
168
+ ## License
169
+
170
+ Refinery CMS Contacts engine is released under the MIT license. Created by Martin Markech
@@ -0,0 +1,27 @@
1
+ # Encoding: UTF-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'refinery/contacts/version'
4
+
5
+ version = Refinery::Contacts::Version.to_s
6
+
7
+ Gem::Specification.new do |s|
8
+ s.platform = Gem::Platform::RUBY
9
+ s.name = 'refinerycms-contacts'
10
+ s.version = version
11
+ s.description = 'Ruby on Rails Contacts extension for Refinery CMS'
12
+ s.summary = 'Attach contact form to any page in Refinery CMS'
13
+ s.email = %q{martin.markech@matho.sk}
14
+ s.homepage = %q{http://github.com/Matho/refinerycms-contacts}
15
+ s.authors = 'Martin Markech'
16
+ s.require_paths = %w(lib)
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ #s.test_files = `git ls-files -- spec/*`.split("\n")
20
+
21
+ # Runtime dependencies
22
+ s.add_dependency 'refinerycms-core', '~> 2.0.9' # should work ~> 2.0.0 , not tested
23
+ s.add_dependency 'recaptcha'
24
+
25
+ # Development dependencies (usually used for testing)
26
+ # s.add_development_dependency 'refinerycms-testing', '~> 2.0.9'
27
+ end