bcms_contact_us_module 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.markdown ADDED
@@ -0,0 +1,33 @@
1
+ # Browser CMS Contact Us Module
2
+
3
+ Contact Us module for BrowserCMS gives you a portlet to put on a contact us page. It will save the submitted question and send an email to a pre-configured email address.
4
+
5
+ ## Getting Started
6
+
7
+ ### Installation
8
+ Have a look here to see how BrowserCMS modules installs in BrowserCMS (http://guides.browsercms.org/installing_modules.html)
9
+
10
+ gem install bcms_contact_us_module
11
+
12
+ ### Configuration changes
13
+
14
+ Edit config/environment.rb
15
+
16
+ config.gem "browsercms"
17
+ config.gem "bcms_contact_us_module"
18
+
19
+ Run this
20
+
21
+ script/generate browser_cms
22
+ rake db:migrate
23
+
24
+ Add this to config/routes.rb
25
+
26
+ map.routes_for_bcms_questions
27
+ map.routes_for_browser_cms
28
+
29
+ ## License
30
+ Contact Us is released under a LGPL license, and is copyright 1998-2009 Freddy Andersen, Zerolimits Technology. The complete copyright can be found in COPYRIGHT.txt, and copy of the license can be found in LICENSE.txt.
31
+
32
+ ## Support
33
+ If you have problems with this module add a new issue under the issues tab on github
@@ -0,0 +1,10 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
7
+
8
+ # Scrub sensitive parameters from your log
9
+ # filter_parameter_logging :password
10
+ end
@@ -0,0 +1,2 @@
1
+ class Cms::QuestionsController < Cms::ContentBlockController
2
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,12 @@
1
+ class Notifications < ActionMailer::Base
2
+
3
+
4
+ def new_question_notification(question, recipients, from_email="no_reply@bcms-site.com", subject="New question submitted")
5
+ subject subject
6
+ recipients recipients
7
+ from from_email
8
+
9
+ body "Question Subject: " + question.subject + "\n\n" + question.message
10
+ end
11
+
12
+ end
@@ -0,0 +1,23 @@
1
+ class Question < ActiveRecord::Base
2
+ acts_as_content_block
3
+
4
+ # Pattern used to find real emails
5
+ EMAIL_PATTERN = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
6
+
7
+ # i18n messages stored in config/locales/en.yml
8
+ validates_presence_of :email
9
+ validates_format_of :email, :with => EMAIL_PATTERN
10
+
11
+ # display_name is used in the admin secton of the cms to give our
12
+ # content block a readable name
13
+ def self.display_name
14
+ "Submitted Questions"
15
+ end
16
+
17
+ # When the question is saved make sure it is also published does not make
18
+ # sens to publish a question right?
19
+ def before_create
20
+ self.published = true
21
+ end
22
+
23
+ end
@@ -0,0 +1,35 @@
1
+ class ContactUsPortlet < Portlet
2
+
3
+ # Mark this as 'true' to allow the portlet's template to be editable via the CMS admin UI.
4
+ enable_template_editor false
5
+
6
+ def render
7
+ pmap = flash[instance_name] || params
8
+ @question = Question.new pmap[:question]
9
+ @question.errors.add_from_hash flash["#{instance_name}_errors"]
10
+ end
11
+
12
+ def action
13
+ question = Question.new(params[:question] || {})
14
+
15
+ if question.save
16
+
17
+ if self.notify_me
18
+ begin
19
+ Notifications.deliver_new_question_notification(question, self.notify_emails)
20
+ rescue => e
21
+ logger.error "[ERROR] in ContactUsPortlet => #{e}"
22
+ end
23
+ end
24
+
25
+ flash[:notice] = "We have received your message and will get intouch with you within 48 hours."
26
+ url_for_success
27
+ else
28
+ flash[:error] = "There was a problem with your question, please check the contact us form and resubmit."
29
+ store_params_in_flash
30
+ store_errors_in_flash(question.errors)
31
+ url_for_failure
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,5 @@
1
+ ##
2
+ # All methods from this helper will be available in the render.html.erb for ContactUsPortlet
3
+ module ContactUsPortletHelper
4
+
5
+ end
@@ -0,0 +1,6 @@
1
+ <%= f.cms_text_field :name %>
2
+ <%= f.cms_text_field :email %>
3
+ <%= f.cms_text_field :subject %>
4
+ <%= f.cms_text_area :message %>
5
+
6
+
@@ -0,0 +1,19 @@
1
+
2
+ <div class="nv_pair">
3
+ <div class="header">Name</div>
4
+ <div><%= @content_block.name %></div>
5
+ </div>
6
+ <div class="nv_pair">
7
+ <div class="header">E-mail</div>
8
+ <div><%= @content_block.email %></div>
9
+ </div>
10
+ <div class="nv_pair">
11
+ <div class="header">Subject</div>
12
+ <div><%= @content_block.subject %></div>
13
+ </div>
14
+
15
+ <div class="header">Question</div>
16
+ <div class="content">
17
+ <p><%= @content_block.message %></p>
18
+ </div>
19
+
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
5
+ <title><%= page_title %></title>
6
+ <%= yield :html_head %>
7
+ </head>
8
+ <body>
9
+ <%= cms_toolbar %>
10
+ <%= flash_messages %>
11
+ <%= render_breadcrumbs %>
12
+ <%= container :default %>
13
+ </body>
14
+ </html>
@@ -0,0 +1,13 @@
1
+ <%= f.cms_text_field :name %>
2
+ <%= f.cms_check_box :notify_me, :instructions => 'To enable email notification put a check mark here.' %>
3
+ <%= f.cms_text_field :notify_emails,
4
+ :instructions => 'Email addresses to notify after a successful submitted question; emails separated by a comma' %>
5
+ <%= f.cms_drop_down :success_url,
6
+ [["Default url",""]] + Page.all(:order => "name").map{|c| ["#{c.name} - [#{c.path}]", c.path]},
7
+ :label => "Success url",
8
+ :instructions => "Determines which page to forward to after a successful submitted question." %>
9
+ <%= f.cms_drop_down :failure_url,
10
+ [["Default url",""]] + Page.all(:order => "name").map{|c| ["#{c.name} - [#{c.path}]", c.path]},
11
+ :label => "Failure url",
12
+ :instructions => "Determines which page to forward to after a failed submitted question." %>
13
+ <%= f.cms_template_editor :template %>
@@ -0,0 +1,37 @@
1
+ <h1><%= @portlet.name %></h1>
2
+
3
+ <div class="contact_us_form">
4
+
5
+ <% form_for @question, :url => cms_handler_path(@portlet, "action") do |f| %>
6
+ <%= error_messages_for :question %>
7
+
8
+ <fieldset>
9
+
10
+ <p>
11
+ <%= f.label :name %>
12
+ <%= f.text_field :name %>
13
+ </p>
14
+
15
+ <p>
16
+ <%= f.label :email %>
17
+ <%= f.text_field :email %>
18
+ </p>
19
+
20
+ <p>
21
+ <%= f.label :subject %>
22
+ <%= f.text_field :subject %>
23
+ </p>
24
+
25
+ <p>
26
+ <%= f.text_area :message %>
27
+ </p>
28
+
29
+ <p>
30
+ <%= f.submit "Submit" %>
31
+ </p>
32
+
33
+ </fieldset>
34
+
35
+ <% end %>
36
+
37
+ </div>
@@ -0,0 +1,21 @@
1
+ class CreateQuestions < ActiveRecord::Migration
2
+ def self.up
3
+ create_content_table :questions do |t|
4
+ t.string :name
5
+ t.string :email
6
+ t.string :subject
7
+ t.text :message
8
+ end
9
+
10
+
11
+ ContentType.create!(:name => "Question", :group_name => "Administration")
12
+ end
13
+
14
+ def self.down
15
+ ContentType.delete_all(['name = ?', 'Question'])
16
+ CategoryType.all(:conditions => ['name = ?', 'Question']).each(&:destroy)
17
+ #If you aren't creating a versioned table, be sure to comment this out.
18
+ drop_table :question_versions
19
+ drop_table :questions
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ module Cms::Routes
2
+ def routes_for_bcms_contact_us_module
3
+ namespace(:cms) do |cms|
4
+ cms.content_blocks :questions
5
+ end
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ require 'bcms_contact_us_module/routes'
data/rails/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ gem_root = File.expand_path(File.join(File.dirname(__FILE__), ".."))
2
+ Cms.add_to_rails_paths gem_root
3
+ Cms.add_generator_paths gem_root, "db/migrate/[0-9]*_*.rb"
4
+ Cms.add_generator_paths gem_root, "public/bcms/contact_us_module/**/*"
5
+
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), '/../../test_helper')
2
+
3
+ class Cms::QuestionsControllerTest < ActionController::TestCase
4
+
5
+ test "Add_test_here" do
6
+
7
+ end
8
+
9
+
10
+
11
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionController::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
+ require 'test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Transactional fixtures accelerate your tests by wrapping each test method
7
+ # in a transaction that's rolled back on completion. This ensures that the
8
+ # test database remains unchanged so your fixtures don't have to be reloaded
9
+ # between every test method. Fewer database queries means faster tests.
10
+ #
11
+ # Read Mike Clark's excellent walkthrough at
12
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
13
+ #
14
+ # Every Active Record database supports transactions except MyISAM tables
15
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
16
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
17
+ # is recommended.
18
+ #
19
+ # The only drawback to using transactional fixtures is when you actually
20
+ # need to test transactions. Since your test is bracketed by a transaction,
21
+ # any transactions started in your code will be automatically rolled back.
22
+ self.use_transactional_fixtures = true
23
+
24
+ # Instantiated fixtures are slow, but give you @david where otherwise you
25
+ # would need people(:david). If you don't want to migrate your existing
26
+ # test cases which use the @david style and don't mind the speed hit (each
27
+ # instantiated fixtures translates to a database query per test method),
28
+ # then set this back to true.
29
+ self.use_instantiated_fixtures = false
30
+
31
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
32
+ #
33
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
34
+ # -- they do not yet inherit this setting
35
+ fixtures :all
36
+
37
+ # Add more helper methods to be used by all tests here...
38
+ end
@@ -0,0 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), '/../../test_helper')
2
+
3
+ class QuestionTest < ActiveSupport::TestCase
4
+
5
+ test "should be able to create new block" do
6
+ assert Question.create!
7
+ end
8
+
9
+ end
@@ -0,0 +1,12 @@
1
+ require 'test_helper'
2
+
3
+ class NotificationsTest < ActionMailer::TestCase
4
+ test "new_question" do
5
+ @expected.subject = 'Notifications#new_question'
6
+ @expected.body = read_fixture('new_question')
7
+ @expected.date = Time.now
8
+
9
+ assert_equal @expected.encoded, Notifications.create_new_question(@expected.date).encoded
10
+ end
11
+
12
+ end
@@ -0,0 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), '/../../test_helper')
2
+
3
+ class ContactUsTest < ActiveSupport::TestCase
4
+
5
+ test "Should be able to create new instance of a portlet" do
6
+ assert ContactUsPortlet.create!(:name => "New Portlet")
7
+ end
8
+
9
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class QuestionObserverTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bcms_contact_us_module
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 1
10
+ version: 1.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Freddy Andersen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-01 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: A BrowserCMS module that gives you a contact us portlet
23
+ email: freddy@zerolimitstech.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - LICENSE.txt
30
+ - README.markdown
31
+ files:
32
+ - app/controllers/application_controller.rb
33
+ - app/controllers/cms/questions_controller.rb
34
+ - app/helpers/application_helper.rb
35
+ - app/models/notifications.rb
36
+ - app/models/question.rb
37
+ - app/portlets/contact_us_portlet.rb
38
+ - app/portlets/helpers/contact_us_portlet_helper.rb
39
+ - app/views/cms/questions/_form.html.erb
40
+ - app/views/cms/questions/render.html.erb
41
+ - app/views/layouts/templates/default.html.erb
42
+ - app/views/portlets/contact_us/_form.html.erb
43
+ - app/views/portlets/contact_us/render.html.erb
44
+ - db/migrate/20101030141654_create_questions.rb
45
+ - lib/bcms_contact_us_module.rb
46
+ - lib/bcms_contact_us_module/routes.rb
47
+ - rails/init.rb
48
+ - LICENSE.txt
49
+ - README.markdown
50
+ - test/functional/cms/questions_controller_test.rb
51
+ - test/performance/browsing_test.rb
52
+ - test/test_helper.rb
53
+ - test/unit/models/question_test.rb
54
+ - test/unit/notifications_test.rb
55
+ - test/unit/portlets/contact_us_portlet_test.rb
56
+ - test/unit/question_observer_test.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/heimdull/bcms_contact_us_module
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.7
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Contact Us portlet in BrowserCMS
91
+ test_files:
92
+ - test/functional/cms/questions_controller_test.rb
93
+ - test/performance/browsing_test.rb
94
+ - test/test_helper.rb
95
+ - test/unit/models/question_test.rb
96
+ - test/unit/notifications_test.rb
97
+ - test/unit/portlets/contact_us_portlet_test.rb
98
+ - test/unit/question_observer_test.rb