bcms_rankings 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/COPYRIGHT.txt +23 -0
  2. data/GPL.txt +674 -0
  3. data/Gemfile +5 -0
  4. data/README.markdown +32 -2
  5. data/app/assets/javascripts/application.js +15 -0
  6. data/app/assets/javascripts/bcms_rankings/application.js +15 -0
  7. data/app/assets/stylesheets/application.css +13 -0
  8. data/app/assets/stylesheets/bcms_rankings/application.css +13 -0
  9. data/app/controllers/bcms_rankings/application_controller.rb +4 -0
  10. data/app/controllers/bcms_rankings/page_rankings_controller.rb +4 -0
  11. data/app/controllers/page_rankings_controller.rb +1 -1
  12. data/app/helpers/bcms_rankings/application_helper.rb +4 -0
  13. data/app/models/bcms_rankings/page_ranking.rb +16 -0
  14. data/app/portlets/highest_ranked_pages_portlet.rb +5 -5
  15. data/app/portlets/rank_this_page_portlet.rb +11 -4
  16. data/app/views/bcms_rankings/page_rankings/_form.html.erb +2 -0
  17. data/app/views/{cms → bcms_rankings}/page_rankings/render.html.erb +0 -0
  18. data/app/views/portlets/highest_ranked_pages/render.html.erb +1 -1
  19. data/app/views/portlets/rank_this_page/render.html.erb +1 -1
  20. data/config/routes.rb +3 -0
  21. data/db/bcms_rankings.seeds.rb +1 -0
  22. data/db/migrate/20090430194533_create_page_rankings.rb +1 -10
  23. data/db/migrate/20120703191943_page_ranking_v2_0_0.rb +7 -0
  24. data/lib/bcms_rankings.rb +5 -1
  25. data/lib/bcms_rankings/engine.rb +11 -0
  26. data/lib/bcms_rankings/route_extensions.rb +9 -0
  27. data/lib/bcms_rankings/version.rb +3 -0
  28. data/lib/generators/bcms_rankings/install/USAGE +3 -0
  29. data/lib/generators/bcms_rankings/install/install_generator.rb +19 -0
  30. data/lib/tasks/bcms_rankings_tasks.rake +4 -0
  31. metadata +80 -51
  32. data/app/controllers/application_controller.rb +0 -10
  33. data/app/controllers/cms/page_rankings_controller.rb +0 -2
  34. data/app/helpers/application_helper.rb +0 -3
  35. data/app/models/page_ranking.rb +0 -14
  36. data/app/views/cms/page_rankings/_form.html.erb +0 -2
  37. data/lib/bcms_rankings/routes.rb +0 -12
  38. data/rails/init.rb +0 -3
  39. data/test/functional/page_rankings_controller_test.rb +0 -24
  40. data/test/performance/browsing_test.rb +0 -9
  41. data/test/test_helper.rb +0 -38
  42. data/test/unit/highest_ranked_pages_portlet_test.rb +0 -41
  43. data/test/unit/page_ranking_test.rb +0 -33
  44. data/test/unit/rank_this_page_portlet_test.rb +0 -53
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+ gem "jquery-rails"
5
+ gem 'sqlite3'
@@ -1,8 +1,38 @@
1
1
  # Rankings Module for BrowserCMS
2
+
2
3
  This is module for BrowserCMS, which allows users to rank pages. It includes the following features:
3
4
 
4
5
  * Rank This Page - Users can use a control on a page that allows users to rank a page from 1-5.
5
6
  * Highest Ranked Pages - Users can see a list of pages which have the highest rank.
6
7
 
7
- This module is primarily for demo purposes, and currently does not have any 'voter fraud' detection to prevent multiple
8
- votes. Ideally, this would need to be done client side, with a cookie, so as to keep pages cachable in the CMS.
8
+ This module is primarily for demo purposes, and currently does not have any 'voter fraud' detection to prevent multiple votes. Ideally, this would need to be done client side, with a cookie, so as to keep pages cachable in the CMS.
9
+
10
+ ## Installation
11
+
12
+
13
+ The Ranking module installs like most other BrowserCMS modules (http://guides.browsercms.org/installing_modules.html)
14
+
15
+ ### 1. Install the module
16
+
17
+ $ rails g cms:install bcms_rankings
18
+
19
+ ### 2. Run the following commands
20
+
21
+ $ rake db:migrate
22
+ $ rake db:seed
23
+
24
+ For projects with existing databases, you may need to comment out other lines in db/seeds.rb so only the module seed data runs.
25
+
26
+ ### 3. Create a Ranking portlet and embed into your templates
27
+
28
+ * Open your browser to localhost:3000/cms/portlets and login
29
+ * Click 'Add New Content', and select 'Rank This Page Portlet'
30
+ * Set the name to 'Rank This Page' and click save.
31
+ * Now go to Administration -> Page Templates -> Sub Page -> Edit
32
+ * Add the following line to your template, somewhere in the body (preferably after your main content area)
33
+
34
+ <%= render_portlet "Rank This Page" %>
35
+
36
+ This will render embed the portlet named "Rank This Page" into any page which uses the Sub Page template.
37
+
38
+ * Now add a new page using the "Sub Page" template and you should see the radio buttons to rank the page. Ranking a page will update the associated page rank.
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ module BcmsRankings
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module BcmsRankings
2
+ class PageRankingsController < Cms::ContentBlockController
3
+ end
4
+ end
@@ -1,7 +1,7 @@
1
1
  class PageRankingsController < ApplicationController
2
2
 
3
3
  def create
4
- @page_ranking = PageRanking.new(params[:page_ranking])
4
+ @page_ranking = BcmsRankings::PageRanking.new(params[:page_ranking])
5
5
  @page_ranking.ip = request.remote_ip
6
6
  @page_ranking.name = "Page '#{@page_ranking.page.name}' ranked as #{@page_ranking.rank}"
7
7
  if !@page_ranking.save
@@ -0,0 +1,4 @@
1
+ module BcmsRankings
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,16 @@
1
+ module BcmsRankings
2
+ class PageRanking < ActiveRecord::Base
3
+ acts_as_content_block
4
+
5
+ belongs_to :page, :class_name => 'Cms::Page'
6
+ validates_presence_of :page_id
7
+ attr_accessible :page
8
+
9
+ scope :for_page, lambda{|p| {:conditions => ["#{table_name}.page_id = ?", p.id]}}
10
+
11
+
12
+ def self.rank(page, rank)
13
+ PageRanking.create!(:page=>page, :rank=>rank)
14
+ end
15
+ end
16
+ end
@@ -1,11 +1,11 @@
1
- class HighestRankedPagesPortlet < Portlet
1
+ class HighestRankedPagesPortlet < Cms::Portlet
2
2
 
3
3
  def render
4
4
  @pages =
5
- Page.find(:all,
6
- :select => 'pages.*, COUNT(page_rankings.id) AS rankings_count, AVG(page_rankings.rank) as avg_rank',
7
- :joins => 'INNER JOIN page_rankings ON page_rankings.page_id = pages.id',
8
- :group => 'pages.id',
5
+ Cms::Page.find(:all,
6
+ :select => "#{Cms::Page.table_name}.*, COUNT(#{BcmsRankings::PageRanking.table_name}.id) AS rankings_count, AVG(#{BcmsRankings::PageRanking.table_name}.rank) as avg_rank",
7
+ :joins => "INNER JOIN #{BcmsRankings::PageRanking.table_name} ON #{BcmsRankings::PageRanking.table_name}.page_id = #{Cms::Page.table_name}.id",
8
+ :group => "#{Cms::Page.table_name}.id",
9
9
  :limit => @portlet.number_to_show,
10
10
  :order => "avg_rank desc")
11
11
  end
@@ -1,13 +1,13 @@
1
- class RankThisPagePortlet < Portlet
1
+ class RankThisPagePortlet < Cms::Portlet
2
2
 
3
3
  def render
4
4
  @page = @controller.instance_variable_get("@page")
5
5
  if @page
6
- @rankings = PageRanking.for_page(@page)
6
+ @rankings = ranking().for_page(@page)
7
7
  @average_rank = average_ranking(@rankings)
8
8
 
9
9
  # For the form to create a new ranking
10
- @page_ranking = PageRanking.new(:page => @page)
10
+ @page_ranking = ranking().new(:page => @page)
11
11
  end
12
12
  end
13
13
 
@@ -17,7 +17,14 @@ class RankThisPagePortlet < Portlet
17
17
  rankings.each do |r|
18
18
  total = total + r.rank
19
19
  end
20
- (total/rankings.size).round_with_precision(1)
20
+ (total/rankings.size).round(1)
21
21
 
22
22
  end
23
+
24
+ private
25
+
26
+ # Faux class like method for less typing
27
+ def ranking()
28
+ BcmsRankings::PageRanking
29
+ end
23
30
  end
@@ -0,0 +1,2 @@
1
+ <%= f.cms_text_field :rank, :instructions=>"Rank should be a number between 1 and 5." %>
2
+ <%= f.cms_drop_down :page_id, Cms::Page.all(:order => "path").map{|p| ["#{p.path} (#{p.name})", p.id]}%>
@@ -2,6 +2,6 @@
2
2
  <p>The list of pages below shows the highest ranked pages, in order of popularity.</p>
3
3
  <ol>
4
4
  <% @pages.each do |page| %>
5
- <li><%= link_to page.name, page.path %>: Average is <%= page.avg_rank.to_f.round_with_precision(1) %> with <%= page.rankings_count %> total votes.</li>
5
+ <li><%= link_to page.name, page.path %>: Average is <%= page.avg_rank.to_f.round(1) %> with <%= page.rankings_count %> total votes.</li>
6
6
  <% end %>
7
7
  </ol>
@@ -2,7 +2,7 @@
2
2
  Average rank is <%= @average_rank %> out of <%= @rankings.size %> total.
3
3
  <h3>Rank this Page</h3>
4
4
  <p>Please rank the quality of this page, with #1 being the worst, and #5 the best.</p>
5
- <% form_for @page_ranking do |f| %>
5
+ <%= form_for @page_ranking do |f| %>
6
6
  <%= f.hidden_field :page_id %>
7
7
  <% (1..5).each do |count| %>
8
8
  <%= count %><%= f.radio_button :rank, count %>
@@ -0,0 +1,3 @@
1
+ BcmsRankings::Engine.routes.draw do
2
+ content_blocks :page_rankings
3
+ end
@@ -0,0 +1 @@
1
+ Cms::ContentType.create!(:name => "BcmsRankings::PageRanking", :group_name => "Page Ranking")
@@ -1,19 +1,10 @@
1
1
  class CreatePageRankings < ActiveRecord::Migration
2
- def self.up
2
+ def change
3
3
  create_versioned_table :page_rankings do |t|
4
4
  t.belongs_to :page
5
5
  t.string :name
6
6
  t.integer :rank
7
7
  t.string :ip
8
8
  end
9
-
10
-
11
- ContentType.create!(:name => "PageRanking", :group_name => "Page Ranking")
12
- end
13
-
14
- def self.down
15
- ContentType.delete_all(['name = ?', 'PageRanking'])
16
- drop_table :page_ranking_versions
17
- drop_table :page_rankings
18
9
  end
19
10
  end
@@ -0,0 +1,7 @@
1
+ require 'cms/upgrades/v3_5_0'
2
+
3
+ class PageRankingV200 < ActiveRecord::Migration
4
+ def change
5
+ v3_5_0_apply_namespace_to_block("BcmsRankings", "PageRanking")
6
+ end
7
+ end
@@ -1 +1,5 @@
1
- require 'bcms_rankings/routes'
1
+ require "bcms_rankings/engine"
2
+ require "bcms_rankings/route_extensions"
3
+
4
+ module BcmsRankings
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'browsercms'
2
+ module BcmsRankings
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace BcmsRankings
5
+ include Cms::Module
6
+
7
+ initializer 'bcms_rankings.route_extensions', :after => 'action_dispatch.prepare_dispatcher' do |app|
8
+ ActionDispatch::Routing::Mapper.send :include, BcmsRankings::RouteExtensions
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module BcmsRankings::RouteExtensions
2
+ def mount_bcms_rankings
3
+ mount BcmsRankings::Engine => "/bcms_rankings"
4
+ post '/page_rankings' => 'page_rankings#create', :as=>'page_rankings'
5
+ end
6
+
7
+ alias :routes_for_bcms_rankings :mount_bcms_rankings
8
+
9
+ end
@@ -0,0 +1,3 @@
1
+ module BcmsRankings
2
+ VERSION = "2.0.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ Installs bcms_rankings into a project. Typically invoked indirectly via:
2
+
3
+ rails generate cms:install bcms_rankings
@@ -0,0 +1,19 @@
1
+ require 'cms/module_installation'
2
+
3
+ class BcmsRankings::InstallGenerator < Cms::ModuleInstallation
4
+ add_migrations_directory_to_source_root __FILE__
5
+
6
+ def copy_migrations
7
+ rake 'bcms_rankings:install:migrations'
8
+ end
9
+
10
+ def add_seed_data_to_project
11
+ copy_file "../bcms_rankings.seeds.rb", "db/bcms_rankings.seeds.rb"
12
+ append_to_file "db/seeds.rb", "load File.expand_path('../bcms_rankings.seeds.rb', __FILE__)\n"
13
+ end
14
+
15
+ def add_routes
16
+ route 'mount_bcms_rankings'
17
+ end
18
+
19
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :bcms_rankings do
3
+ # # Task goes here
4
+ # end
metadata CHANGED
@@ -1,77 +1,106 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: bcms_rankings
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - BrowserMedia
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2009-07-02 00:00:00 -04:00
13
- default_executable:
14
- dependencies: []
15
-
12
+ date: 2012-07-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: browsercms
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - <
20
+ - !ruby/object:Gem::Version
21
+ version: 3.6.0
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: 3.5.0
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: 3.6.0
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: 3.5.0
16
36
  description: A Page ranking Module for BrowserCMS
17
37
  email: github@browsermedia.com
18
38
  executables: []
19
-
20
39
  extensions: []
21
-
22
- extra_rdoc_files:
23
- - LICENSE.txt
40
+ extra_rdoc_files:
24
41
  - README.markdown
25
- files:
26
- - app/controllers/application_controller.rb
27
- - app/controllers/cms/page_rankings_controller.rb
42
+ files:
43
+ - app/assets/javascripts/application.js
44
+ - app/assets/javascripts/bcms_rankings/application.js
45
+ - app/assets/stylesheets/application.css
46
+ - app/assets/stylesheets/bcms_rankings/application.css
47
+ - app/controllers/bcms_rankings/application_controller.rb
48
+ - app/controllers/bcms_rankings/page_rankings_controller.rb
28
49
  - app/controllers/page_rankings_controller.rb
29
- - app/helpers/application_helper.rb
30
- - app/models/page_ranking.rb
50
+ - app/helpers/bcms_rankings/application_helper.rb
51
+ - app/models/bcms_rankings/page_ranking.rb
31
52
  - app/portlets/highest_ranked_pages_portlet.rb
32
53
  - app/portlets/rank_this_page_portlet.rb
33
- - app/views/cms/page_rankings/_form.html.erb
34
- - app/views/cms/page_rankings/render.html.erb
54
+ - app/views/bcms_rankings/page_rankings/_form.html.erb
55
+ - app/views/bcms_rankings/page_rankings/render.html.erb
35
56
  - app/views/portlets/highest_ranked_pages/_form.html.erb
36
57
  - app/views/portlets/highest_ranked_pages/render.html.erb
37
58
  - app/views/portlets/rank_this_page/_form.html.erb
38
59
  - app/views/portlets/rank_this_page/render.html.erb
60
+ - config/routes.rb
61
+ - db/bcms_rankings.seeds.rb
39
62
  - db/migrate/20090430194533_create_page_rankings.rb
63
+ - db/migrate/20120703191943_page_ranking_v2_0_0.rb
64
+ - lib/bcms_rankings/engine.rb
65
+ - lib/bcms_rankings/route_extensions.rb
66
+ - lib/bcms_rankings/version.rb
40
67
  - lib/bcms_rankings.rb
41
- - lib/bcms_rankings/routes.rb
42
- - rails/init.rb
43
- - LICENSE.txt
68
+ - lib/generators/bcms_rankings/install/install_generator.rb
69
+ - lib/generators/bcms_rankings/install/USAGE
70
+ - lib/tasks/bcms_rankings_tasks.rake
44
71
  - README.markdown
45
- has_rdoc: true
46
- homepage: http://browsercms.org
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - COPYRIGHT.txt
75
+ - GPL.txt
76
+ homepage: http://www.github.com/browsermedia/bcms_rankings
77
+ licenses: []
47
78
  post_install_message:
48
- rdoc_options:
49
- - --charset=UTF-8
50
- require_paths:
79
+ rdoc_options: []
80
+ require_paths:
51
81
  - lib
52
- required_ruby_version: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: "0"
57
- version:
58
- required_rubygems_version: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: "0"
63
- version:
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ segments:
89
+ - 0
90
+ hash: -1733280016254060861
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ segments:
98
+ - 0
99
+ hash: -1733280016254060861
64
100
  requirements: []
65
-
66
- rubyforge_project: browsercms
67
- rubygems_version: 1.3.1
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.24
68
103
  signing_key:
69
- specification_version: 2
104
+ specification_version: 3
70
105
  summary: A Page ranking Module for BrowserCMS
71
- test_files:
72
- - test/functional/page_rankings_controller_test.rb
73
- - test/performance/browsing_test.rb
74
- - test/test_helper.rb
75
- - test/unit/highest_ranked_pages_portlet_test.rb
76
- - test/unit/page_ranking_test.rb
77
- - test/unit/rank_this_page_portlet_test.rb
106
+ test_files: []