Permalink
Browse files

Merge BrowserCMS 3.3 compatibility into master.

  • Loading branch information...
2 parents 060f9ac + ce098f1 commit baee6d25de643ee13d08789325b8e69a91536e3e @peakpg peakpg committed Jan 9, 2012
Showing 686 changed files with 4,167 additions and 101,548 deletions.
View
@@ -10,5 +10,6 @@ tmp/restart.txt
public/cache
.idea
.specification
+Gemfile.lock
*.swp
TODO
View
@@ -0,0 +1 @@
+rvm use 1.9.2@rails3.0
View
@@ -0,0 +1,8 @@
+source 'http://rubygems.org'
+
+gem 'sqlite3'
+
+gem 'factory_girl_rails', '1.0', :group=>:test
+gem 'mocha', :require=>false, :group=>:test
+gem 'bcms_support'
+gemspec
View
@@ -19,23 +19,14 @@ The blog module installs like most other BrowserCMS modules (http://guides.brows
## Set up your application to use the module
-### 1. Edit config/environment.rb
+### 1. Install the module
- config.gem "browsercms"
- config.gem "bcms_blog"
+ rails g cms:install bcms_blog
### 2. Run the following commands
- script/generate browser_cms
rake db:migrate
-
-### 3. Edit config/routes.rb
-
-Make sure the routes.rb loads the blog routes.
-
- map.routes_for_bcms_blog
- map.routes_for_browser_cms
-
+
## Creating a Blog
* To get started, go to the Content Library and choose the Blog module in the left hand menu.
View
@@ -1,45 +1,10 @@
# 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.
-require(File.join(File.dirname(__FILE__), 'config', 'boot'))
-
+require File.expand_path('../config/application', __FILE__)
require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-
-require 'tasks/rails'
-
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gemspec|
- gemspec.name = "bcms_blog"
- gemspec.rubyforge_project = "browsercms"
- gemspec.summary = "The Blog Module for BrowserCMS"
- gemspec.email = "github@browsermedia.com"
- gemspec.homepage = "http://browsercms.org"
- gemspec.description = "The Blog Module for BrowserCMS"
- gemspec.authors = ["BrowserMedia"]
- gemspec.files = []
- gemspec.files += Dir["app/**/*"]
- gemspec.files += Dir["doc/**/*"]
- gemspec.files += Dir["db/migrate/[0-9]*.rb"].reject {|f| f =~ /_browsercms|_load_seed/ }
- gemspec.files += Dir["lib/bcms_blog.rb"]
- gemspec.files += Dir["lib/bcms_blog/*"]
- gemspec.files += Dir["rails/init.rb"]
- gemspec.add_development_dependency 'bcms_support'
- end
-rescue LoadError
- puts "Jeweler not available. Install it with: sudo gem install jeweler"
-end
-# These are new tasks
-begin
- require 'rake/contrib/sshpublisher'
- namespace :rubyforge do
- desc "Release gem and RDoc documentation to RubyForge"
- task :release => ["rubyforge:release:gem"]
- end
-rescue LoadError
- puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
-end
+BcmsBlog::Application.load_tasks
+require 'bundler'
+Bundler::GemHelper.install_tasks
View
@@ -1,5 +0,0 @@
----
-:minor: 1
-:build:
-:patch: 1
-:major: 1
@@ -1,10 +1,3 @@
-# Filters added to this controller apply to all controllers in the application.
-# Likewise, all the methods added will be available for all controllers.
-
class ApplicationController < ActionController::Base
- helper :all # include all helpers, all the time
- protect_from_forgery # See ActionController::RequestForgeryProtection for details
-
- # Scrub sensitive parameters from your log
- # filter_parameter_logging :password
+ protect_from_forgery
end
@@ -1,3 +1,2 @@
-# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end
@@ -13,5 +13,8 @@ def feeds_link_tag_for(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
@@ -8,7 +8,7 @@ class Blog < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name
- named_scope :editable_by, lambda { |user|
+ scope :editable_by, lambda { |user|
if user.able_to?(:administrate)
{ }
else
@@ -91,4 +91,5 @@ def potential_authors
def name_for_path
name.to_slug.gsub('-', '_')
end
+
end
@@ -4,7 +4,9 @@ class BlogComment < ActiveRecord::Base
validates_presence_of :post_id, :author, :body
- def before_create
+ before_create :publish_if_comments_are_enabled
+
+ def publish_if_comments_are_enabled
self.published = true unless post.blog.moderate_comments?
end
@@ -5,15 +5,21 @@ def after_create(blog)
create_section_pages_and_routes
end
- def before_update(blog)
- update_section_pages_and_route(blog)
+ def after_save(blog)
+ if blog.persisted?
+ blog.publish
+ end
end
- def after_update(blog)
- blog.publish
+ # 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
@@ -37,9 +43,7 @@ def create_blog_section
:path => "/#{@blog.name_for_path}",
:parent_id => 1
)
- @section.groups << Group.find_by_code("cms-admin")
- @section.groups << Group.find_by_code("guest")
- @section.groups << Group.find_by_code("content-editor")
+ @section.allow_groups = :all
@section.save!
@section
)
@@ -106,12 +110,12 @@ def update_section_pages_and_route(blog)
end
def reload_routes
- ActionController::Routing::Routes.load!
+ PageRoute.reload_routes
end
def create_route(page, name, pattern)
route = page.page_routes.build(:name => name, :pattern => pattern, :code => "")
- route.send(:create_without_callbacks)
+ 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")
@@ -26,13 +26,13 @@ def set_attachment_section
before_validation :set_slug
validates_presence_of :name, :slug, :blog_id, :author_id
- named_scope :published_between, lambda { |start, finish|
+ scope :published_between, lambda { |start, finish|
{ :conditions => [
"blog_posts.published_at >= ? AND blog_posts.published_at < ?",
start, finish ] }
}
- named_scope :not_tagged_with, lambda { |tag| {
+ scope :not_tagged_with, lambda { |tag| {
:conditions => [
"blog_posts.id not in (
SELECT taggings.taggable_id FROM taggings
@@ -1,6 +1,6 @@
class BlogPostPortlet < Portlet
- #render_inline false
- #enable_template_editor false
+
+ enable_template_editor false
def render
scope = Blog.find(self.blog_id).posts
@@ -16,6 +16,8 @@ def render
raise BlogPost::INCORRECT_PARAMETERS
end
+ make_page_title_use_blog_post_name(@blog_post)
+
pmap = flash[instance_name] || params
pmap[:blog_comment] ||= {}
@@ -24,6 +26,8 @@ def render
end
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])
if blog_comment.valid? && blog_comment.save
@@ -34,5 +38,21 @@ def create_comment
url_for_failure
end
end
+
+ private
+
+ def work_around_cms_3_3_bug_where_current_user_is_not_correctly_set
+ User.current = current_user
+ end
+
+ # This is a work around for a bug in bcms 3.3 where the Cms::PageHeler#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.
+ # Instead, we just temporarily set the name of the page itself.
+ def make_page_title_use_blog_post_name(post)
+ page = @controller.current_page
+ page.name = post.name
+ end
end
@@ -1,5 +1,8 @@
class BlogPostsPortlet < Portlet
- def after_initialize
+
+ after_initialize :build_permalink_code
+
+ def build_permalink_code
self.render_blog_post_code ||= 'truncate(blog_post.name, 30)'
end
@@ -1,2 +1,2 @@
<%= link_to h(@content_block.post.name), cms_blog_post_path(@content_block.post) %>
-<p><%=h @content_block.body %></p>
+<p><%=h @content_block.body.html_safe %></p>
@@ -20,7 +20,7 @@
<div class="body">
<% if showing_individual_post or blog_post.summary.blank? %>
- <%= blog_post.body %>
+ <%= blog_post.body.html_safe %>
<% else %>
<%= blog_post.summary %>
<p class="read_more">
@@ -38,7 +38,7 @@
<% if blog_post.tags.any? %>
Tags:
<span class="tags">
- <%= blog_post.tags.map{|t| link_to(h(t.name), _blog_path(blog_post.blog, 'posts_with_tag', :tag => t.name)) }.join(", ") %>
+ <%= blog_post.tags.map{|t| link_to(h(t.name), _blog_path(blog_post.blog, 'posts_with_tag', :tag => t.name)) }.join(", ").html_safe %>
</span>
<strong>|</strong>
<% end %>
@@ -1,10 +1,15 @@
+<%
+ logger.warn "Page title is: #{page_title}"
+ page_title "SOMETHING ELSE"
+ logger.warn "Now it's #{page_title}"
+%>
<% page_title @blog_post.name %>
<%= render :partial => "partials/blog_post", :object => @blog_post %>
<div class="blog_comment_form">
- <% form_for @blog_comment, :url => cms_handler_path(@portlet, "create_comment") do |f| %>
+ <%= form_for @blog_comment, :url => new_comment_path(@portlet) do |f| %>
<%= f.hidden_field :post_id %>
- <%= f.error_messages %>
+ <%= f.cms_error_messages %>
<div class="fields text_fields">
<%= f.label :author, 'Name *' %>
<%= f.text_field :author %>
Oops, something went wrong.

0 comments on commit baee6d2

Please sign in to comment.