bcms_event 1.0.0

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 ADDED
@@ -0,0 +1,243 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb" templates
7
+ that are primarily responsible for inserting pre-built data in between HTML tags.
8
+ The model contains the "smart" domain objects (such as Account, Product, Person,
9
+ Post) that holds all the business logic and knows how to persist themselves to
10
+ a database. The controller handles the incoming requests (such as Save New Account,
11
+ Update Product, Show Post) by manipulating the model and directing data to the view.
12
+
13
+ In Rails, the model is handled by what's called an object-relational mapping
14
+ layer entitled Active Record. This layer allows you to present the data from
15
+ database rows as objects and embellish these data objects with business logic
16
+ methods. You can read more about Active Record in
17
+ link:files/vendor/rails/activerecord/README.html.
18
+
19
+ The controller and view are handled by the Action Pack, which handles both
20
+ layers by its two parts: Action View and Action Controller. These two layers
21
+ are bundled in a single package due to their heavy interdependence. This is
22
+ unlike the relationship between the Active Record and Action Pack that is much
23
+ more separate. Each of these packages can be used independently outside of
24
+ Rails. You can read more about Action Pack in
25
+ link:files/vendor/rails/actionpack/README.html.
26
+
27
+
28
+ == Getting Started
29
+
30
+ 1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
31
+ and your application name. Ex: rails myapp
32
+ 2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
33
+ 3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
34
+ 4. Follow the guidelines to start developing your application
35
+
36
+
37
+ == Web Servers
38
+
39
+ By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
40
+ with a variety of other web servers.
41
+
42
+ Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
43
+ suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
44
+ getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
45
+ More info at: http://mongrel.rubyforge.org
46
+
47
+ Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
48
+ Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
49
+ FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
50
+
51
+ == Apache .htaccess example for FCGI/CGI
52
+
53
+ # General Apache options
54
+ AddHandler fastcgi-script .fcgi
55
+ AddHandler cgi-script .cgi
56
+ Options +FollowSymLinks +ExecCGI
57
+
58
+ # If you don't want Rails to look in certain directories,
59
+ # use the following rewrite rules so that Apache won't rewrite certain requests
60
+ #
61
+ # Example:
62
+ # RewriteCond %{REQUEST_URI} ^/notrails.*
63
+ # RewriteRule .* - [L]
64
+
65
+ # Redirect all requests not available on the filesystem to Rails
66
+ # By default the cgi dispatcher is used which is very slow
67
+ #
68
+ # For better performance replace the dispatcher with the fastcgi one
69
+ #
70
+ # Example:
71
+ # RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
72
+ RewriteEngine On
73
+
74
+ # If your Rails application is accessed via an Alias directive,
75
+ # then you MUST also set the RewriteBase in this htaccess file.
76
+ #
77
+ # Example:
78
+ # Alias /myrailsapp /path/to/myrailsapp/public
79
+ # RewriteBase /myrailsapp
80
+
81
+ RewriteRule ^$ index.html [QSA]
82
+ RewriteRule ^([^.]+)$ $1.html [QSA]
83
+ RewriteCond %{REQUEST_FILENAME} !-f
84
+ RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
85
+
86
+ # In case Rails experiences terminal errors
87
+ # Instead of displaying this message you can supply a file here which will be rendered instead
88
+ #
89
+ # Example:
90
+ # ErrorDocument 500 /500.html
91
+
92
+ ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
93
+
94
+
95
+ == Debugging Rails
96
+
97
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
98
+ will help you debug it and get it back on the rails.
99
+
100
+ First area to check is the application log files. Have "tail -f" commands running
101
+ on the server.log and development.log. Rails will automatically display debugging
102
+ and runtime information to these files. Debugging info will also be shown in the
103
+ browser on requests from 127.0.0.1.
104
+
105
+ You can also log your own messages directly into the log file from your code using
106
+ the Ruby logger class from inside your controllers. Example:
107
+
108
+ class WeblogController < ActionController::Base
109
+ def destroy
110
+ @weblog = Weblog.find(params[:id])
111
+ @weblog.destroy
112
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
113
+ end
114
+ end
115
+
116
+ The result will be a message in your log file along the lines of:
117
+
118
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
119
+
120
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
121
+
122
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
123
+
124
+ * The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
125
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
126
+
127
+ These two online (and free) books will bring you up to speed on the Ruby language
128
+ and also on programming in general.
129
+
130
+
131
+ == Debugger
132
+
133
+ Debugger support is available through the debugger command when you start your Mongrel or
134
+ Webrick server with --debugger. This means that you can break out of execution at any point
135
+ in the code, investigate and change the model, AND then resume execution!
136
+ You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
137
+ Example:
138
+
139
+ class WeblogController < ActionController::Base
140
+ def index
141
+ @posts = Post.find(:all)
142
+ debugger
143
+ end
144
+ end
145
+
146
+ So the controller will accept the action, run the first line, then present you
147
+ with a IRB prompt in the server window. Here you can do things like:
148
+
149
+ >> @posts.inspect
150
+ => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
151
+ #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
152
+ >> @posts.first.title = "hello from a debugger"
153
+ => "hello from a debugger"
154
+
155
+ ...and even better is that you can examine how your runtime objects actually work:
156
+
157
+ >> f = @posts.first
158
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
159
+ >> f.
160
+ Display all 152 possibilities? (y or n)
161
+
162
+ Finally, when you're ready to resume execution, you enter "cont"
163
+
164
+
165
+ == Console
166
+
167
+ You can interact with the domain model by starting the console through <tt>script/console</tt>.
168
+ Here you'll have all parts of the application configured, just like it is when the
169
+ application is running. You can inspect domain models, change values, and save to the
170
+ database. Starting the script without arguments will launch it in the development environment.
171
+ Passing an argument will specify a different environment, like <tt>script/console production</tt>.
172
+
173
+ To reload your controllers and models after launching the console run <tt>reload!</tt>
174
+
175
+ == dbconsole
176
+
177
+ You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
178
+ You would be connected to the database with the credentials defined in database.yml.
179
+ Starting the script without arguments will connect you to the development database. Passing an
180
+ argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
181
+ Currently works for mysql, postgresql and sqlite.
182
+
183
+ == Description of Contents
184
+
185
+ app
186
+ Holds all the code that's specific to this particular application.
187
+
188
+ app/controllers
189
+ Holds controllers that should be named like weblogs_controller.rb for
190
+ automated URL mapping. All controllers should descend from ApplicationController
191
+ which itself descends from ActionController::Base.
192
+
193
+ app/models
194
+ Holds models that should be named like post.rb.
195
+ Most models will descend from ActiveRecord::Base.
196
+
197
+ app/views
198
+ Holds the template files for the view that should be named like
199
+ weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
200
+ syntax.
201
+
202
+ app/views/layouts
203
+ Holds the template files for layouts to be used with views. This models the common
204
+ header/footer method of wrapping views. In your views, define a layout using the
205
+ <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
206
+ call <% yield %> to render the view using this layout.
207
+
208
+ app/helpers
209
+ Holds view helpers that should be named like weblogs_helper.rb. These are generated
210
+ for you automatically when using script/generate for controllers. Helpers can be used to
211
+ wrap functionality for your views into methods.
212
+
213
+ config
214
+ Configuration files for the Rails environment, the routing map, the database, and other dependencies.
215
+
216
+ db
217
+ Contains the database schema in schema.rb. db/migrate contains all
218
+ the sequence of Migrations for your schema.
219
+
220
+ doc
221
+ This directory is where your application documentation will be stored when generated
222
+ using <tt>rake doc:app</tt>
223
+
224
+ lib
225
+ Application specific libraries. Basically, any kind of custom code that doesn't
226
+ belong under controllers, models, or helpers. This directory is in the load path.
227
+
228
+ public
229
+ The directory available for the web server. Contains subdirectories for images, stylesheets,
230
+ and javascripts. Also contains the dispatchers and the default HTML files. This should be
231
+ set as the DOCUMENT_ROOT of your web server.
232
+
233
+ script
234
+ Helper scripts for automation and generation.
235
+
236
+ test
237
+ Unit and functional tests along with fixtures. When using the script/generate scripts, template
238
+ test files will be generated for you and placed in this directory.
239
+
240
+ vendor
241
+ External libraries that the application depends on. Also includes the plugins subdirectory.
242
+ If the app has frozen rails, those gems also go here, under vendor/rails/.
243
+ This directory is in the load path.
@@ -0,0 +1,2 @@
1
+ class Cms::EventsController < Cms::ContentBlockController
2
+ end
@@ -0,0 +1,53 @@
1
+ class Event < ActiveRecord::Base
2
+ acts_as_content_block :taggable => true
3
+ belongs_to_category
4
+
5
+ before_validation :set_slug
6
+ validates_presence_of :name, :slug, :starts_on
7
+
8
+ named_scope :starts_on, lambda {|date|
9
+ d = if date.kind_of?(Hash)
10
+ Date.new(date[:year].to_i, date[:month].to_i, date[:day].to_i)
11
+ else
12
+ date
13
+ end
14
+
15
+ {:conditions => ["events.starts_on = ?", d]}
16
+ }
17
+
18
+ named_scope :with_slug, lambda{|slug| {:conditions => ["events.slug = ?",slug]}}
19
+
20
+ def self.default_order
21
+ "starts_on desc"
22
+ end
23
+
24
+ def self.columns_for_index
25
+ [ {:label => "Name", :method => :name, :order => "name" },
26
+ {:label => "Starts On", :method => :starts_on_label, :order => "starts_on" } ]
27
+ end
28
+
29
+ def starts_on_label
30
+ starts_on ? starts_on.to_s(:long) : nil
31
+ end
32
+
33
+ def set_slug
34
+ self.slug = name.to_slug
35
+ end
36
+
37
+ def route_params
38
+ {:year => year, :month => month, :day => day, :slug => slug}
39
+ end
40
+
41
+ def year
42
+ starts_on.strftime("%Y")
43
+ end
44
+
45
+ def month
46
+ starts_on.strftime("%m")
47
+ end
48
+
49
+ def day
50
+ starts_on.strftime("%d")
51
+ end
52
+
53
+ end
@@ -0,0 +1,10 @@
1
+ class EventPortlet < Portlet
2
+
3
+ def render
4
+ # @event should already be set by the page route
5
+ if !@event && params[:event_id]
6
+ @event = Event.published.find(params[:event_id])
7
+ end
8
+ end
9
+
10
+ end
@@ -0,0 +1,11 @@
1
+ class EventsPortlet < Portlet
2
+
3
+ def render
4
+ if self.category_id.blank?
5
+ @events = Event.published.all
6
+ else
7
+ @events = Event.published.all(:conditions => {:category_id => self.category_id})
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ <%= f.cms_text_field :name %>
2
+ <%= f.cms_date_picker :starts_on %>
3
+ <%= f.cms_date_picker :ends_on %>
4
+ <%= f.cms_text_field :location %>
5
+ <%= f.cms_text_field :contact_email %>
6
+ <%= f.cms_text_area :description %>
7
+ <%= f.cms_text_field :more_info_url %>
8
+ <%= f.cms_text_field :registration_url %>
9
+ <%= f.cms_drop_down :category_id, categories_for('Event').map{|c| [c.path, c.id]}, :include_blank => true %>
10
+ <%= f.cms_tag_list %>
11
+ <%= f.cms_text_editor :body %>
@@ -0,0 +1,10 @@
1
+ <p><b>Name:</b> <%= @content_block.name %></p>
2
+ <p><b>Starts On:</b> <%= @content_block.starts_on %></p>
3
+ <p><b>Ends On:</b> <%= @content_block.ends_on %></p>
4
+ <p><b>Location:</b> <%= @content_block.location %></p>
5
+ <p><b>Contact Email:</b> <%= @content_block.contact_email %></p>
6
+ <p><b>Description:</b> <%= simple_format h(@content_block.description) %></p>
7
+ <p><b>More Info Url:</b> <%= @content_block.more_info_url %></p>
8
+ <p><b>Registration Url:</b> <%= @content_block.registration_url %></p>
9
+ <p><b>Category:</b> <%= @content_block.category_name %></p>
10
+ <p><b>Body:</b> <%= @content_block.body %></p>
@@ -0,0 +1,2 @@
1
+ <%= f.cms_text_field :name %>
2
+ <%= f.cms_text_area :template, :default_value => @block.class.default_template %>
@@ -0,0 +1,10 @@
1
+ <p><b>Name:</b> <%= @event.name %></p>
2
+ <p><b>Starts On:</b> <%= @event.starts_on %></p>
3
+ <p><b>Ends On:</b> <%= @event.ends_on %></p>
4
+ <p><b>Location:</b> <%= @event.location %></p>
5
+ <p><b>Contact Email:</b> <%= @event.contact_email %></p>
6
+ <p><b>Description:</b> <%= simple_format h(@event.description) %></p>
7
+ <p><b>More Info Url:</b> <%= @event.more_info_url %></p>
8
+ <p><b>Registration Url:</b> <%= @event.registration_url %></p>
9
+ <p><b>Category:</b> <%= @event.category_name %></p>
10
+ <p><b>Body:</b> <%= @event.body %></p>
@@ -0,0 +1,3 @@
1
+ <%= f.cms_text_field :name %>
2
+ <%= f.cms_drop_down :category_id, categories_for('Event').map{|c| [c.path, c.id]}, :include_blank => true %>
3
+ <%= f.cms_text_area :template, :default_value => @block.class.default_template %>
@@ -0,0 +1,18 @@
1
+ <div>
2
+ <% @events.group_by{|e| e.starts_on.year}.sort_by(&:first).reverse.each do |year, events_grouped_by_year| %>
3
+ <!-- <%= year %> -->
4
+ <% events_grouped_by_year.group_by{|e| e.starts_on.month}.sort_by(&:first).reverse.each do |month, events_grouped_by_month| %>
5
+ <b class="month"><%= Date::MONTHNAMES[month] %></b>
6
+ <% for event in events_grouped_by_month.sort_by(&:starts_on).reverse %>
7
+ <div id="event_<%= event.id %>" class="event">
8
+ <span class="event_starts_on"><b><%= event.starts_on.to_s(:long) %></b></span>
9
+ <br/>
10
+ <%= link_to "<b>#{h(event.name)}</b>", event_path(event.route_params) %><br/>
11
+ <% unless event.description.blank? -%>
12
+ <p><%= simple_format h(event.description) %></p>
13
+ <% end %>
14
+ </div>
15
+ <% end %>
16
+ <% end %>
17
+ <% end %>
18
+ </div>
@@ -0,0 +1,60 @@
1
+ class CreateEvents < ActiveRecord::Migration
2
+ def self.up
3
+ create_versioned_table :events do |t|
4
+ t.string :name
5
+ t.string :slug
6
+ t.date :starts_on
7
+ t.date :ends_on
8
+ t.string :location
9
+ t.string :contact_email
10
+ t.text :description
11
+ t.string :more_info_url
12
+ t.string :registration_url
13
+ t.belongs_to :category
14
+ t.text :body, :size => (64.kilobytes + 1)
15
+ end
16
+ unless CategoryType.named('Event').exists?
17
+ CategoryType.create!(:name => "Event")
18
+ end
19
+
20
+ ContentType.create!(:name => "Event", :group_name => "Event")
21
+
22
+ event_page = Page.create!(
23
+ :name => "Event",
24
+ :path => "/event",
25
+ :section => Section.root.first,
26
+ :template_file_name => "default.html.erb")
27
+
28
+ EventPortlet.create!(
29
+ :name => "Event Details",
30
+ :template => EventPortlet.default_template,
31
+ :connect_to_page_id => event_page.id,
32
+ :connect_to_container => "main",
33
+ :publish_on_save => true)
34
+
35
+ EventsPortlet.create!(
36
+ :name => "Event List",
37
+ :template => EventsPortlet.default_template,
38
+ :connect_to_page_id => event_page.id,
39
+ :connect_to_container => "main",
40
+ :publish_on_save => true)
41
+
42
+ route = event_page.page_routes.build(
43
+ :name => "Event",
44
+ :pattern => "/events/:year/:month/:day/:slug",
45
+ :code => "@event = Event.published.starts_on(params).with_slug(params[:slug]).first")
46
+ route.add_condition(:method, "get")
47
+ route.add_requirement(:year, '\d{4,}')
48
+ route.add_requirement(:month, '\d{2,}')
49
+ route.add_requirement(:day, '\d{2,}')
50
+ route.save!
51
+
52
+ end
53
+
54
+ def self.down
55
+ ContentType.delete_all(['name = ?', 'Event'])
56
+ CategoryType.all(:conditions => ['name = ?', 'Event']).each(&:destroy)
57
+ drop_table :event_versions
58
+ drop_table :events
59
+ end
60
+ end
@@ -0,0 +1,7 @@
1
+ module Cms::Routes
2
+ def routes_for_bcms_event
3
+ namespace(:cms) do |cms|
4
+ cms.content_blocks :events
5
+ end
6
+ end
7
+ end
data/lib/bcms_event.rb ADDED
@@ -0,0 +1 @@
1
+ require 'bcms_event/routes'
data/rails/init.rb ADDED
@@ -0,0 +1,3 @@
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"
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class EventsPortletTest < ActionController::TestCase
4
+ tests Cms::ContentController
5
+
6
+ def setup
7
+ create_baseline_data!
8
+ create_sample_data!
9
+ @events_portlet = EventsPortlet.create!(:name => "Events Portlet",
10
+ :template => EventsPortlet.default_template,
11
+ :connect_to_page_id => @events_page.id,
12
+ :connect_to_container => "main",
13
+ :publish_on_save => true)
14
+ end
15
+
16
+ def test_show_post
17
+ get :show, :path => ["events"]
18
+ log @response.body
19
+ assert_response :success
20
+ assert_select "title", "Events"
21
+
22
+ assert_select ".event" do
23
+ assert_select ".event_starts_on", "January 19, 2009"
24
+ assert_select "a b", "Martin Luther King Day"
25
+ end
26
+
27
+ assert_select ".event a b", {:text => "Unpublished", :count => 0}
28
+
29
+ end
30
+
31
+ 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,73 @@
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
+ require File.dirname(__FILE__) + '/test_logging'
7
+ include TestLogging
8
+ include SampleData
9
+ # Transactional fixtures accelerate your tests by wrapping each test method
10
+ # in a transaction that's rolled back on completion. This ensures that the
11
+ # test database remains unchanged so your fixtures don't have to be reloaded
12
+ # between every test method. Fewer database queries means faster tests.
13
+ #
14
+ # Read Mike Clark's excellent walkthrough at
15
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
16
+ #
17
+ # Every Active Record database supports transactions except MyISAM tables
18
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
19
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
20
+ # is recommended.
21
+ #
22
+ # The only drawback to using transactional fixtures is when you actually
23
+ # need to test transactions. Since your test is bracketed by a transaction,
24
+ # any transactions started in your code will be automatically rolled back.
25
+ self.use_transactional_fixtures = true
26
+
27
+ # Instantiated fixtures are slow, but give you @david where otherwise you
28
+ # would need people(:david). If you don't want to migrate your existing
29
+ # test cases which use the @david style and don't mind the speed hit (each
30
+ # instantiated fixtures translates to a database query per test method),
31
+ # then set this back to true.
32
+ self.use_instantiated_fixtures = false
33
+
34
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
35
+ #
36
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
37
+ # -- they do not yet inherit this setting
38
+ fixtures :all
39
+
40
+ # Add more helper methods to be used by all tests here...
41
+ def create_baseline_data!
42
+ @section = Section.create!(:name => "My Site", :path => "/")
43
+ Group.create!(:name => "Guest", :code => "guest", :sections => [@section])
44
+ @page_template = PageTemplate.create!(:name => "test", :format => "html", :handler => "erb", :body => %q{<html>
45
+ <head>
46
+ <title>
47
+ <%= page_title %>
48
+ </title>
49
+ <%= yield :html_head %>
50
+ </head>
51
+ <body>
52
+ <%= cms_toolbar %>
53
+ <%= container :main %>
54
+ </body>
55
+ </html>})
56
+
57
+ @events_page = Page.create!(:name => "Events", :section => @section, :path => "/events", :template_file_name => "test.html.erb")
58
+ @event_page = Page.create!(:name => "Event", :section => @section, :path => "/event", :template_file_name => "test.html.erb")
59
+
60
+ @event_route = @event_page.page_routes.build(
61
+ :name => "Event",
62
+ :pattern => "/events/:year/:month/:day/:slug",
63
+ :code => "@event = Event.published.starts_on(params).with_slug(params[:slug]).first")
64
+ @event_route.add_condition(:method, "get")
65
+ @event_route.add_requirement(:year, '\d{4,}')
66
+ @event_route.add_requirement(:month, '\d{2,}')
67
+ @event_route.add_requirement(:day, '\d{2,}')
68
+ @event_route.save!
69
+
70
+ @events_page.publish!
71
+ @event_page.publish!
72
+ end
73
+ end
@@ -0,0 +1,64 @@
1
+ module TestLogging
2
+ def log(msg)
3
+ Rails.logger.info(msg)
4
+ end
5
+
6
+ def log_array(obj, *columns)
7
+ lengths = columns.map{|m| m.to_s.length }
8
+
9
+ obj.each do |r|
10
+ columns.each_with_index do |m, i|
11
+ v = r.send(m)
12
+ if v.to_s.length > lengths[i]
13
+ lengths[i] = v.to_s.length
14
+ end
15
+ end
16
+ end
17
+
18
+ str = " "
19
+ columns.each_with_index do |m, i|
20
+ str << "%#{lengths[i]}s" % m
21
+ str << " "
22
+ end
23
+ str << "\n "
24
+
25
+ columns.each_with_index do |m, i|
26
+ str << ("-"*lengths[i])
27
+ str << " "
28
+ end
29
+ str << "\n "
30
+
31
+ obj.each do |r|
32
+ columns.each_with_index do |m, i|
33
+ str << "%#{lengths[i]}s" % r.send(m)
34
+ str << " "
35
+ end
36
+ str << "\n "
37
+ end
38
+
39
+ log str
40
+ end
41
+
42
+ def log_table(cls, options={})
43
+ if options[:include_columns]
44
+ columns = options[:include_columns]
45
+ elsif options[:exclude_columns]
46
+ columns = cls.column_names - options[:exclude_columns].map(&:to_s)
47
+ else
48
+ columns = cls.column_names
49
+ end
50
+ log_array (cls.uses_soft_delete? ? cls.find_with_deleted(:all) : cls.all), *columns
51
+ end
52
+
53
+ def log_table_with(cls, *columns)
54
+ log_table(cls, :include_columns => columns)
55
+ end
56
+
57
+ def log_table_without(cls, *columns)
58
+ log_table(cls, :exclude_columns => columns)
59
+ end
60
+
61
+ def log_table_without_stamps(cls, *columns)
62
+ log_table(cls, :exclude_columns => %w[created_at updated_at created_by_id updated_by_id] + columns)
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bcms_event
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - BrowserMedia
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-02 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: The Event Module for BrowserCMS
17
+ email: github@browsermedia.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE.txt
24
+ - README
25
+ files:
26
+ - app/controllers/cms/events_controller.rb
27
+ - app/models/event.rb
28
+ - app/portlets/event_portlet.rb
29
+ - app/portlets/events_portlet.rb
30
+ - app/views/cms/events/_form.html.erb
31
+ - app/views/cms/events/render.html.erb
32
+ - app/views/portlets/event/_form.html.erb
33
+ - app/views/portlets/event/render.html.erb
34
+ - app/views/portlets/events/_form.html.erb
35
+ - app/views/portlets/events/render.html.erb
36
+ - db/migrate/20090504174621_create_events.rb
37
+ - lib/bcms_event.rb
38
+ - lib/bcms_event/routes.rb
39
+ - rails/init.rb
40
+ - LICENSE.txt
41
+ - README
42
+ has_rdoc: true
43
+ homepage: http://browsercms.org
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --charset=UTF-8
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project: browsercms
64
+ rubygems_version: 1.3.1
65
+ signing_key:
66
+ specification_version: 2
67
+ summary: The Event Module for BrowserCMS
68
+ test_files:
69
+ - test/functional/events_portlet_test.rb
70
+ - test/performance/browsing_test.rb
71
+ - test/test_helper.rb
72
+ - test/test_logging.rb