Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 4 commits
  • 131 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 29, 2012
@peakpg peakpg Initial upgrade to 3.5.x
* All tests pass
* Can add blogs/posts through admin UI
* Comments can be added through portlets.
d3e2d3b
Commits on May 30, 2012
@peakpg peakpg * Can display comments
* Can link from from blog posts.
f49374e
@peakpg peakpg Feeds work dc928d4
@peakpg peakpg Ensure installation works correctly.
* Update instructions
ae358a8
Showing with 2,565 additions and 10,933 deletions.
  1. +7 −14 .gitignore
  2. +1 −1  .rvmrc
  3. +5 −3 Gemfile
  4. +132 −0 Gemfile.lock
  5. +10 −4 README.markdown
  6. +36 −6 Rakefile
  7. 0  {vendor/plugins → app/assets/images/bcms_blog}/.gitkeep
  8. +15 −0 app/assets/javascripts/bcms_blog/application.js
  9. +13 −0 app/assets/stylesheets/bcms_blog/application.css
  10. +5 −0 app/controllers/bcms_blog/blog_comments_controller.rb
  11. +37 −0 app/controllers/bcms_blog/blog_posts_controller.rb
  12. +13 −0 app/controllers/bcms_blog/blogs_controller.rb
  13. +10 −0 app/controllers/bcms_blog/feeds_controller.rb
  14. +0 −3  app/controllers/cms/blog_comments_controller.rb
  15. +0 −35 app/controllers/cms/blog_posts_controller.rb
  16. +0 −11 app/controllers/cms/blogs_controller.rb
  17. +0 −8 app/controllers/feeds_controller.rb
  18. +27 −0 app/helpers/bcms_blog/blog_helper.rb
  19. +0 −20 app/helpers/cms/blog_helper.rb
  20. +99 −0 app/models/bcms_blog/blog.rb
  21. +36 −0 app/models/bcms_blog/blog_comment.rb
  22. +6 −0 app/models/bcms_blog/blog_group_membership.rb
  23. +141 −0 app/models/bcms_blog/blog_observer.rb
  24. +108 −0 app/models/bcms_blog/blog_post.rb
  25. +0 −95 app/models/blog.rb
  26. +0 −34 app/models/blog_comment.rb
  27. +0 −4 app/models/blog_group_membership.rb
  28. +0 −140 app/models/blog_observer.rb
  29. +0 −113 app/models/blog_post.rb
  30. +6 −6 app/portlets/blog_post_portlet.rb
  31. +4 −4 app/portlets/blog_posts_portlet.rb
  32. +5 −0 app/views/bcms_blog/blog_comments/_form.html.erb
  33. +2 −0  app/views/bcms_blog/blog_comments/render.html.erb
  34. +1 −1  app/views/{cms → bcms_blog}/blog_posts/_form.html.erb
  35. 0  app/views/{cms → bcms_blog}/blog_posts/no_access.html.erb
  36. 0  app/views/{cms → bcms_blog}/blog_posts/render.html.erb
  37. +2 −2 app/views/{cms → bcms_blog}/blogs/_form.html.erb
  38. 0  app/views/{cms → bcms_blog}/blogs/admin_only.html.erb
  39. 0  app/views/{cms → bcms_blog}/blogs/render.html.erb
  40. +3 −3 app/views/{ → bcms_blog}/feeds/index.rss.builder
  41. +0 −5 app/views/cms/blog_comments/_form.html.erb
  42. +0 −2  app/views/cms/blog_comments/render.html.erb
  43. +1 −1  app/views/portlets/blog_post/_form.html.erb
  44. +3 −1 app/views/portlets/blog_post/render.html.erb
  45. +1 −1  app/views/portlets/blog_posts/_form.html.erb
  46. +15 −10 bcms_blog.gemspec
  47. +0 −6 config/boot.rb
  48. +0 −26 config/database.mysql.yml
  49. +4 −61 config/routes.rb
  50. +4 −0 db/bcms_blog.seeds.rb
  51. +5 −6 db/migrate/20090415000000_create_blogs.rb
  52. +1 −5 db/migrate/20090415000001_create_blog_posts.rb
  53. +0 −2  db/migrate/20090415000002_create_blog_comments.rb
  54. +0 −9 db/migrate/20091109175123_browsercms_3_0_5.rb
  55. +12 −0 db/migrate/20120529184028_v130.rb
  56. +4 −4 doc/migrate_to_20100427.rb
  57. +5 −2 lib/bcms_blog.rb
  58. +15 −1 lib/bcms_blog/engine.rb
  59. +8 −0 lib/bcms_blog/route_extensions.rb
  60. +0 −10 lib/bcms_blog/routes.rb
  61. +3 −0  lib/bcms_blog/version.rb
  62. +11 −11 lib/generators/bcms_blog/install/install_generator.rb
  63. +4 −0 lib/tasks/bcms_blog_tasks.rake
  64. +0 −2  public/javascripts/application.js
  65. +0 −965 public/javascripts/controls.js
  66. +0 −974 public/javascripts/dragdrop.js
  67. +0 −1,123 public/javascripts/effects.js
  68. +0 −591 public/javascripts/jquery-ui.js
  69. +0 −6,001 public/javascripts/prototype.js
  70. +0 −191 public/javascripts/rails.js
  71. +0 −5 public/robots.txt
  72. +0 −1  public/site/customconfig.js
  73. +5 −3 script/rails
  74. +7 −0 test/bcms_blog_test.rb
  75. +0 −54 test/blog_test_helper.rb
  76. +261 −0 test/dummy/README.rdoc
  77. +7 −0 test/dummy/Rakefile
  78. +15 −0 test/dummy/app/assets/javascripts/application.js
  79. +13 −0 test/dummy/app/assets/stylesheets/application.css
  80. 0  { → test/dummy}/app/controllers/application_controller.rb
  81. 0  { → test/dummy}/app/helpers/application_helper.rb
  82. 0  public/favicon.ico → test/dummy/app/mailers/.gitkeep
  83. 0  test/dummy/app/models/.gitkeep
  84. +14 −0 test/dummy/app/views/layouts/application.html.erb
  85. +2 −0  { → test/dummy}/app/views/layouts/templates/default.html.erb
  86. +1 −1  { → test/dummy}/config.ru
  87. +21 −11 { → test/dummy}/config/application.rb
  88. +10 −0 test/dummy/config/boot.rb
  89. 0  { → test/dummy}/config/database.yml
  90. +1 −1  { → test/dummy}/config/environment.rb
  91. +16 −5 { → test/dummy}/config/environments/development.rb
  92. +32 −14 { → test/dummy}/config/environments/production.rb
  93. +11 −9 { → test/dummy}/config/environments/test.rb
  94. 0  { → test/dummy}/config/initializers/backtrace_silencers.rb
  95. +5 −0 { → test/dummy}/config/initializers/inflections.rb
  96. 0  { → test/dummy}/config/initializers/mime_types.rb
  97. +1 −1  { → test/dummy}/config/initializers/secret_token.rb
  98. +2 −2 { → test/dummy}/config/initializers/session_store.rb
  99. +14 −0 test/dummy/config/initializers/wrap_parameters.rb
  100. +1 −1  { → test/dummy}/config/locales/en.yml
  101. +5 −0 test/dummy/config/routes.rb
  102. +21 −14 db/seeds.rb → test/dummy/db/browsercms.seeds.rb
  103. +69 −76 db/migrate/20080815014337_browsercms_3_0_0.rb → test/dummy/db/migrate/20120529162207_browsercms300.cms.rb
  104. +10 −0 test/dummy/db/migrate/20120529162208_browsercms305.cms.rb
  105. +96 −0 test/dummy/db/migrate/20120529162209_browsercms315.cms.rb
  106. +57 −0 test/dummy/db/migrate/20120529162210_browsercms330.cms.rb
  107. +63 −0 test/dummy/db/migrate/20120529162211_browsercms340.cms.rb
  108. +33 −0 test/dummy/db/migrate/20120529162212_browsercms350.cms.rb
  109. +627 −0 test/dummy/db/schema.rb
  110. +3 −0  test/dummy/db/seeds.rb
  111. 0  test/dummy/lib/assets/.gitkeep
  112. 0  test/dummy/log/.gitkeep
  113. 0  { → test/dummy}/public/404.html
  114. 0  { → test/dummy}/public/422.html
  115. +0 −1  { → test/dummy}/public/500.html
  116. 0  test/dummy/public/favicon.ico
  117. +6 −0 test/dummy/script/rails
  118. +0 −24 test/factories.rb
  119. +39 −37 test/functional/cms/blog_posts_controller_test.rb
  120. +21 −19 test/functional/cms/blogs_controller_test.rb
  121. +1 −1  test/integration/blog_controller_test.rb
  122. +1 −1  test/integration/blog_post_test.rb
  123. +0 −9 test/performance/browsing_test.rb
  124. +71 −0 test/support/blog_test_helper.rb
  125. +54 −0 test/support/factories.rb
  126. +2 −0  test/support/factory_girl_support.rb
  127. +9 −12 test/test_helper.rb
  128. +8 −8 test/unit/blog_comment_test.rb
  129. +69 −67 test/unit/blog_observer_test.rb
  130. +34 −32 test/unit/blog_post_test.rb
  131. +7 −7 test/unit/blog_test.rb
View
21 .gitignore
@@ -1,15 +1,8 @@
-coverage/**/*
-.DS_Store
+.bundle/
log/*.log
-tmp/**/*
-db/*.sqlite3
-db/schema.rb
-*.gem
-.dotest
-tmp/restart.txt
-public/cache
-.idea
-.specification
-Gemfile.lock
-*.swp
-TODO
+pkg/
+test/dummy/db/*.sqlite3
+test/dummy/log/*.log
+test/dummy/tmp/
+test/dummy/.sass-cache
+.DS_Store
View
2  .rvmrc
@@ -1 +1 @@
-rvm use 1.9.2@rails3.0
+rvm use 1.9.3@r3.2
View
8 Gemfile
@@ -2,7 +2,9 @@ source 'http://rubygems.org'
gem 'sqlite3'
-gem 'factory_girl_rails', '1.0', :group=>:test
-gem 'mocha', :require=>false, :group=>:test
-gem 'bcms_support'
+group :test do
+ gem 'factory_girl_rails'
+ gem 'mocha', :require=>false
+end
+
gemspec
View
132 Gemfile.lock
@@ -0,0 +1,132 @@
+PATH
+ remote: .
+ specs:
+ bcms_blog (1.3.0)
+ browsercms (>= 3.5.0.rc4, < 3.6.0)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.2.3)
+ actionpack (= 3.2.3)
+ mail (~> 2.4.4)
+ actionpack (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.1)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.1.2)
+ activemodel (3.2.3)
+ activesupport (= 3.2.3)
+ builder (~> 3.0.0)
+ activerecord (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activeresource (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
+ activesupport (3.2.3)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ ancestry (1.2.5)
+ activerecord (>= 2.2.2)
+ arel (3.0.2)
+ browsercms (3.5.0.rc4)
+ ancestry (~> 1.2.4)
+ ckeditor_rails (~> 3.6.2.2)
+ jquery-rails (~> 2.0)
+ paperclip (~> 3.0.3)
+ rails (~> 3.2.0)
+ sass-rails
+ term-ansicolor
+ builder (3.0.0)
+ ckeditor_rails (3.6.2.2)
+ railties (~> 3.0)
+ thor (~> 0.14)
+ cocaine (0.2.1)
+ erubis (2.7.0)
+ factory_girl (3.3.0)
+ activesupport (>= 3.0.0)
+ factory_girl_rails (3.3.0)
+ factory_girl (~> 3.3.0)
+ railties (>= 3.0.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ journey (1.0.3)
+ jquery-rails (2.0.2)
+ railties (>= 3.2.0, < 5.0)
+ thor (~> 0.14)
+ json (1.7.3)
+ mail (2.4.4)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ metaclass (0.0.1)
+ mime-types (1.18)
+ mocha (0.11.4)
+ metaclass (~> 0.0.1)
+ multi_json (1.3.6)
+ paperclip (3.0.4)
+ activemodel (>= 3.0.0)
+ activerecord (>= 3.0.0)
+ activesupport (>= 3.0.0)
+ cocaine (>= 0.0.2)
+ mime-types
+ polyglot (0.3.3)
+ rack (1.4.1)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.2.3)
+ actionmailer (= 3.2.3)
+ actionpack (= 3.2.3)
+ activerecord (= 3.2.3)
+ activeresource (= 3.2.3)
+ activesupport (= 3.2.3)
+ bundler (~> 1.0)
+ railties (= 3.2.3)
+ railties (3.2.3)
+ actionpack (= 3.2.3)
+ activesupport (= 3.2.3)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ sass (3.1.19)
+ sass-rails (3.2.5)
+ railties (~> 3.2.0)
+ sass (>= 3.1.10)
+ tilt (~> 1.3)
+ sprockets (2.1.3)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.6)
+ term-ansicolor (1.0.7)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.33)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bcms_blog!
+ factory_girl_rails
+ mocha
+ sqlite3
View
14 README.markdown
@@ -15,18 +15,21 @@ A simple blog module that lets users create multiple blogs.
The blog module installs like most other BrowserCMS modules (http://guides.browsercms.org/installing_modules.html)
- gem install bcms_blog
+ $ gem install bcms_blog
## Set up your application to use the module
### 1. Install the module
- rails g cms:install bcms_blog
+ $ rails g cms:install bcms_blog
### 2. Run the following commands
- rake db:migrate
-
+ $ rake db:migrate
+ $ rake db:seed
+
+For projects with existing databases, you may need to comment out other lines in db/seeds.rb so only the blog seed data runs.
+
## Creating a Blog
* To get started, go to the Content Library and choose the Blog module in the left hand menu.
@@ -103,3 +106,6 @@ Special thanks to some amazing folks from the BrowserCMS community for their wor
* Notifications for Comments - Blogs should have an option to be notified when a new comment is created. This will allow for practical management of comments/spam.
* Messaging for Moderated comments - If moderation is turned on, users get no feedback about the comment they just left. Ideally, they would get some sort of javascript notice that their comment is awaiting notification.
+## 3.5.x Todo
+
+* Test and release
View
42 Rakefile
@@ -1,10 +1,40 @@
-# Add your own tasks in files placed in lib/tasks ending in .rake,
-# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+#!/usr/bin/env rake
+begin
+ require 'bundler/setup'
+rescue LoadError
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
+end
+begin
+ require 'rdoc/task'
+rescue LoadError
+ require 'rdoc/rdoc'
+ require 'rake/rdoctask'
+ RDoc::Task = Rake::RDocTask
+end
+
+RDoc::Task.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'BcmsBlog'
+ rdoc.options << '--line-numbers'
+ rdoc.rdoc_files.include('README.rdoc')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
+load 'rails/tasks/engine.rake'
-require File.expand_path('../config/application', __FILE__)
-require 'rake'
-BcmsBlog::Application.load_tasks
-require 'bundler'
Bundler::GemHelper.install_tasks
+
+require 'rake/testtask'
+
+Rake::TestTask.new(:test => 'app:test:prepare') do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = false
+end
+
+
+task :default => :test
View
0  vendor/plugins/.gitkeep → app/assets/images/bcms_blog/.gitkeep
File renamed without changes
View
15 app/assets/javascripts/bcms_blog/application.js
@@ -0,0 +1,15 @@
+// This is a manifest file that'll be compiled into application.js, which will include all the files
+// listed below.
+//
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
+// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
+//
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
+// GO AFTER THE REQUIRES BELOW.
+//
+//= require jquery
+//= require jquery_ujs
+//= require_tree .
View
13 app/assets/stylesheets/bcms_blog/application.css
@@ -0,0 +1,13 @@
+/*
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
+ * listed below.
+ *
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
+ *
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
+ * compiled file, but it's generally better to create a new file per style scope.
+ *
+ *= require_self
+ *= require_tree .
+*/
View
5 app/controllers/bcms_blog/blog_comments_controller.rb
@@ -0,0 +1,5 @@
+module BcmsBlog
+ class BlogCommentsController < Cms::ContentBlockController
+
+ end
+end
View
37 app/controllers/bcms_blog/blog_posts_controller.rb
@@ -0,0 +1,37 @@
+module BcmsBlog
+ class BlogPostsController < Cms::ContentBlockController
+ before_filter :show_no_access_if_none_editable
+
+ def build_block
+ super
+ ensure_blog_editable
+ @block.author = current_user
+ end
+
+ def load_block
+ super
+ ensure_blog_editable
+ end
+
+ def load_blocks
+ super
+ @blocks.delete_if { |b| !b.editable_by?(current_user) }
+ end
+
+ private
+
+ # If the current user is not able to edit any blog, just show them a page saying so
+ def show_no_access_if_none_editable
+ if Blog.editable_by(current_user).empty?
+ render :action => "no_access"
+ end
+ end
+
+ # Ensure the current user can actually edit the blog this blog post is associated with
+ def ensure_blog_editable
+ if @block.blog
+ raise Cms::Errors::AccessDenied unless @block.blog.editable_by?(current_user)
+ end
+ end
+ end
+end
View
13 app/controllers/bcms_blog/blogs_controller.rb
@@ -0,0 +1,13 @@
+module BcmsBlog
+ class BlogsController < Cms::ContentBlockController
+ check_permissions :administrate, :except => :index
+
+ def index
+ if current_user.able_to?(:administrate)
+ super
+ else
+ render :action => "admin_only"
+ end
+ end
+ end
+end
View
10 app/controllers/bcms_blog/feeds_controller.rb
@@ -0,0 +1,10 @@
+module BcmsBlog
+ class FeedsController < ApplicationController
+
+ def index
+ @blog = Blog.find(params[:blog_id])
+ @blog_posts = @blog.posts.published.all(:limit => 10, :order => "published_at DESC")
+ end
+
+ end
+end
View
3  app/controllers/cms/blog_comments_controller.rb
@@ -1,3 +0,0 @@
-class Cms::BlogCommentsController < Cms::ContentBlockController
-
-end
View
35 app/controllers/cms/blog_posts_controller.rb
@@ -1,35 +0,0 @@
-class Cms::BlogPostsController < Cms::ContentBlockController
- before_filter :show_no_access_if_none_editable
-
- def build_block
- super
- ensure_blog_editable
- @block.author = current_user
- end
-
- def load_block
- super
- ensure_blog_editable
- end
-
- def load_blocks
- super
- @blocks.delete_if { |b| !b.editable_by?(current_user) }
- end
-
- private
-
- # If the current user is not able to edit any blog, just show them a page saying so
- def show_no_access_if_none_editable
- if Blog.editable_by(current_user).empty?
- render :action => "no_access"
- end
- end
-
- # Ensure the current user can actually edit the blog this blog post is associated with
- def ensure_blog_editable
- if @block.blog
- raise Cms::Errors::AccessDenied unless @block.blog.editable_by?(current_user)
- end
- end
-end
View
11 app/controllers/cms/blogs_controller.rb
@@ -1,11 +0,0 @@
-class Cms::BlogsController < Cms::ContentBlockController
- check_permissions :administrate, :except => :index
-
- def index
- if current_user.able_to?(:administrate)
- super
- else
- render :action => "admin_only"
- end
- end
-end
View
8 app/controllers/feeds_controller.rb
@@ -1,8 +0,0 @@
-class FeedsController < ApplicationController
-
- def index
- @blog = Blog.find(params[:blog_id])
- @blog_posts = @blog.posts.published.all(:limit => 10, :order => "published_at DESC")
- end
-
-end
View
27 app/helpers/bcms_blog/blog_helper.rb
@@ -0,0 +1,27 @@
+module BcmsBlog
+ module BlogHelper
+ # We can't call it 'blog_path' because that would conflict with the actual named route method if there's a blog named "Blog".
+ def _blog_path(blog, route_name, route_params)
+ send("#{blog.name_for_path}_#{route_name}_path", route_params)
+ end
+
+ def _blog_post_path(blog_post)
+ main_app.send("#{blog_post.route_name}_path", blog_post.route_params)
+ end
+
+ def feeds_link_tag_for(name)
+ blog = Blog.find_by_name(name)
+ auto_discovery_link_tag(:rss, main_app.blog_feeds_url(:blog_id => blog), :title => "#{blog.name}")
+ end
+
+ def new_comment_params(portlet)
+ {:url=> Cms::Engine.routes.url_helpers.portlet_handler_path(:id=>portlet.id, :handler=>'create_comment'),
+ :method=>'post'}
+ end
+
+ # Cms::ViewContext doesn't expose this method correctly, so duplicating it here.
+ def main_app
+ Rails.application.routes.url_helpers
+ end
+ end
+end
View
20 app/helpers/cms/blog_helper.rb
@@ -1,20 +0,0 @@
-module Cms::BlogHelper
- # We can't call it 'blog_path' because that would conflict with the actual named route method if there's a blog named "Blog".
- def _blog_path(blog, route_name, route_params)
- send("#{blog.name_for_path}_#{route_name}_path", route_params)
- end
-
- def _blog_post_path(blog_post)
- send("#{blog_post.route_name}_path", blog_post.route_params)
- end
-
- def feeds_link_tag_for(name)
- blog = Blog.find_by_name(name)
- auto_discovery_link_tag(:rss, blog_feeds_url(:blog_id => blog), :title => "#{blog.name}")
- end
-
- def new_comment_path(portlet)
- url_for(:controller=>"cms/portlet", :action=>"execute_handler", :id=>portlet.id, :handler=>"create_comment")
- end
-end
-
View
99 app/models/bcms_blog/blog.rb
@@ -0,0 +1,99 @@
+module BcmsBlog
+ class Blog < ActiveRecord::Base
+ acts_as_content_block
+
+ has_many :posts, :class_name => "BlogPost", :conditions => { :published => true }, :order => "published_at desc"
+ has_many :blog_group_memberships
+ has_many :groups, :through => :blog_group_memberships, :class_name=>"Cms::Group"
+
+ attr_accessible :group_ids
+
+ validates_presence_of :name
+ validates_uniqueness_of :name
+
+ scope :editable_by, lambda { |user|
+ if user.able_to?(:administrate)
+ { }
+ else
+ { :include => :groups, :conditions => ["groups.id IN (?)", user.group_ids.join(",")] }
+ end
+ }
+
+ def self.default_template
+ template_file = ActionController::Base.view_paths.map do |vp|
+ path = vp.to_s.first == "/" ? vp.to_s : File.join(Rails.root, vp.to_s)
+ File.join(path, "bcms_blog/blogs/render.html.erb")
+ end.detect{|f| File.exists? f }
+ template_file ? open(template_file){|f| f.read } : ""
+ end
+
+ def self.posts_finder(finder, options)
+ if options[:tag]
+ finder = finder.tagged_with(options[:tag])
+ end
+ if options[:exclude_tags]
+ finder = finder.not_tagged_with(options[:exclude_tags])
+ end
+ if options[:category] || options[:category_id]
+ category_type = Cms::CategoryType.named("Blog Post").first
+ category = category_type.categories.named(options[:category]).first if options[:category]
+ category = category_type.categories. find(options[:category_id]) if options[:category_id]
+ finder = finder.in_category(category)
+ end
+ finder
+ end
+
+ def render
+ @blog = self
+ finder = @blog.posts.published
+ finder = Blog.posts_finder(finder, params)
+
+ if params[:year] && params[:month] && params[:day]
+ @date = Date.new(params[:year].to_i, params[:month].to_i, params[:day].to_i)
+ finder = posts.published_between(@date, @date + 1.day)
+ elsif params[:year] && params[:month]
+ @date = Date.new(params[:year].to_i, params[:month].to_i)
+ finder = posts.published_between(@date, @date + 1.month)
+ elsif params[:year]
+ @date = Date.new(params[:year].to_i)
+ finder = posts.published_between(@date, @date + 1.year)
+ end
+
+ @blog_posts = finder.all(:limit => 25, :order => "published_at desc")
+ raise ActiveRecord::RecordNotFound.new("No posts found") if @blog_posts.empty?
+
+ if params[:category]
+ @page_title = "#{params[:category]}"
+ elsif params[:tag]
+ @page_title = "Posts tagged with #{params[:tag]}"
+ elsif params[:year] && params[:month] && params[:day]
+ @page_title = "Posts from #{@date.to_s(:long)}"
+ elsif params[:year] && params[:month]
+ @page_title = "Posts from #{Date::MONTHNAMES[@date.month]} #{@date.year}"
+ elsif params[:year]
+ @page_title = "Posts from #{@date.year}"
+ end
+ end
+
+ def inline_options
+ {:inline => self.template}
+ end
+
+ def self.default_order
+ "name"
+ end
+
+ def editable_by?(user)
+ user.able_to?(:administrate) || !(group_ids & user.group_ids).empty?
+ end
+
+ def potential_authors
+ groups.map(&:users).flatten.uniq
+ end
+
+ def name_for_path
+ name.to_slug.gsub('-', '_')
+ end
+
+ end
+end
View
36 app/models/bcms_blog/blog_comment.rb
@@ -0,0 +1,36 @@
+module BcmsBlog
+ class BlogComment < ActiveRecord::Base
+ acts_as_content_block :is_searachable => "body"
+ belongs_to :post, :class_name => "BlogPost", :counter_cache => "comments_count"
+
+ validates_presence_of :post_id, :author, :body
+
+ before_create :publish_if_comments_are_enabled
+
+ def publish_if_comments_are_enabled
+ self.published = true unless post.blog.moderate_comments?
+ end
+
+ def self.default_order
+ "created_at desc"
+ end
+
+ def self.default_order_for_search
+ default_order
+ end
+
+ def self.columns_for_index
+ [ {:label => "Comment", :method => :name, :order => "body" },
+ {:label => "Created At", :method => :formatted_created_at, :order => "created_at"} ]
+ end
+
+ def name
+ body ? body[0..50] : ""
+ end
+
+ def formatted_created_at
+ created_at.to_s(:date)
+ end
+
+ end
+end
View
6 app/models/bcms_blog/blog_group_membership.rb
@@ -0,0 +1,6 @@
+module BcmsBlog
+ class BlogGroupMembership < ActiveRecord::Base
+ belongs_to :blog, :class_name => "BcmsBlog::Blog"
+ belongs_to :group, :class_name => "Cms::Group"
+ end
+end
View
141 app/models/bcms_blog/blog_observer.rb
@@ -0,0 +1,141 @@
+module BcmsBlog
+ class BlogObserver < ActiveRecord::Observer
+
+ def after_create(blog)
+ @blog = blog
+ create_section_pages_and_routes
+ end
+
+ def after_save(blog)
+ if blog.persisted?
+ blog.publish
+ end
+ end
+
+ # Can't use before_update since CMS callback stack is altered from normal callbacks.
+ def before_save(blog)
+ if blog.persisted?
+ update_section_pages_and_route(blog)
+ end
+ end
+
+ private
+
+ # A section, two pages, 6 routes and a portlet are created alongside every blog.
+ # This structure provides sensible defaults so users can pretty much start adding
+ # posts right after creating a blog without having to worry about where to put
+ # their blog and portlets.
+ def create_section_pages_and_routes
+ create_blog_section
+ create_blog_block_page
+ create_post_portlet_page
+ reload_routes
+ end
+
+ # Every blog is created within a section with the same name.
+ # For example, if you create a blog named 'MyBlog', a section 'MyBlog' will be
+ # created. This section will hold two pages: one for the blog ContentBlock that
+ # will render the list of posts and one for the BlogPost portlet (ie the individual
+ # post view)
+ def create_blog_section
+ @section = Cms::Section.find_by_name(@blog.name) || (
+ @section = Cms::Section.create!(
+ :name => @blog.name,
+ :path => "/#{@blog.name_for_path}",
+ :parent => Cms::Section.root.first
+ )
+ @section.allow_groups = :all
+ @section.save!
+ @section
+ )
+ end
+
+ # Following with the above example, the first page that is created is named 'MyBlog' and
+ # holds the Blog ContentBlock directly, not a portlet. Together with the 5 created routes,
+ # this page and its ContentBlock handle different post listings (all posts, posts in year,
+ # month or day and posts by tag or category).
+ def create_blog_block_page
+ page = Cms::Page.find_by_name(@blog.name) || Cms::Page.create!(
+ :name => @blog.name,
+ :path => "/#{@blog.name_for_path}",
+ :section => @section,
+ :template_file_name => "default.html.erb",
+ :hidden => true
+ )
+ page.create_connector(@blog, 'main')
+
+ create_route(page, "#{@blog.name}: Posts In Day", "/#{@blog.name_for_path}/:year/:month/:day")
+ create_route(page, "#{@blog.name}: Posts In Month", "/#{@blog.name_for_path}/:year/:month")
+ create_route(page, "#{@blog.name}: Posts In Year", "/#{@blog.name_for_path}/:year")
+ create_route(page, "#{@blog.name}: Posts With Tag", "/#{@blog.name_for_path}/tag/:tag")
+ create_route(page, "#{@blog.name}: Posts In Category", "/#{@blog.name_for_path}/category/:category")
+ end
+
+ # The second page that is created holds the BlogPostPortlet and displays the individual
+ # post view, along with it's comments.
+ def create_post_portlet_page
+ page = Cms::Page.find_by_name(portlet_name = "#{@blog.name}: Post") || Cms::Page.create!(
+ :name => portlet_name,
+ :path => "/#{@blog.name_for_path}/post",
+ :section => @section,
+ :template_file_name => "default.html.erb",
+ :hidden => true)
+ page.publish
+ create_route(page, portlet_name, "/#{@blog.name_for_path}/:year/:month/:day/:slug")
+ create_portlet(page, portlet_name, BlogPostPortlet)
+ end
+
+ # When the name of a Blog block changes, we need to change the Post page route.
+ # We also change the *names* of the section and pages that hold the blog block and
+ # post portlet because presumably, by changing the name of the blog, the intention
+ # was to reflect this name change in breadcrumbs and menus.
+ #
+ # Note that no other routes or paths are updated. This is intentional to be consistent
+ # with how BrowserCMS behaves when a Section or Page names change: paths are not
+ # updated automatically.
+ def update_section_pages_and_route(blog)
+ if blog.name_changed?
+ old_blog_name = blog.name_was
+
+ Cms::Section.find_by_name(old_blog_name).update_attribute(:name, blog.name)
+ Cms::PageRoute.find_by_name("#{old_blog_name}: Post").update_attribute(:name, "#{blog.name}: Post")
+
+ page = Cms::Page.find_by_name("#{old_blog_name}: Post")
+ page.update_attribute(:name, "#{blog.name}: Post")
+ page.publish
+
+ page = Cms::Page.find_by_name(old_blog_name)
+ page.update_attribute(:name, blog.name)
+ page.publish
+ end
+ end
+
+ def reload_routes
+ Cms::PageRoute.reload_routes
+ end
+
+ def create_route(page, name, pattern)
+ route = page.page_routes.build(:name => name, :pattern => pattern, :code => "")
+ route.save!
+ route.add_condition(:method, "get").save
+ route.add_requirement(:year, '\d{4,}') if pattern.include?(":year")
+ route.add_requirement(:month, '\d{2,}') if pattern.include?(":month")
+ route.add_requirement(:day, '\d{2,}') if pattern.include?(":day")
+ route.requirements.each(&:save)
+ end
+
+ def create_portlet(page, name, portlet_class)
+ portlet_class.create!(
+ :name => "#{name} Portlet",
+ :blog_id => @blog.id,
+ :template => portlet_class.default_template,
+ :connect_to_page_id => page.id,
+ :connect_to_container => "main",
+ :publish_on_save => true)
+ end
+ end
+end
+
+
+
+
View
108 app/models/bcms_blog/blog_post.rb
@@ -0,0 +1,108 @@
+module BcmsBlog
+ class BlogPost < ActiveRecord::Base
+ acts_as_content_block :taggable => true
+
+ has_attachment :file
+
+
+ before_save :set_published_at
+
+ belongs_to :blog
+ belongs_to_category
+ belongs_to :author, :class_name => "Cms::User"
+ has_many :comments, :class_name => "BlogComment", :foreign_key => "post_id"
+
+ before_validation :set_slug
+ validates_presence_of :name, :slug, :blog_id, :author_id
+
+ scope :published_between, lambda { |start, finish|
+ { :conditions => [
+ "#{table_name}.published_at >= ? AND #{table_name}.published_at < ?",
+ start, finish ] }
+ }
+
+ scope :not_tagged_with, lambda { |tag| {
+ :conditions => [
+ "#{table_name}.id not in (
+ SELECT taggings.taggable_id FROM taggings
+ JOIN tags ON tags.id = taggings.tag_id
+ WHERE taggings.taggable_type = 'BlogPost'
+ AND (tags.name = ?)
+ )",
+ tag
+ ]
+ } }
+
+ INCORRECT_PARAMETERS = "Incorrect parameters. This is probably because you are trying to view the " +
+ "portlet through the CMS interface, and so we have no way of knowing what " +
+ "post(s) to show"
+
+ delegate :editable_by?, :to => :blog
+
+ def set_published_at
+ if !published_at && publish_on_save
+ self.published_at = Time.now
+ end
+ end
+
+ # This is necessary because, oddly, the publish! method in the Publishing behaviour sends an update
+ # query directly to the database, bypassing callbacks, so published_at does not get set by our
+ # set_published_at callback.
+ def after_publish_with_set_published_at
+ if published_at.nil?
+ self.published_at = Time.now
+ self.save!
+ end
+ after_publish_without_set_published_at if respond_to? :after_publish_without_set_published_at
+ end
+ if instance_methods.map(&:to_s).include? 'after_publish'
+ alias_method_chain :after_publish, :set_published_at
+ else
+ alias_method :after_publish, :after_publish_with_set_published_at
+ end
+
+ def self.default_order
+ "created_at desc"
+ end
+
+ def self.columns_for_index
+ [ {:label => "Name", :method => :name, :order => "name" },
+ {:label => "Published At", :method => :published_label, :order => "published_at" } ]
+ end
+
+ def published_label
+ published_at ? published_at.to_s(:date) : nil
+ end
+
+ def set_slug
+ self.slug = name.to_slug
+ end
+
+ def path
+ send("#{blog.name_for_path}_post_path", route_params)
+ end
+ def route_name
+ "#{blog.name_for_path}_post"
+ end
+ def route_params
+ {:year => year, :month => month, :day => day, :slug => slug}
+ end
+
+ def year
+ published_at.strftime("%Y") unless published_at.blank?
+ end
+
+ def month
+ published_at.strftime("%m") unless published_at.blank?
+ end
+
+ def day
+ published_at.strftime("%d") unless published_at.blank?
+ end
+
+ # Return true if this model has an attachment
+ def attachment
+ !file.blank?
+ end
+ end
+end
View
95 app/models/blog.rb
@@ -1,95 +0,0 @@
-class Blog < ActiveRecord::Base
- acts_as_content_block
-
- has_many :posts, :class_name => "BlogPost", :conditions => { :published => true }, :order => "published_at desc"
- has_many :blog_group_memberships
- has_many :groups, :through => :blog_group_memberships
-
- validates_presence_of :name
- validates_uniqueness_of :name
-
- scope :editable_by, lambda { |user|
- if user.able_to?(:administrate)
- { }
- else
- { :include => :groups, :conditions => ["groups.id IN (?)", user.group_ids.join(",")] }
- end
- }
-
- def self.default_template
- template_file = ActionController::Base.view_paths.map do |vp|
- path = vp.to_s.first == "/" ? vp.to_s : File.join(Rails.root, vp.to_s)
- File.join(path, "cms/blogs/render.html.erb")
- end.detect{|f| File.exists? f }
- template_file ? open(template_file){|f| f.read } : ""
- end
-
- def self.posts_finder(finder, options)
- if options[:tag]
- finder = finder.tagged_with(options[:tag])
- end
- if options[:exclude_tags]
- finder = finder.not_tagged_with(options[:exclude_tags])
- end
- if options[:category] || options[:category_id]
- category_type = CategoryType.named("Blog Post").first
- category = category_type.categories.named(options[:category]).first if options[:category]
- category = category_type.categories. find(options[:category_id]) if options[:category_id]
- finder = finder.in_category(category)
- end
- finder
- end
-
- def render
- @blog = self
- finder = @blog.posts.published
- finder = Blog.posts_finder(finder, params)
-
- if params[:year] && params[:month] && params[:day]
- @date = Date.new(params[:year].to_i, params[:month].to_i, params[:day].to_i)
- finder = posts.published_between(@date, @date + 1.day)
- elsif params[:year] && params[:month]
- @date = Date.new(params[:year].to_i, params[:month].to_i)
- finder = posts.published_between(@date, @date + 1.month)
- elsif params[:year]
- @date = Date.new(params[:year].to_i)
- finder = posts.published_between(@date, @date + 1.year)
- end
-
- @blog_posts = finder.all(:limit => 25, :order => "published_at desc")
- raise ActiveRecord::RecordNotFound.new("No posts found") if @blog_posts.empty?
-
- if params[:category]
- @page_title = "#{params[:category]}"
- elsif params[:tag]
- @page_title = "Posts tagged with #{params[:tag]}"
- elsif params[:year] && params[:month] && params[:day]
- @page_title = "Posts from #{@date.to_s(:long)}"
- elsif params[:year] && params[:month]
- @page_title = "Posts from #{Date::MONTHNAMES[@date.month]} #{@date.year}"
- elsif params[:year]
- @page_title = "Posts from #{@date.year}"
- end
- end
-
- def inline_options
- {:inline => self.template}
- end
-
- def self.default_order
- "name"
- end
-
- def editable_by?(user)
- user.able_to?(:administrate) || !(group_ids & user.group_ids).empty?
- end
-
- def potential_authors
- groups.map(&:users).flatten.uniq
- end
-
- def name_for_path
- name.to_slug.gsub('-', '_')
- end
-
-end
View
34 app/models/blog_comment.rb
@@ -1,34 +0,0 @@
-class BlogComment < ActiveRecord::Base
- acts_as_content_block :is_searachable => "body"
- belongs_to :post, :class_name => "BlogPost", :counter_cache => "comments_count"
-
- validates_presence_of :post_id, :author, :body
-
- before_create :publish_if_comments_are_enabled
-
- def publish_if_comments_are_enabled
- self.published = true unless post.blog.moderate_comments?
- end
-
- def self.default_order
- "blog_comments.created_at desc"
- end
-
- def self.default_order_for_search
- default_order
- end
-
- def self.columns_for_index
- [ {:label => "Comment", :method => :name, :order => "blog_comments.body" },
- {:label => "Created At", :method => :formatted_created_at, :order => "blog_comments.created_at"} ]
- end
-
- def name
- body ? body[0..50] : ""
- end
-
- def formatted_created_at
- created_at.to_s(:date)
- end
-
-end
View
4 app/models/blog_group_membership.rb
@@ -1,4 +0,0 @@
-class BlogGroupMembership < ActiveRecord::Base
- belongs_to :blog
- belongs_to :group
-end
View
140 app/models/blog_observer.rb
@@ -1,140 +0,0 @@
-class BlogObserver < ActiveRecord::Observer
-
- def after_create(blog)
- @blog = blog
- create_section_pages_and_routes
- end
-
- def after_save(blog)
- if blog.persisted?
- blog.publish
- end
- end
-
- # Can't use before_update since CMS callback stack is altered from normal callbacks.
- def before_save(blog)
- if blog.persisted?
- update_section_pages_and_route(blog)
- end
- end
-
- private
-
- # A section, two pages, 6 routes and a portlet are created alongside every blog.
- # This structure provides sensible defaults so users can pretty much start adding
- # posts right after creating a blog without having to worry about where to put
- # their blog and portlets.
- def create_section_pages_and_routes
- create_blog_section
- create_blog_block_page
- create_post_portlet_page
- reload_routes
- end
-
- # Every blog is created within a section with the same name.
- # For example, if you create a blog named 'MyBlog', a section 'MyBlog' will be
- # created. This section will hold two pages: one for the blog ContentBlock that
- # will render the list of posts and one for the BlogPost portlet (ie the individual
- # post view)
- def create_blog_section
- @section = Section.find_by_name(@blog.name) || (
- @section = Section.create!(
- :name => @blog.name,
- :path => "/#{@blog.name_for_path}",
- :parent_id => 1
- )
- @section.allow_groups = :all
- @section.save!
- @section
- )
- end
-
- # Following with the above example, the first page that is created is named 'MyBlog' and
- # holds the Blog ContentBlock directly, not a portlet. Together with the 5 created routes,
- # this page and its ContentBlock handle different post listings (all posts, posts in year,
- # month or day and posts by tag or category).
- def create_blog_block_page
- page = Page.find_by_name(@blog.name) || Page.create!(
- :name => @blog.name,
- :path => "/#{@blog.name_for_path}",
- :section => @section,
- :template_file_name => "default.html.erb",
- :hidden => true
- )
- page.create_connector(@blog, 'main')
-
- create_route(page, "#{@blog.name}: Posts In Day", "/#{@blog.name_for_path}/:year/:month/:day")
- create_route(page, "#{@blog.name}: Posts In Month", "/#{@blog.name_for_path}/:year/:month")
- create_route(page, "#{@blog.name}: Posts In Year", "/#{@blog.name_for_path}/:year")
- create_route(page, "#{@blog.name}: Posts With Tag", "/#{@blog.name_for_path}/tag/:tag")
- create_route(page, "#{@blog.name}: Posts In Category", "/#{@blog.name_for_path}/category/:category")
- end
-
- # The second page that is created holds the BlogPostPortlet and displays the individual
- # post view, along with it's comments.
- def create_post_portlet_page
- page = Page.find_by_name(portlet_name = "#{@blog.name}: Post") || Page.create!(
- :name => portlet_name,
- :path => "/#{@blog.name_for_path}/post",
- :section => @section,
- :template_file_name => "default.html.erb",
- :hidden => true)
- page.publish
- create_route(page, portlet_name, "/#{@blog.name_for_path}/:year/:month/:day/:slug")
- create_portlet(page, portlet_name, BlogPostPortlet)
- end
-
- # When the name of a Blog block changes, we need to change the Post page route.
- # We also change the *names* of the section and pages that hold the blog block and
- # post portlet because presumably, by changing the name of the blog, the intention
- # was to reflect this name change in breadcrumbs and menus.
- #
- # Note that no other routes or paths are updated. This is intentional to be consistent
- # with how BrowserCMS behaves when a Section or Page names change: paths are not
- # updated automatically.
- def update_section_pages_and_route(blog)
- if blog.name_changed?
- old_blog_name = blog.name_was
-
- Section.find_by_name(old_blog_name).update_attribute(:name, blog.name)
- PageRoute.find_by_name("#{old_blog_name}: Post").update_attribute(:name, "#{blog.name}: Post")
-
- page = Page.find_by_name("#{old_blog_name}: Post")
- page.update_attribute(:name, "#{blog.name}: Post")
- page.publish
-
- page = Page.find_by_name(old_blog_name)
- page.update_attribute(:name, blog.name)
- page.publish
- end
- end
-
- def reload_routes
- PageRoute.reload_routes
- end
-
- def create_route(page, name, pattern)
- route = page.page_routes.build(:name => name, :pattern => pattern, :code => "")
- route.save!
- route.add_condition(:method, "get").save
- route.add_requirement(:year, '\d{4,}') if pattern.include?(":year")
- route.add_requirement(:month, '\d{2,}') if pattern.include?(":month")
- route.add_requirement(:day, '\d{2,}') if pattern.include?(":day")
- route.requirements.each(&:save)
- end
-
- def create_portlet(page, name, portlet_class)
- portlet_class.create!(
- :name => "#{name} Portlet",
- :blog_id => @blog.id,
- :template => portlet_class.default_template,
- :connect_to_page_id => page.id,
- :connect_to_container => "main",
- :publish_on_save => true)
- end
-end
-
-
-
-
-
View
113 app/models/blog_post.rb
@@ -1,113 +0,0 @@
-class BlogPost < ActiveRecord::Base
- acts_as_content_block :taggable => true
-
- belongs_to_attachment
- def set_attachment_file_path
- # The default behavior is use /attachments/file.txt for the attachment path,
- # assuming file.txt was the name of the file the user uploaded
- # You should override this with your own strategy for setting the attachment path
- super
- end
-
- def set_attachment_section
- # The default behavior is to put all attachments in the root section
- # Override this method if you would like to change that
- super
- end
-
-
- before_save :set_published_at
-
- belongs_to :blog
- belongs_to_category
- belongs_to :author, :class_name => "User"
- has_many :comments, :class_name => "BlogComment", :foreign_key => "post_id"
-
- before_validation :set_slug
- validates_presence_of :name, :slug, :blog_id, :author_id
-
- scope :published_between, lambda { |start, finish|
- { :conditions => [
- "blog_posts.published_at >= ? AND blog_posts.published_at < ?",
- start, finish ] }
- }
-
- scope :not_tagged_with, lambda { |tag| {
- :conditions => [
- "blog_posts.id not in (
- SELECT taggings.taggable_id FROM taggings
- JOIN tags ON tags.id = taggings.tag_id
- WHERE taggings.taggable_type = 'BlogPost'
- AND (tags.name = ?)
- )",
- tag
- ]
- } }
-
- INCORRECT_PARAMETERS = "Incorrect parameters. This is probably because you are trying to view the " +
- "portlet through the CMS interface, and so we have no way of knowing what " +
- "post(s) to show"
-
- delegate :editable_by?, :to => :blog
-
- def set_published_at
- if !published_at && publish_on_save
- self.published_at = Time.now
- end
- end
-
- # This is necessary because, oddly, the publish! method in the Publishing behaviour sends an update
- # query directly to the database, bypassing callbacks, so published_at does not get set by our
- # set_published_at callback.
- def after_publish_with_set_published_at
- if published_at.nil?
- self.published_at = Time.now
- self.save!
- end
- after_publish_without_set_published_at if respond_to? :after_publish_without_set_published_at
- end
- if instance_methods.map(&:to_s).include? 'after_publish'
- alias_method_chain :after_publish, :set_published_at
- else
- alias_method :after_publish, :after_publish_with_set_published_at
- end
-
- def self.default_order
- "created_at desc"
- end
-
- def self.columns_for_index
- [ {:label => "Name", :method => :name, :order => "name" },
- {:label => "Published At", :method => :published_label, :order => "published_at" } ]
- end
-
- def published_label
- published_at ? published_at.to_s(:date) : nil
- end
-
- def set_slug
- self.slug = name.to_slug
- end
-
- def path
- send("#{blog.name_for_path}_post_path", route_params)
- end
- def route_name
- "#{blog.name_for_path}_post"
- end
- def route_params
- {:year => year, :month => month, :day => day, :slug => slug}
- end
-
- def year
- published_at.strftime("%Y") unless published_at.blank?
- end
-
- def month
- published_at.strftime("%m") unless published_at.blank?
- end
-
- def day
- published_at.strftime("%d") unless published_at.blank?
- end
-end
View
12 app/portlets/blog_post_portlet.rb
@@ -1,9 +1,9 @@
-class BlogPostPortlet < Portlet
+class BlogPostPortlet < Cms::Portlet
enable_template_editor false
def render
- scope = Blog.find(self.blog_id).posts
+ scope = BcmsBlog::Blog.find(self.blog_id).posts
if params[:blog_post_id]
@blog_post = scope.find(params[:blog_post_id])
elsif params[:slug]
@@ -13,7 +13,7 @@ def render
end
@blog_post = scope.find_by_slug!(params[:slug])
else
- raise BlogPost::INCORRECT_PARAMETERS
+ raise BcmsBlog::BlogPost::INCORRECT_PARAMETERS
end
make_page_title_use_blog_post_name(@blog_post)
@@ -29,7 +29,7 @@ def create_comment
work_around_cms_3_3_bug_where_current_user_is_not_correctly_set
params[:blog_comment].merge! :ip => request.remote_ip
- blog_comment = BlogComment.new(params[:blog_comment])
+ blog_comment = BcmsBlog::BlogComment.new(params[:blog_comment])
if blog_comment.valid? && blog_comment.save
url_for_success
else
@@ -42,10 +42,10 @@ def create_comment
private
def work_around_cms_3_3_bug_where_current_user_is_not_correctly_set
- User.current = current_user
+ Cms::User.current = current_user
end
- # This is a work around for a bug in bcms 3.3 where the Cms::PageHeler#page_title doesnt
+ # This is a work around for a bug in bcms 3.3 where the Cms::PageHelper#page_title doesnt
# share state between the portlet view and the page view.
# When the portlet view (app/views/portlets/blog_post/render) calls 'page_title @post.name'
# that instance variable isn't shared back to the page template.
View
8 app/portlets/blog_posts_portlet.rb
@@ -1,4 +1,4 @@
-class BlogPostsPortlet < Portlet
+class BlogPostsPortlet < Cms::Portlet
after_initialize :build_permalink_code
@@ -22,9 +22,9 @@ def render(_options = {})
Rails.logger.debug "... BlogPostsPortlet#render(options=#{@options.inspect} #{@options.class})"
if @options[:blog_id]
- finder = Blog.find(@options[:blog_id]).posts
+ finder = BcmsBlog::Blog.find(@options[:blog_id]).posts
elsif @options[:blog_name]
- finder = Blog.find_by_name(@options[:blog_name]).posts
+ finder = BcmsBlog::Blog.find_by_name(@options[:blog_name]).posts
else
finder = BlogPost
end
@@ -35,7 +35,7 @@ def render(_options = {})
end
finder = finder.published
- finder = Blog.posts_finder(finder, @options)
+ finder = BcmsBlog::Blog.posts_finder(finder, @options)
@blog_posts = finder.all(
:limit => @options[:limit] || 25,
View
5 app/views/bcms_blog/blog_comments/_form.html.erb
@@ -0,0 +1,5 @@
+<%= f.cms_drop_down :post_id, BcmsBlog::BlogPost.all(:order => "name").map{|p| [p.name, p.id]} %>
+<%= f.cms_text_field :author %>
+<%= f.cms_text_field :email %>
+<%= f.cms_text_field :url %>
+<%= f.cms_text_area :body %>
View
2  app/views/bcms_blog/blog_comments/render.html.erb
@@ -0,0 +1,2 @@
+<%= link_to h(@content_block.post.name), _blog_post_path(@content_block.post) %>
+<p><%=h @content_block.body.html_safe %></p>
View
2  app/views/cms/blog_posts/_form.html.erb → ...views/bcms_blog/blog_posts/_form.html.erb
@@ -7,5 +7,5 @@
<% end %>
<%= f.cms_drop_down :category_id, categories_for('Blog Post').map{|c| [c.path, c.id]}, :include_blank => true %>
<%= f.cms_tag_list %>
-<%= f.cms_drop_down :blog_id, Blog.editable_by(current_user).map{|b| [b.name, b.id]} %>
+<%= f.cms_drop_down :blog_id, BcmsBlog::Blog.editable_by(current_user).map{|b| [b.name, b.id]} %>
<%= f.cms_file_field :attachment_file, :label => "Image" %>
View
0  app/views/cms/blog_posts/no_access.html.erb → ...s/bcms_blog/blog_posts/no_access.html.erb
File renamed without changes
View
0  app/views/cms/blog_posts/render.html.erb → ...iews/bcms_blog/blog_posts/render.html.erb
File renamed without changes
View
4 app/views/cms/blogs/_form.html.erb → app/views/bcms_blog/blogs/_form.html.erb
@@ -5,7 +5,7 @@
<label>Permissions</label>
<%= hidden_field_tag "blog[group_ids][]", "", :id => nil %>
<div class="checkboxes">
- <% for group in Group.cms_access.all(:order => "groups.name") %>
+ <% for group in Cms::Group.cms_access.all(:order => "groups.name") %>
<div class="checkbox_fields">
<%= check_box_tag "blog[group_ids][]", group.id,
@block.groups.include?(group), :class => "cms_group_ids", :id => "cms_group_ids_#{group.id}", :tabindex => next_tabindex %>
@@ -21,7 +21,7 @@
</div>
<br clear="all" />
-<%= f.cms_text_area :template, :default_value => Blog.default_template %>
+<%= f.cms_text_area :template, :default_value => BcmsBlog::Blog.default_template %>
<div class="instructions" style="float:none">
Saving your blog might take a couple of seconds while everything is set up.
View
0  app/views/cms/blogs/admin_only.html.erb → ...views/bcms_blog/blogs/admin_only.html.erb
File renamed without changes
View
0  app/views/cms/blogs/render.html.erb → app/views/bcms_blog/blogs/render.html.erb
File renamed without changes
View
6 app/views/feeds/index.rss.builder → app/views/bcms_blog/feeds/index.rss.builder
@@ -2,7 +2,7 @@ xml.instruct! :xml, :version=>"1.0"
xml.rss(:version=>"2.0") do
xml.channel do
xml.title("#{@blog.name} Posts Feed")
- xml.link(blog_feeds_url(:id => @blog.id, :format => "rss"))
+ xml.link(main_app.blog_feeds_url(:id => @blog.id, :format => "rss"))
xml.description("")
xml.language('en-us')
for post in @blog_posts
@@ -10,8 +10,8 @@ xml.rss(:version=>"2.0") do
xml.title(post.name)
xml.description(post.summary) unless post.summary.blank?
xml.pubDate(post.published_at.strftime("%a, %d %b %Y %H:%M:%S %z")) unless post.published_at.blank?
- xml.link(send("#{@blog.name_for_path}_post_url", post.route_params))
- xml.guid(send("#{@blog.name_for_path}_post_url", post.route_params))
+ xml.link(main_app.send("#{@blog.name_for_path}_post_url", post.route_params))
+ xml.guid(main_app.send("#{@blog.name_for_path}_post_url", post.route_params))
end
end
end
View
5 app/views/cms/blog_comments/_form.html.erb
@@ -1,5 +0,0 @@
-<%= f.cms_drop_down :post_id, BlogPost.all(:order => "name").map{|p| [p.name, p.id]} %>
-<%= f.cms_text_field :author %>
-<%= f.cms_text_field :email %>
-<%= f.cms_text_field :url %>
-<%= f.cms_text_area :body %>
View
2  app/views/cms/blog_comments/render.html.erb
@@ -1,2 +0,0 @@
-<%= link_to h(@content_block.post.name), cms_blog_post_path(@content_block.post) %>
-<p><%=h @content_block.body.html_safe %></p>
View
2  app/views/portlets/blog_post/_form.html.erb
@@ -1,3 +1,3 @@
<%= f.cms_text_field :name %>
-<%= f.cms_drop_down :blog_id, Blog.all.map{|b| [b.name, b.id.to_s]} %>
+<%= f.cms_drop_down :blog_id, BcmsBlog::Blog.all.map{|b| [b.name, b.id.to_s]} %>
<%# f.cms_text_area :template, :default_value => @block.class.default_template %>
View
4 app/views/portlets/blog_post/render.html.erb
@@ -7,7 +7,9 @@
<%= render :partial => "partials/blog_post", :object => @blog_post %>
<div class="blog_comment_form">
- <%= form_for @blog_comment, :url => new_comment_path(@portlet) do |f| %>
+ <%#= form_for @blog_comment, :url => new_comment_path(@portlet) do |f| %>
+ <%= form_for @blog_comment, new_comment_params(@portlet) do |f| %>
+
<%= f.hidden_field :post_id %>
<%= f.cms_error_messages %>
<div class="fields text_fields">
View
2  app/views/portlets/blog_posts/_form.html.erb
@@ -1,6 +1,6 @@
<%= f.cms_text_field :name, :label => 'Portlet Name', :instructions => 'Since we may have many Articles portlets, each with different parameters, give each portlet a descriptive name.' %>
-<%= f.cms_drop_down :blog_id, Blog.all.map{|b| [b.name, b.id.to_s]}, :include_blank => true, :label => "Show posts from", :instructions => 'Leave blank to include posts from all blogs' %>
+<%= f.cms_drop_down :blog_id, Bcms::Blog.all.map{|b| [b.name, b.id.to_s]}, :include_blank => true, :label => "Show posts from", :instructions => 'Leave blank to include posts from all blogs' %>
<%# f.cms_drop_down :show_posts_as, [['First post as full post, the rest as Summary + Read More link', 'first_full_post_others_summary'], ['Summary + Read More link', 'summary'], ['Full post', 'full_post'], ['Title (links to post)', 'link']] %>
<%= f.cms_drop_down :show_posts_as, [['Title (links to post)', 'link'], ['Post', 'post']] %>
<%= f.cms_check_box :show_full_posts %>
View
25 bcms_blog.gemspec
@@ -1,10 +1,12 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "bcms_blog/version"
+
Gem::Specification.new do |s|
s.name = %q{bcms_blog}
- s.rubyforge_project = "bcms_blog"
- s.version = "1.2.0"
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version
+ s.rubyforge_project = s.name
+ s.version = BcmsBlog::VERSION
s.authors = ["BrowserMedia"]
- s.date = %q{2010-07-11}
s.description = %q{The Blog Module for BrowserCMS}
s.extra_rdoc_files = [
"LICENSE.txt",
@@ -13,12 +15,15 @@ Gem::Specification.new do |s|
s.summary = "The Blog Module for BrowserCMS"
s.email = "github@browsermedia.com"
s.homepage = "http://www.github.com/browsermedia/bcms_blog"
- s.files = Dir["app/**/*"]
- s.files += Dir["doc/**/*"]
- s.files += Dir["db/migrate/[0-9]*.rb"].reject {|f| f =~ /_browsercms|_load_seed/ }
- s.files += Dir["lib/**/*"]
- s.files -= Dir["app/controllers/application_controller.rb", "app/helpers/application_helper.rb"]
- s.add_dependency('browsercms', '~> 3.3.0')
+
+ s.files = Dir["{app,config,db,lib}/**/*"]
+ s.files += Dir["Gemfile", "LICENSE.txt", "COPYRIGHT.txt", "GPL.txt" ]
+
+ s.test_files += Dir["test/**/*"]
+ s.test_files -= Dir['test/dummy/**/*']
+
+ s.add_dependency("browsercms", "< 3.6.0", ">= 3.5.0.rc4")
+
end
View
6 config/boot.rb
@@ -1,6 +0,0 @@
-require 'rubygems'
-
-# Set up gems listed in the Gemfile.
-ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
-
-require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
View
26 config/database.mysql.yml
@@ -1,26 +0,0 @@
-development:
- adapter: mysql
- encoding: utf8
- database: browsercms_development
- username: root
- password:
- socket: /tmp/mysql.sock
-
-# Warning: The database defined as 'test' will be erased and
-# re-generated from your development database when you run 'rake'.
-# Do not set this db to the same as development or production.
-test:
- adapter: mysql
- encoding: utf8
- database: browsercms_test
- username: root
- password:
- socket: /tmp/mysql.sock
-
-production:
- adapter: mysql
- encoding: utf8
- database: browsercms_production
- username: root
- password:
- socket: /tmp/mysql.sock
View
65 config/routes.rb
@@ -1,62 +1,5 @@
-BcmsBlog::Application.routes.draw do
- routes_for_bcms_blog
-
- routes_for_browser_cms
-
- # The priority is based upon order of creation:
- # first created -> highest priority.
-
- # Sample of regular route:
- # match 'products/:id' => 'catalog#view'
- # Keep in mind you can assign values other than :controller and :action
-
- # Sample of named route:
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
- # This route can be invoked with purchase_url(:id => product.id)
-
- # Sample resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
-
- # Sample resource route with options:
- # resources :products do
- # member do
- # get 'short'
- # post 'toggle'
- # end
- #
- # collection do
- # get 'sold'
- # end
- # end
-
- # Sample resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Sample resource route with more complex sub-resources
- # resources :products do
- # resources :comments
- # resources :sales do
- # get 'recent', :on => :collection
- # end
- # end
-
- # Sample resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (app/controllers/admin/products_controller.rb)
- # resources :products
- # end
-
- # You can have the root of your site routed with "root"
- # just remember to delete public/index.html.
- # root :to => "welcome#index"
-
- # See how all your routes lay out with "rake routes"
-
- # This is a legacy wild controller route that's not recommended for RESTful applications.
- # Note: This route will make all actions in every controller accessible via GET requests.
- # match ':controller(/:action(/:id(.:format)))'
+BcmsBlog::Engine.routes.draw do
+ content_blocks :blogs
+ content_blocks :blog_posts
+ content_blocks :blog_comments
end
View
4 db/bcms_blog.seeds.rb
@@ -0,0 +1,4 @@
+Cms::ContentType.create!(:name => "BcmsBlog::Blog", :group_name => "Blog")
+Cms::CategoryType.create!(:name => "Blog Post")
+Cms::ContentType.create!(:name => "BcmsBlog::BlogPost", :group_name => "Blog")
+Cms::ContentType.create!(:name => "BcmsBlog::BlogComment", :group_name => "Blog")
View
11 db/migrate/20090415000000_create_blogs.rb
@@ -1,11 +1,11 @@
require 'pp'
-Page # trigger auto-loading
+Cms::Page # trigger auto-loading
# At the time of this writing, these associations are missing :dependent => :destroy
-class Page
+class Cms::Page
has_many :page_routes, :dependent => :destroy
end
-class PageRoute
+class Cms::PageRoute
has_many :requirements, :class_name => "PageRouteRequirement", :dependent => :destroy
has_many :conditions, :class_name => "PageRouteCondition", :dependent => :destroy
end
@@ -23,7 +23,6 @@ def self.up
t.integer :group_id
end
- ContentType.create!(:name => "Blog", :group_name => "Blog")
end
def self.down
@@ -34,8 +33,8 @@ def self.down
#Blog.all.map(&:connected_pages).flatten.map(&:page_routes).flatten.each(&:destroy)
pp Blog.all.map(&:connected_pages).flatten.each(&:destroy)
- ContentType.destroy_all(:name => "Blog")
- Connector.destroy_all(:connectable_type => "Blog")
+ Cms::ContentType.destroy_all(:name => "Blog")
+ Cms::Connector.destroy_all(:connectable_type => "Blog")
drop_table :blog_versions
drop_table :blogs
View
6 db/migrate/20090415000001_create_blog_posts.rb
@@ -11,14 +11,10 @@ def self.up
t.integer :comments_count
t.datetime :published_at
end
- CategoryType.create!(:name => "Blog Post")
- ContentType.create!(:name => "BlogPost", :group_name => "Blog")
+
end
def self.down
- ContentType.destroy_all(:name => 'BlogPost')
- CategoryType.destroy_all(:name => "Blog Post")
-
drop_table :blog_post_versions
drop_table :blog_posts
end
View
2  db/migrate/20090415000002_create_blog_comments.rb
@@ -8,11 +8,9 @@ def self.up
t.string :ip
t.text :body
end
- ContentType.create!(:name => "BlogComment", :group_name => "Blog")
end
def self.down
- ContentType.destroy_all(:name => 'BlogComment')
drop_table :blog_comment_versions
drop_table :blog_comments
end
View
9 db/migrate/20091109175123_browsercms_3_0_5.rb
@@ -1,9 +0,0 @@
-class Browsercms305 < ActiveRecord::Migration
- def self.up
- add_column :users, :reset_token, :string
- end
-
- def self.down
- remove_column :users, :reset_token
- end
-end
View
12 db/migrate/20120529184028_v130.rb
@@ -0,0 +1,12 @@
+require 'cms/upgrades/v3_5_0'
+
+# Upgrade this module to v1.3.0 of BcmsBlog (Rails 3.2/CMS 3.5.x compatible)
+class V130 < ActiveRecord::Migration
+ def change
+ ["Blog", "BlogPost", "BlogComment"].each do |model|
+ v3_5_0_apply_namespace_to_block("BcmsBlog", model)
+ end
+
+ rename_table "blog_group_memberships", "bcms_blog_blog_group_memberships"
+ end
+end
View
8 doc/migrate_to_20100427.rb
@@ -24,12 +24,12 @@
require 'pp'
-Page # trigger auto-loading
+Cms::Page # trigger auto-loading
# At the time of this writing, these associations are missing :dependent => :destroy
-class Page
+class Cms::Page
has_many :page_routes, :dependent => :destroy
end
-class PageRoute
+class Cms::PageRoute
has_many :requirements, :class_name => "PageRouteRequirement", :dependent => :destroy
has_many :conditions, :class_name => "PageRouteCondition", :dependent => :destroy
end
@@ -46,7 +46,7 @@ class MigrateTo20100427 < ActiveRecord::Migration
def self.up
drop_table :blog_group_membership_versions
- PageRouteOption.all.each {|a| a.destroy unless a.page_route }
+ Cms::PageRouteOption.all.each {|a| a.destroy unless a.page_route }
puts "Destroying portlets, pages, page_routes left over from old version of bcms_blog..."
puts "(*Not* destroying any existing Blogs, pages on which Blogs are connected, or BlogPosts)"
View
7 lib/bcms_blog.rb
@@ -1,2 +1,5 @@
-require 'bcms_blog/engine'
-require 'bcms_blog/routes'
+require "bcms_blog/engine"
+require 'bcms_blog/route_extensions'
+
+module BcmsBlog
+end
View
16 lib/bcms_blog/engine.rb
@@ -3,8 +3,22 @@
module BcmsBlog
class Engine < Rails::Engine
include Cms::Module
+ isolate_namespace BcmsBlog
- config.active_record.observers = :blog_observer
+ config.active_record.observers = 'bcms_blog/blog_observer'
+ config.to_prepare do
+ Cms::ViewContext.send(:include, BcmsBlog::BlogHelper)
+ ApplicationHelper.send(:include, BcmsBlog::BlogHelper)
+ end
+
+ initializer 'bcms_blog.route_extensions', :after => 'action_dispatch.prepare_dispatcher' do |app|
+ ActionDispatch::Routing::Mapper.send :include, BcmsBlog::RouteExtensions
+ end
+
+ config.before_configuration do |app|
+ # Used by blog_feed_url to determine the host
+ Rails.application.routes.default_url_options[:host]= config.cms.site_domain
+ end
end
end
View
8 lib/bcms_blog/route_extensions.rb
@@ -0,0 +1,8 @@
+module BcmsBlog::RouteExtensions
+ def mount_bcms_blog
+ mount BcmsBlog::Engine => "/bcms_blog"
+ match '/blog/feeds', :to=>"bcms_blog/feeds#index", :defaults=>{:format => "rss"}, :as=>'blog_feeds'
+ end
+
+ alias :routes_for_bcms_blog :mount_bcms_blog
+end
View
10 lib/bcms_blog/routes.rb
@@ -1,10 +0,0 @@
-module Cms::Routes
- def routes_for_bcms_blog
- match '/blog/feeds', :to=>"feeds#index", :defaults=>{:format => "rss"}, :as=>'blog_feeds'
- namespace(:cms) do
- content_blocks :blogs
- content_blocks :blog_posts
- content_blocks :blog_comments
- end
- end
-end
View
3  lib/bcms_blog/version.rb
@@ -0,0 +1,3 @@
+module BcmsBlog
+ VERSION = "1.3.0"
+end
View
22 lib/generators/bcms_blog/install/install_generator.rb
@@ -2,17 +2,17 @@
class BcmsBlog::InstallGenerator < Cms::ModuleInstallation
add_migrations_directory_to_source_root __FILE__
-
- # Add migrations to be copied, by uncommenting the following file and editing as needed.
- ['20090415000001_create_blog_posts.rb', '20090415000000_create_blogs.rb', '20090415000002_create_blog_comments.rb',
- '20090415000003_add_attachment_to_blog_posts.rb', '20100521042244_add_moderate_comments_to_blog.rb'].each do |mg|
- copy_migration_file mg
- end
+ def copy_migrations
+ rake 'bcms_blog:install:migrations'
+ end
+
+ def add_seed_data_to_project
+ copy_file "../bcms_blog.seeds.rb", "db/bcms_blog.seeds.rb"
+ append_to_file "db/seeds.rb", "\nload File.expand_path('../bcms_blog.seeds.rb', __FILE__)\n"
+ end
- def add_helpers
- append_to_file 'app/helpers/application_helper.rb', :after=>"module ApplicationHelper\n" do
- " include Cms::BlogHelper\n"
- end
- end
+ def add_routes
+ route 'mount_bcms_blog'
+ end
end
View
4 lib/tasks/bcms_blog_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :bcms_blog do
+# # Task goes here
+# end
View
2  public/javascripts/application.js
@@ -1,2 +0,0 @@
-// Place your application-specific JavaScript functions and classes here
-// This file is automatically included by javascript_include_tag :defaults
View
965 public/javascripts/controls.js
@@ -1,965 +0,0 @@
-// script.aculo.us controls.js v1.8.3, Thu Oct 08 11:23:33 +0200 2009
-
-// Copyright (c) 2005-2009 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
-// (c) 2005-2009 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
-// (c) 2005-2009 Jon Tirsen (http://www.tirsen.com)
-// Contributors:
-// Richard Livsey
-// Rahul Bhargava
-// Rob Wills
-//
-// script.aculo.us is freely distributable under the terms of an MIT-style license.
-// For details, see the script.aculo.us web site: http://script.aculo.us/
-
-// Autocompleter.Base handles all the autocompletion functionality
-// that's independent of the data source for autocompletion. This
-// includes drawing the autocompletion menu, observin