Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails3 #4

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ log/*.log
tmp/**/*
db/*.sqlite3
db/schema.rb
config/database.yml
*.gem
.dotest
tmp/restart.txt
public/cache
.idea
.specification
Gemfile.lock
*.swp
TODO
9 changes: 9 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source 'http://rubygems.org'

gem 'rails', '3.0.5'
gem 'sqlite3'

gem 'factory_girl_rails', '1.0', :group=>:test
gem 'mocha', :require=>false, :group=>:test
gem 'bcms_support'
gemspec
41 changes: 28 additions & 13 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@ 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


### 3. Modify the ApplicationHelper

module ApplicationHelper
include Cms::BlogHelper
end

### 4. Activate the observer

in config/application.rb, add:
config.active_record.observers = :blog_observer

## Creating a Blog

* To get started, go to the Content Library and choose the Blog module in the left hand menu.
Expand All @@ -52,6 +54,20 @@ under 'Blog Comments', these comments will appear in draft status. They can be P

If the blog is set to no moderation, then comments will appear immediately. This obviously increases the likelyhood of spam, but staff can use the Content Library to delete the offending comments like any other content.

## Feeds

This module includes an RSS feeds route that can handle multiple blogs. To expose the RSS autodiscovery link, you can call the feeds\_link\_tag\_for helper in your template header:

<%= feeds_link_tag_for "MyBlog" %>

Where "MyBlog" is the __name__ of the blog.

If your site has multiple blogs, you need to call the helper once for every link you intend to expose:

<%= feeds_link_tag_for "MyBlog" %>
<%= feeds_link_tag_for "MyOtherBlog" %>


## Security

This module adds some additional level of security around blogs and content that are slightly different from a vanilla BrowserCMS installation. Here's the highlights:
Expand Down Expand Up @@ -95,7 +111,6 @@ Special thanks to some amazing folks from the BrowserCMS community for their wor

## Wishlist Features

* RSS feeds - Each blog should have its own RSS feed created as part of the initial blog creation.
* 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.

41 changes: 2 additions & 39 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,44 +1,7 @@
# 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 = "[email protected]"
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"]
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
5 changes: 0 additions & 5 deletions VERSION.yml

This file was deleted.

9 changes: 1 addition & 8 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions app/controllers/feeds_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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
1 change: 0 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end
6 changes: 6 additions & 0 deletions app/helpers/cms/blog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ def _blog_path(blog, route_name, route_params)
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

end

2 changes: 2 additions & 0 deletions app/helpers/feeds_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module FeedsHelper
end
73 changes: 3 additions & 70 deletions app/models/blog.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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

Expand All @@ -25,8 +25,8 @@ def self.default_template
end

def self.posts_finder(finder, options)
if options[:tags]
finder = finder.tagged_with(options[:tags])
if options[:tag]
finder = finder.tagged_with(options[:tag])
end
if options[:exclude_tags]
finder = finder.not_tagged_with(options[:exclude_tags])
Expand Down Expand Up @@ -88,75 +88,8 @@ def potential_authors
groups.map(&:users).flatten.uniq
end


#-------------------------------------------------------------------------------------------------

def name_for_path
name.to_slug.gsub('-', '_')
end

protected
def after_create
section = Section.find_by_name(name) || (
section = Section.create!(
:name => name,
:path => "/#{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.save!
section
)

page = Page.find_by_name(name) || Page.create!(
:name => name,
:path => "/#{name_for_path}",
:section => section,
:template_file_name => "default.html.erb",
:hidden => true
)
page.create_connector(self, 'main')
create_route(page, "#{name}: Posts In Day", "/#{name_for_path}/:year/:month/:day")
create_route(page, "#{name}: Posts In Month", "/#{name_for_path}/:year/:month")
create_route(page, "#{name}: Posts In Year", "/#{name_for_path}/:year")
create_route(page, "#{name}: Posts With Tag", "/#{name_for_path}/tag/:tag")
create_route(page, "#{name}: Posts In Category", "/#{name_for_path}/category/:category")

page = Page.find_by_name(portlet_name = "#{name}: Post") || Page.create!(
:name => portlet_name,
:path => "/#{name_for_path}/post",
:section => section,
:template_file_name => "default.html.erb",
:hidden => true)
page.publish
create_route( page, portlet_name, "/#{name_for_path}/:year/:month/:day/:slug")
create_portlet(page, portlet_name, BlogPostPortlet)

reload_routes
end

def create_route(page, name, pattern)
route = page.page_routes.build(:name => name, :pattern => pattern, :code => "")
route.add_condition(:method, "get")
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.send(:create_without_callbacks)
end

def create_portlet(page, name, portlet_class)
portlet_class.create!(
:name => "#{name} Portlet",
:blog_id => self.id,
:template => portlet_class.default_template,
:connect_to_page_id => page.id,
:connect_to_container => "main",
:publish_on_save => true)
end

def reload_routes
ActionController::Routing::Routes.load!
end
end
Loading