mhs-bcms_content_rotator 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,34 @@
1
+ # Content Rotator Module for BrowserCMS
2
+
3
+ This module allows editors to create a rotating jquery based slideshow. Each rotator can have up to five slides, which can feature an image, title and text that can auto rotate, or allow users to click on a specific slide to view it. It is commonly used on home pages to feature lots of content within a small area, with some visual interest due to the rotation.
4
+
5
+ ## Features
6
+
7
+ * _Rotator_ - Allows up to five slides in rotation. Staff can choose to enable autorotation, as well as how long between each slide.
8
+ * _Slides_ - Each slide represents a single frame within the rotation.
9
+ * _Preloading Slides_ - Editors can create as many slides as they like, and choose which slides should appear in the rotation and in what order.
10
+
11
+ ### Slide Content Type
12
+
13
+ Each slide can consists of the following attributes:
14
+
15
+ * Title (String)
16
+ * Alt Text (String)
17
+ * Image URL (URL)
18
+ * Description (Html)
19
+ * Link Url (URL) - Determines where the user goes when they click the slide.
20
+
21
+
22
+ ## Installation
23
+
24
+ Follow the standard bcms module installation found here: http://guides.browsercms.org/installing_modules.html
25
+
26
+ Since this module relies on jquery, manually the javascript_include_tag to your page templates for any page that the slide show will appear on, like so:
27
+
28
+ <head>
29
+ ...
30
+ <%= javascript_include_tag 'jquery' %>
31
+ <%= yield :html_head %>
32
+ </head>
33
+
34
+ Once this is complete, you can add a new "Content Rotator Portlet" to any page. Create several slides, and edit the content rotator to choose the order.
@@ -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::SlidesController < 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,7 @@
1
+ class Slide < ActiveRecord::Base
2
+ acts_as_content_block
3
+
4
+ def has_link?
5
+ !link_url.blank?
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ class ContentRotatorPortlet < 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 true
5
+
6
+ def render
7
+
8
+ # Collect the list of slide_ids
9
+ @slide_ids = []
10
+ (1..5).each do |i|
11
+ s_id = self.send("slide_#{i}_id")
12
+ @slide_ids << s_id.to_i if (s_id && !s_id.empty?)
13
+ end
14
+
15
+ unsorted_slides = Slide.find(@slide_ids)
16
+
17
+ # Sort slides into explicit order based on slide_ids
18
+ @slides = []
19
+ @slide_ids.each do |id|
20
+ @slides << unsorted_slides.select{|item| item.id == id}.first
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ ##
2
+ # All methods from this helper will be available in the render.html.erb for ContentRotatorPortlet
3
+ module ContentRotatorPortletHelper
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ <%= f.cms_text_field :name %>
2
+ <%= f.cms_text_field :image_url, :label=>"Image URL" %>
3
+ <%= f.cms_text_field :alt_text %>
4
+ <%= f.cms_text_field :link_url, :label=>"Link URL", :instructions=>"Set a URL (http://...) here to make the slide clickable, leave blank otherwise." %>
5
+ <%= f.cms_text_editor :description %>
@@ -0,0 +1,5 @@
1
+ <p><b>Name:</b> <%= h @content_block.name %></p>
2
+ <p><b>Image Url:</b> <%= h @content_block.image_url %></p>
3
+ <p><b>Alt Text:</b> <%= h @content_block.alt_text %></p>
4
+ <p><b>Description:</b> <%= @content_block.description %></p>
5
+ <p><b>Link Url:</b> <%= @content_block.link_url %>
@@ -0,0 +1,18 @@
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
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
6
+ <title><%= page_title %></title>
7
+ <%= yield :html_head %>
8
+ </head>
9
+ <body style="margin: 0; padding: 0; text-align: center;">
10
+ <%= cms_toolbar %>
11
+ <div id="wrapper" style="width: 700px; margin: 0 auto; text-align: left; padding: 30px">
12
+ Breadcrumbs: <%= render_breadcrumbs %>
13
+ Main Menu: <%= render_menu %>
14
+ <h1><%= page_title %></h1>
15
+ <%= container :main %>
16
+ </div>
17
+ </body>
18
+ </html>
@@ -0,0 +1,10 @@
1
+ <% @slides = Slide.all %>
2
+ <%= f.cms_text_field :name %>
3
+ <%= f.cms_drop_down :slide_1_id, @slides.map{|c| [c.name, c.id.to_s]}, :label=>"Slide 1", :include_blank=>"[No slide selected]" %>
4
+ <%= f.cms_drop_down :slide_2_id, @slides.map{|c| [c.name, c.id.to_s]}, :label=>"Slide 2", :include_blank=>"[No slide selected]" %>
5
+ <%= f.cms_drop_down :slide_3_id, @slides.map{|c| [c.name, c.id.to_s]}, :label=>"Slide 3", :include_blank=>"[No slide selected]" %>
6
+ <%= f.cms_drop_down :slide_4_id, @slides.map{|c| [c.name, c.id.to_s]}, :label=>"Slide 4", :include_blank=>"[No slide selected]" %>
7
+ <%= f.cms_drop_down :slide_5_id, @slides.map{|c| [c.name, c.id.to_s]}, :label=>"Slide 5", :include_blank=>"[No slide selected]" %>
8
+ <%= f.cms_check_box :autorotate, :label => "Automatically rotate" %>
9
+ <%= f.cms_text_field :rotate_interval, :label => "Rotation delay", :instructions => "in seconds (has no effect if autorotate is off)" %>
10
+ <%= f.cms_template_editor :template %>
@@ -0,0 +1,64 @@
1
+ <script type="text/javascript">
2
+ //<![CDATA[
3
+ $(function() {
4
+ var slides = $('#slides div.slide'),
5
+ currentItem = 0,
6
+ rotateInterval = <%= @portlet.rotate_interval.to_i %> * 1000,
7
+ autorotate = <%= @portlet.autorotate %>,
8
+
9
+
10
+ runSlideShow = function() {
11
+ var item = $('#slides ul#controls li a:eq('+currentItem+')');
12
+ if (item.length) {
13
+ item.trigger('click', ['timer']);
14
+ currentItem++;
15
+ } else {
16
+ currentItem = 0;
17
+ }
18
+ },
19
+
20
+ selectSlide = function(e) {
21
+ if ($(this).parent().hasClass('on')) {
22
+ return false;
23
+ } else {
24
+ $('#slides ul#controls li').removeClass('on');
25
+ $(this).parent().addClass('on');
26
+ slides.hide();
27
+ slides.filter(this.hash).show();
28
+ return false;
29
+ }
30
+ };
31
+
32
+ slides.hide();
33
+ slides.filter(':first').show();
34
+ $('#slides #controls li').filter(':first').addClass('on');
35
+ $('#slides ul#controls li a').bind('click', {}, selectSlide).
36
+ each(function(i) { this.slideIndex=i; });
37
+
38
+ if (autorotate) {
39
+ setInterval(runSlideShow, (rotateInterval < 1000 ? 1000 : rotateInterval));
40
+ }
41
+ });
42
+ //]]>
43
+ </script>
44
+
45
+ <div id="slides">
46
+ <ul id="controls">
47
+ <% @slides.each_with_index do |slide, i| %>
48
+ <li><a href="#slide-<%= i %>"><%= h slide.name %></a></li>
49
+ <% end %>
50
+ </ul>
51
+ <% @slides.each_with_index do |slide, i| %>
52
+ <div id="slide-<%= i %>" class="slide">
53
+ <div class="info">
54
+ <div class="pad">
55
+ <h3><%= h slide.name %></h3>
56
+ <%= slide.description %>
57
+ </div>
58
+ </div>
59
+ <% unless slide.image_url.blank? %>
60
+ <%= link_to_if(slide.has_link?, image_tag(slide.image_url, :alt => h(slide.alt_text)), slide.link_url) %>
61
+ <% end %>
62
+ </div>
63
+ <% end %>
64
+ </div>
@@ -0,0 +1,21 @@
1
+ class CreateSlides < ActiveRecord::Migration
2
+ def self.up
3
+ create_content_table :slides do |t|
4
+ t.string :name
5
+ t.string :image_url
6
+ t.string :alt_text
7
+ t.text :description
8
+ end
9
+
10
+
11
+ ContentType.create!(:name => "Slide", :group_name => "Content Rotator")
12
+ end
13
+
14
+ def self.down
15
+ ContentType.delete_all(['name = ?', 'Slide'])
16
+ CategoryType.all(:conditions => ['name = ?', 'Slide']).each(&:destroy)
17
+ #If you aren't creating a versioned table, be sure to comment this out.
18
+ drop_table :slide_versions
19
+ drop_table :slides
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ class AddLinkUrlToSlide < ActiveRecord::Migration
2
+ def self.up
3
+ add_content_column :slides, :link_url, :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column :slides, :link_url
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ require 'bcms_content_rotator/routes'
@@ -0,0 +1,7 @@
1
+ module Cms::Routes
2
+ def routes_for_bcms_content_rotator
3
+ namespace(:cms) do
4
+ content_blocks :slides
5
+ end
6
+ end
7
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'browsercms'
2
+ gem_root = File.expand_path(File.join(File.dirname(__FILE__), ".."))
3
+ Cms.add_to_rails_paths gem_root
4
+ Cms.add_generator_paths gem_root, "db/migrate/[0-9]*_*.rb"
5
+ Cms.add_generator_paths gem_root, "public/bcms/content_rotator/**/*"
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mhs-bcms_content_rotator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - BrowserMedia
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-12 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: A BrowserCMS module for creating a Slideshow/Homepage rotator designed
15
+ to showcase site content using jQuery.
16
+ email: github@browsermedia.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README.markdown
21
+ files:
22
+ - app/controllers/application_controller.rb
23
+ - app/controllers/cms/slides_controller.rb
24
+ - app/helpers/application_helper.rb
25
+ - app/models/slide.rb
26
+ - app/portlets/content_rotator_portlet.rb
27
+ - app/portlets/helpers/content_rotator_portlet_helper.rb
28
+ - app/views/cms/slides/_form.html.erb
29
+ - app/views/cms/slides/render.html.erb
30
+ - app/views/layouts/templates/default.html.erb
31
+ - app/views/portlets/content_rotator/_form.html.erb
32
+ - app/views/portlets/content_rotator/render.html.erb
33
+ - db/migrate/20101111030324_create_slides.rb
34
+ - db/migrate/20110407193952_add_link_url_to_slide.rb
35
+ - lib/bcms_content_rotator.rb
36
+ - lib/bcms_content_rotator/routes.rb
37
+ - rails/init.rb
38
+ - README.markdown
39
+ homepage: https://github.com/browsermedia/bcms_content_rotator
40
+ licenses: []
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project: mhs-bcms_content_rotator
59
+ rubygems_version: 1.8.8
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: A BrowserCMS for creating a Slideshow/Homepage rotator designed to showcase
63
+ site content using jQuery.
64
+ test_files: []