bcms_blog 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -0
- data/app/controllers/cms/blog_comments_controller.rb +3 -0
- data/app/controllers/cms/blog_posts_controller.rb +2 -0
- data/app/controllers/cms/blogs_controller.rb +2 -0
- data/app/models/blog.rb +38 -0
- data/app/models/blog_comment.rb +26 -0
- data/app/models/blog_post.rb +69 -0
- data/app/portlets/blog_post_portlet.rb +24 -0
- data/app/views/cms/blog_comments/_form.html.erb +5 -0
- data/app/views/cms/blog_comments/render.html.erb +2 -0
- data/app/views/cms/blog_posts/_form.html.erb +6 -0
- data/app/views/cms/blog_posts/render.html.erb +5 -0
- data/app/views/cms/blogs/_form.html.erb +2 -0
- data/app/views/cms/blogs/render.html.erb +3 -0
- data/app/views/portlets/blog_post/_blog_post.html.erb +29 -0
- data/app/views/portlets/blog_post/_form.html.erb +2 -0
- data/app/views/portlets/blog_post/render.html.erb +36 -0
- data/db/migrate/20090415000000_create_blogs.rb +32 -0
- data/db/migrate/20090415000001_create_blog_posts.rb +50 -0
- data/db/migrate/20090415000002_create_blog_comments.rb +18 -0
- data/lib/bcms_blog/routes.rb +9 -0
- data/lib/bcms_blog.rb +1 -0
- data/rails/init.rb +3 -0
- data/test/factories.rb +3 -0
- data/test/functional/blog_post_test.rb +35 -0
- data/test/functional/blog_test.rb +45 -0
- data/test/performance/browsing_test.rb +9 -0
- data/test/test_helper.rb +137 -0
- data/test/test_logging.rb +64 -0
- metadata +80 -0
data/README.markdown
ADDED
data/app/models/blog.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
class Blog < ActiveRecord::Base
|
2
|
+
acts_as_content_block
|
3
|
+
has_many :posts, :class_name => "BlogPost"
|
4
|
+
|
5
|
+
validates_presence_of :name
|
6
|
+
validates_uniqueness_of :name
|
7
|
+
|
8
|
+
def self.default_template
|
9
|
+
template_file = ActionController::Base.view_paths.map do |vp|
|
10
|
+
path = vp.to_s.first == "/" ? vp.to_s : File.join(Rails.root, vp.to_s)
|
11
|
+
File.join(path, "cms/blogs/render.html.erb")
|
12
|
+
end.detect{|f| File.exists? f }
|
13
|
+
template_file ? open(template_file){|f| f.read } : ""
|
14
|
+
end
|
15
|
+
|
16
|
+
def render
|
17
|
+
@blog = self
|
18
|
+
finder = @blog.posts.published
|
19
|
+
if params[:tag]
|
20
|
+
finder = finder.tagged_with(params[:tag])
|
21
|
+
end
|
22
|
+
if params[:category]
|
23
|
+
@category_type = CategoryType.named("Blog Post").first
|
24
|
+
@category = @category_type.categories.named(params[:category]).first
|
25
|
+
finder = finder.in_category(@category)
|
26
|
+
end
|
27
|
+
@blog_posts = finder.all(:limit => 15, :order => "published_at desc")
|
28
|
+
end
|
29
|
+
|
30
|
+
def inline_options
|
31
|
+
{:inline => self.template}
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.default_order
|
35
|
+
"name"
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class BlogComment < ActiveRecord::Base
|
2
|
+
acts_as_content_block :is_searachable => "body"
|
3
|
+
belongs_to :post, :class_name => "BlogPost", :counter_cache => "comments_count"
|
4
|
+
|
5
|
+
def self.default_order
|
6
|
+
"blog_comments.created_at desc"
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.default_order_for_search
|
10
|
+
default_order
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.columns_for_index
|
14
|
+
[ {:label => "Comment", :method => :name, :order => "blog_comments.body" },
|
15
|
+
{:label => "Created At", :method => :formatted_created_at, :order => "blog_comments.created_at"} ]
|
16
|
+
end
|
17
|
+
|
18
|
+
def name
|
19
|
+
body ? body[0..50] : ""
|
20
|
+
end
|
21
|
+
|
22
|
+
def formatted_created_at
|
23
|
+
created_at.to_s(:date)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class BlogPost < ActiveRecord::Base
|
2
|
+
acts_as_content_block :taggable => true
|
3
|
+
|
4
|
+
before_save :set_published_at
|
5
|
+
|
6
|
+
belongs_to :blog
|
7
|
+
belongs_to_category
|
8
|
+
belongs_to :author, :class_name => "User"
|
9
|
+
has_many :comments, :class_name => "BlogComment", :foreign_key => "post_id"
|
10
|
+
|
11
|
+
before_validation :set_slug
|
12
|
+
validates_presence_of :name, :slug
|
13
|
+
|
14
|
+
named_scope :published_on, lambda {|date|
|
15
|
+
d = if date.kind_of?(Hash)
|
16
|
+
Date.new(date[:year].to_i, date[:month].to_i, date[:day].to_i)
|
17
|
+
else
|
18
|
+
date
|
19
|
+
end
|
20
|
+
|
21
|
+
{:conditions => [
|
22
|
+
"blog_posts.published_at >= ? AND blog_posts.published_at < ?",
|
23
|
+
d.beginning_of_day,
|
24
|
+
(d.beginning_of_day + 1.day)
|
25
|
+
]}
|
26
|
+
}
|
27
|
+
|
28
|
+
named_scope :with_slug, lambda{|slug| {:conditions => ["blog_posts.slug = ?",slug]}}
|
29
|
+
|
30
|
+
def set_published_at
|
31
|
+
if !published_at && publish_on_save
|
32
|
+
self.published_at = Time.now
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.default_order
|
37
|
+
"created_at desc"
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.columns_for_index
|
41
|
+
[ {:label => "Name", :method => :name, :order => "name" },
|
42
|
+
{:label => "Published", :method => :published_label, :order => "published" } ]
|
43
|
+
end
|
44
|
+
|
45
|
+
def published_label
|
46
|
+
published_at ? published_at.to_s(:date) : nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_slug
|
50
|
+
self.slug = name.to_slug
|
51
|
+
end
|
52
|
+
|
53
|
+
def route_params
|
54
|
+
{:year => year, :month => month, :day => day, :slug => slug}
|
55
|
+
end
|
56
|
+
|
57
|
+
def year
|
58
|
+
published_at.strftime("%Y") unless published_at.blank?
|
59
|
+
end
|
60
|
+
|
61
|
+
def month
|
62
|
+
published_at.strftime("%m") unless published_at.blank?
|
63
|
+
end
|
64
|
+
|
65
|
+
def day
|
66
|
+
published_at.strftime("%d") unless published_at.blank?
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class BlogPostPortlet < Portlet
|
2
|
+
|
3
|
+
def render
|
4
|
+
# @blog_post should already be set by the page route
|
5
|
+
if !@blog_post && params[:blog_post_id]
|
6
|
+
@blog_post = BlogPost.find(params[:blog_post_id])
|
7
|
+
end
|
8
|
+
pmap = flash[instance_name] || params
|
9
|
+
@blog_comment = @blog_post.comments.build pmap[:blog_comment]
|
10
|
+
@blog_comment.errors.add_from_hash flash["#{instance_name}_errors"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_comment
|
14
|
+
blog_comment = BlogComment.new(params[:blog_comment])
|
15
|
+
if blog_comment.save
|
16
|
+
url_for_success
|
17
|
+
else
|
18
|
+
store_params_in_flash
|
19
|
+
store_errors_in_flash(blog_comment.errors)
|
20
|
+
url_for_failure
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<%= f.cms_drop_down :blog_id, Blog.all.map{|b| [b.name, b.id]} %>
|
2
|
+
<%= f.cms_drop_down :category_id, categories_for('Blog Post').map{|c| [c.path, c.id]}, :include_blank => true %>
|
3
|
+
<%= f.cms_text_field :name %>
|
4
|
+
<%= f.cms_tag_list %>
|
5
|
+
<%= f.cms_text_area :summary, :style => "height: 200px" %>
|
6
|
+
<%= f.cms_text_editor :body %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<div id="blog_post_<%= blog_post.id %>" class="blog_post">
|
2
|
+
<h2>
|
3
|
+
<% if blog_post.published_at %>
|
4
|
+
<%= link_to h(blog_post.name), blog_post_path(blog_post.route_params) %>
|
5
|
+
<% else %>
|
6
|
+
<%=h blog_post.name %>
|
7
|
+
<% end %>
|
8
|
+
</h2>
|
9
|
+
<% if blog_post.published_at %>
|
10
|
+
<p class="date"><%= blog_post.published_at.to_s(:long) %></p>
|
11
|
+
<% end %>
|
12
|
+
<p class="body">
|
13
|
+
<%= blog_post.body %>
|
14
|
+
</p>
|
15
|
+
<p class="meta">
|
16
|
+
<% unless blog_post.category_id.blank? %>
|
17
|
+
Posted in <%= link_to h(blog_post.category_name), blog_posts_in_category_path(:category => blog_post.category_name) %>
|
18
|
+
<strong>|</strong>
|
19
|
+
<% end %>
|
20
|
+
Tags
|
21
|
+
<span class="tags">
|
22
|
+
<%= blog_post.tags.map{|t| link_to(h(t.name), blog_posts_with_tag_path(:tag => t.name)) }.join(", ") %>
|
23
|
+
</span>
|
24
|
+
<strong>|</strong>
|
25
|
+
<% if blog_post.published_at %>
|
26
|
+
<%= link_to h(pluralize(blog_post.comments_count, "Comment")), "#{blog_post_path(blog_post.route_params)}#comments" %>
|
27
|
+
<% end %>
|
28
|
+
</p>
|
29
|
+
</div>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<% if @blog_post -%>
|
2
|
+
<% page_title @blog_post.name %>
|
3
|
+
<%= render :partial => "portlets/blog_post/blog_post", :object => @blog_post %>
|
4
|
+
<h2>Comments</h2>
|
5
|
+
<% for comment in @blog_post.comments %>
|
6
|
+
<p><%=h comment.body %></p>
|
7
|
+
<% end %>
|
8
|
+
<div class="blog_comment_form">
|
9
|
+
<% form_for @blog_comment, :url => cms_handler_path(@portlet, "create_comment") do |f| %>
|
10
|
+
<%= f.hidden_field :post_id %>
|
11
|
+
<%= f.error_messages %>
|
12
|
+
<p>
|
13
|
+
<%= f.label :author %>
|
14
|
+
<%= f.text_field :author %>
|
15
|
+
</p>
|
16
|
+
<p>
|
17
|
+
<%= f.label :email %>
|
18
|
+
<%= f.text_field :email %>
|
19
|
+
</p>
|
20
|
+
<p>
|
21
|
+
<%= f.label :url %>
|
22
|
+
<%= f.text_field :url %>
|
23
|
+
</p>
|
24
|
+
<p>
|
25
|
+
<%= f.label :body %>
|
26
|
+
<%= f.text_area :body, :size => "50x3" %>
|
27
|
+
</p>
|
28
|
+
<p>
|
29
|
+
<%= submit_tag "Submit" %>
|
30
|
+
</p>
|
31
|
+
<% end %>
|
32
|
+
</div>
|
33
|
+
<% else -%>
|
34
|
+
<b>Missing required parameter</b><br/>
|
35
|
+
This portlet expects a request parameter 'blog_post_id'. Be sure the calling page provides it.
|
36
|
+
<% end -%>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class CreateBlogs < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_versioned_table :blogs do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :format
|
6
|
+
t.text :template
|
7
|
+
end
|
8
|
+
ContentType.create!(:name => "Blog", :group_name => "Blog")
|
9
|
+
|
10
|
+
blog_page = Page.first(:conditions => {:path => "/"})
|
11
|
+
|
12
|
+
Blog.create!(
|
13
|
+
:name => "My Blog",
|
14
|
+
:template => Blog.default_template,
|
15
|
+
:connect_to_page_id => blog_page.id,
|
16
|
+
:connect_to_container => "main",
|
17
|
+
:publish_on_save => true)
|
18
|
+
|
19
|
+
blog_page.page_routes.create(
|
20
|
+
:name => "Blog Posts With Tag",
|
21
|
+
:pattern => "/articles/tag/:tag")
|
22
|
+
|
23
|
+
blog_page.page_routes.create(
|
24
|
+
:name => "Blog Posts In Category",
|
25
|
+
:pattern => "/articles/category/:category")
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.down
|
29
|
+
ContentType.delete_all(['name = ?', 'Blog'])
|
30
|
+
drop_table :blogs
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class CreateBlogPosts < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_versioned_table :blog_posts do |t|
|
4
|
+
t.integer :blog_id
|
5
|
+
t.integer :author_id
|
6
|
+
t.integer :category_id
|
7
|
+
t.string :name
|
8
|
+
t.string :slug
|
9
|
+
t.text :summary
|
10
|
+
t.text :body, :size => (64.kilobytes + 1)
|
11
|
+
t.integer :comments_count
|
12
|
+
t.datetime :published_at
|
13
|
+
end
|
14
|
+
CategoryType.create!(:name => "Blog Post")
|
15
|
+
ContentType.create!(:name => "BlogPost", :group_name => "Blog")
|
16
|
+
|
17
|
+
blog_post_page = Page.create!(
|
18
|
+
:name => "Blog Post",
|
19
|
+
:path => "/blog/post",
|
20
|
+
:section => Section.root.first,
|
21
|
+
:template_file_name => "default.html.erb")
|
22
|
+
|
23
|
+
BlogPostPortlet.create!(
|
24
|
+
:name => "Blog Post Portlet",
|
25
|
+
:template => BlogPostPortlet.default_template,
|
26
|
+
:connect_to_page_id => blog_post_page.id,
|
27
|
+
:connect_to_container => "main",
|
28
|
+
:publish_on_save => true)
|
29
|
+
|
30
|
+
route = blog_post_page.page_routes.build(
|
31
|
+
:name => "Blog Post",
|
32
|
+
:pattern => "/articles/:year/:month/:day/:slug",
|
33
|
+
:code => "@blog_post = BlogPost.published_on(params).with_slug(params[:slug]).first")
|
34
|
+
route.add_condition(:method, "get")
|
35
|
+
route.add_requirement(:year, '\d{4,}')
|
36
|
+
route.add_requirement(:month, '\d{2,}')
|
37
|
+
route.add_requirement(:day, '\d{2,}')
|
38
|
+
route.save!
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.down
|
45
|
+
ContentType.delete_all(['name = ?', 'BlogPost'])
|
46
|
+
CategoryType.all(:conditions => ['name = ?', 'Blog Post']).each(&:destroy)
|
47
|
+
drop_table :blog_post_versions
|
48
|
+
drop_table :blog_posts
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateBlogComments < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_versioned_table :blog_comments do |t|
|
4
|
+
t.integer :post_id
|
5
|
+
t.string :author
|
6
|
+
t.string :email
|
7
|
+
t.string :url
|
8
|
+
t.string :ip
|
9
|
+
t.text :body
|
10
|
+
end
|
11
|
+
ContentType.create!(:name => "BlogComment", :group_name => "Blog")
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
ContentType.delete_all(['name = ?', 'BlogComment'])
|
16
|
+
drop_table :blog_comments
|
17
|
+
end
|
18
|
+
end
|
data/lib/bcms_blog.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bcms_blog/routes'
|
data/rails/init.rb
ADDED
data/test/factories.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class BlogPostTest < ActionController::TestCase
|
4
|
+
tests Cms::ContentController
|
5
|
+
|
6
|
+
def setup
|
7
|
+
create_baseline_data
|
8
|
+
@blog_post_portlet = BlogPostPortlet.create!(:name => "Blog Post Portlet",
|
9
|
+
:template => BlogPostPortlet.default_template,
|
10
|
+
:connect_to_page_id => @blog_post_page.id,
|
11
|
+
:connect_to_container => "main",
|
12
|
+
:publish_on_save => true)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_show_post
|
16
|
+
get :show_page_route, :_page_route_id => @blog_post_route.id.to_s,
|
17
|
+
:year => @first_post.year,
|
18
|
+
:month => @first_post.month,
|
19
|
+
:day => @first_post.day,
|
20
|
+
:slug => @first_post.slug
|
21
|
+
#log @response.body
|
22
|
+
assert_response :success
|
23
|
+
assert_select "title", @first_post.name
|
24
|
+
assert_select ".blog_post", 1
|
25
|
+
|
26
|
+
assert_select "#blog_post_#{@first_post.id}" do
|
27
|
+
assert_select "h2 a", "First Post"
|
28
|
+
assert_select "p.body", "Yadda Yadda Yadda"
|
29
|
+
assert_select "p.meta a", "General"
|
30
|
+
assert_select "p.meta a", "0 Comments"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class BlogTest < ActionController::TestCase
|
4
|
+
tests Cms::ContentController
|
5
|
+
|
6
|
+
def setup
|
7
|
+
create_baseline_data
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_list_of_blog_posts
|
11
|
+
get :show, :paths => ["/"]
|
12
|
+
#log @response.body
|
13
|
+
assert_response :success
|
14
|
+
assert_select ".blog_post", 5
|
15
|
+
|
16
|
+
assert_select "#blog_post_#{@first_post.id}" do
|
17
|
+
assert_select "h2 a", "First Post"
|
18
|
+
assert_select "p.body", "Yadda Yadda Yadda"
|
19
|
+
assert_select "p.meta a", "General"
|
20
|
+
assert_select "p.meta a", "0 Comments"
|
21
|
+
end
|
22
|
+
|
23
|
+
assert_select "#blog_post_#{@foo_post_1.id}" do
|
24
|
+
assert_select "h2 a", "Foo #1"
|
25
|
+
assert_select "p.body", "Foo 1 Foo 1 Foo 1"
|
26
|
+
assert_select "p.meta .tags a", "foo"
|
27
|
+
assert_select "p.meta .tags a", "stuff"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_list_of_tagged_blog_posts
|
32
|
+
get :show, :paths => ["/"], :category => "General"
|
33
|
+
#log @response.body
|
34
|
+
assert_response :success
|
35
|
+
assert_select ".blog_post", 3
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_list_of_categorized_blog_posts
|
39
|
+
get :show, :paths => ["/"], :tag => "foo"
|
40
|
+
#log @response.body
|
41
|
+
assert_response :success
|
42
|
+
assert_select ".blog_post", 2
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
ENV['BACKTRACE'] = "YES PLEASE"
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
4
|
+
require 'test_help'
|
5
|
+
|
6
|
+
class ActiveSupport::TestCase
|
7
|
+
require File.dirname(__FILE__) + '/test_logging'
|
8
|
+
include TestLogging
|
9
|
+
# Transactional fixtures accelerate your tests by wrapping each test method
|
10
|
+
# in a transaction that's rolled back on completion. This ensures that the
|
11
|
+
# test database remains unchanged so your fixtures don't have to be reloaded
|
12
|
+
# between every test method. Fewer database queries means faster tests.
|
13
|
+
#
|
14
|
+
# Read Mike Clark's excellent walkthrough at
|
15
|
+
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
16
|
+
#
|
17
|
+
# Every Active Record database supports transactions except MyISAM tables
|
18
|
+
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
19
|
+
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
20
|
+
# is recommended.
|
21
|
+
#
|
22
|
+
# The only drawback to using transactional fixtures is when you actually
|
23
|
+
# need to test transactions. Since your test is bracketed by a transaction,
|
24
|
+
# any transactions started in your code will be automatically rolled back.
|
25
|
+
self.use_transactional_fixtures = true
|
26
|
+
|
27
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
28
|
+
# would need people(:david). If you don't want to migrate your existing
|
29
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
30
|
+
# instantiated fixtures translates to a database query per test method),
|
31
|
+
# then set this back to true.
|
32
|
+
self.use_instantiated_fixtures = false
|
33
|
+
|
34
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
35
|
+
#
|
36
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
37
|
+
# -- they do not yet inherit this setting
|
38
|
+
fixtures :all
|
39
|
+
|
40
|
+
# Add more helper methods to be used by all tests here...
|
41
|
+
def create_baseline_data
|
42
|
+
@section = Section.create!(:name => "My Site", :path => "/")
|
43
|
+
Group.create!(:name => "Guest", :code => "guest", :sections => [@section])
|
44
|
+
@page_template = PageTemplate.create!(:name => "test", :format => "html", :handler => "erb", :body => %q{<html>
|
45
|
+
<head>
|
46
|
+
<title>
|
47
|
+
<%= page_title %>
|
48
|
+
</title>
|
49
|
+
<%= yield :html_head %>
|
50
|
+
</head>
|
51
|
+
<body>
|
52
|
+
<%= cms_toolbar %>
|
53
|
+
<%= container :main %>
|
54
|
+
</body>
|
55
|
+
</html>})
|
56
|
+
|
57
|
+
@blog_page = Page.create!(:name => "My Blog Page", :section => @section, :path => "/", :template_file_name => "test.html.erb")
|
58
|
+
@blog_post_page = Page.create!(:name => "Blog Post Page", :section => @section, :path => "/blog/post", :template_file_name => "test.html.erb")
|
59
|
+
|
60
|
+
@blog_posts_with_tag_route = @blog_page.page_routes.create(
|
61
|
+
:name => "Blog Posts With Tag",
|
62
|
+
:pattern => "/articles/tag/:tag")
|
63
|
+
|
64
|
+
@blog_posts_in_category_route = @blog_page.page_routes.create(
|
65
|
+
:name => "Blog Posts In Category",
|
66
|
+
:pattern => "/articles/category/:category")
|
67
|
+
|
68
|
+
@blog_post_route = @blog_post_page.page_routes.build(
|
69
|
+
:name => "Blog Post",
|
70
|
+
:pattern => "/articles/:year/:month/:day/:slug",
|
71
|
+
:code => "@blog_post = BlogPost.published_on(params).with_slug(params[:slug]).first")
|
72
|
+
@blog_post_route.add_condition(:method, "get")
|
73
|
+
@blog_post_route.add_requirement(:year, '\d{4,}')
|
74
|
+
@blog_post_route.add_requirement(:month, '\d{2,}')
|
75
|
+
@blog_post_route.add_requirement(:day, '\d{2,}')
|
76
|
+
@blog_post_route.save!
|
77
|
+
|
78
|
+
@blog_page.publish!
|
79
|
+
@blog_post_page.publish!
|
80
|
+
|
81
|
+
@category_type = CategoryType.create!(:name => "Blog Post")
|
82
|
+
@stuff = Category.create!(:name => "Stuff", :category_type => @category_type)
|
83
|
+
@general = Category.create!(:name => "General", :category_type => @category_type)
|
84
|
+
|
85
|
+
@blog = Blog.create!(
|
86
|
+
:name => "My Blog",
|
87
|
+
:template => Blog.default_template,
|
88
|
+
:connect_to_page_id => @blog_page.id,
|
89
|
+
:connect_to_container => "main",
|
90
|
+
:publish_on_save => true)
|
91
|
+
|
92
|
+
@first_post = BlogPost.create!(
|
93
|
+
:name => "First Post",
|
94
|
+
:blog => @blog,
|
95
|
+
:category => @general,
|
96
|
+
:summary => "This is the first post",
|
97
|
+
:body => "Yadda Yadda Yadda",
|
98
|
+
:publish_on_save => true)
|
99
|
+
|
100
|
+
@foo_post_1 = BlogPost.create!(
|
101
|
+
:name => "Foo #1",
|
102
|
+
:blog => @blog,
|
103
|
+
:category => @stuff,
|
104
|
+
:tag_list => "foo stuff",
|
105
|
+
:summary => "This is the first foo post",
|
106
|
+
:body => "Foo 1 Foo 1 Foo 1",
|
107
|
+
:publish_on_save => true)
|
108
|
+
|
109
|
+
@foo_post_2 = BlogPost.create!(
|
110
|
+
:name => "Foo #2",
|
111
|
+
:blog => @blog,
|
112
|
+
:category => @general,
|
113
|
+
:tag_list => "foo",
|
114
|
+
:summary => "This is the second foo post",
|
115
|
+
:body => "Foo 2 Foo 2 Foo 2",
|
116
|
+
:publish_on_save => true)
|
117
|
+
|
118
|
+
@bar_post_1 = BlogPost.create!(
|
119
|
+
:name => "Bar #1",
|
120
|
+
:blog => @blog,
|
121
|
+
:category => @stuff,
|
122
|
+
:tag_list => "bar things",
|
123
|
+
:summary => "This is the first bar post",
|
124
|
+
:body => "Bar 1 Bar 1 Bar 1",
|
125
|
+
:publish_on_save => true)
|
126
|
+
|
127
|
+
@bar_post_2 = BlogPost.create!(
|
128
|
+
:name => "Bar #2",
|
129
|
+
:blog => @blog,
|
130
|
+
:category => @general,
|
131
|
+
:tag_list => "bar",
|
132
|
+
:summary => "This is the second bar post",
|
133
|
+
:body => "Bar 2 Bar 2 Bar 2",
|
134
|
+
:publish_on_save => true)
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module TestLogging
|
2
|
+
def log(msg)
|
3
|
+
Rails.logger.info(msg)
|
4
|
+
end
|
5
|
+
|
6
|
+
def log_array(obj, *columns)
|
7
|
+
lengths = columns.map{|m| m.to_s.length }
|
8
|
+
|
9
|
+
obj.each do |r|
|
10
|
+
columns.each_with_index do |m, i|
|
11
|
+
v = r.send(m)
|
12
|
+
if v.to_s.length > lengths[i]
|
13
|
+
lengths[i] = v.to_s.length
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
str = " "
|
19
|
+
columns.each_with_index do |m, i|
|
20
|
+
str << "%#{lengths[i]}s" % m
|
21
|
+
str << " "
|
22
|
+
end
|
23
|
+
str << "\n "
|
24
|
+
|
25
|
+
columns.each_with_index do |m, i|
|
26
|
+
str << ("-"*lengths[i])
|
27
|
+
str << " "
|
28
|
+
end
|
29
|
+
str << "\n "
|
30
|
+
|
31
|
+
obj.each do |r|
|
32
|
+
columns.each_with_index do |m, i|
|
33
|
+
str << "%#{lengths[i]}s" % r.send(m)
|
34
|
+
str << " "
|
35
|
+
end
|
36
|
+
str << "\n "
|
37
|
+
end
|
38
|
+
|
39
|
+
log str
|
40
|
+
end
|
41
|
+
|
42
|
+
def log_table(cls, options={})
|
43
|
+
if options[:include_columns]
|
44
|
+
columns = options[:include_columns]
|
45
|
+
elsif options[:exclude_columns]
|
46
|
+
columns = cls.column_names - options[:exclude_columns].map(&:to_s)
|
47
|
+
else
|
48
|
+
columns = cls.column_names
|
49
|
+
end
|
50
|
+
log_array (cls.uses_soft_delete? ? cls.find_with_deleted(:all) : cls.all), *columns
|
51
|
+
end
|
52
|
+
|
53
|
+
def log_table_with(cls, *columns)
|
54
|
+
log_table(cls, :include_columns => columns)
|
55
|
+
end
|
56
|
+
|
57
|
+
def log_table_without(cls, *columns)
|
58
|
+
log_table(cls, :exclude_columns => columns)
|
59
|
+
end
|
60
|
+
|
61
|
+
def log_table_without_stamps(cls, *columns)
|
62
|
+
log_table(cls, :exclude_columns => %w[created_at updated_at created_by_id updated_by_id] + columns)
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bcms_blog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- BrowserMedia
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-02 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: The Blog Module for BrowserCMS
|
17
|
+
email: github@browsermedia.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.markdown
|
24
|
+
files:
|
25
|
+
- app/controllers/cms/blog_comments_controller.rb
|
26
|
+
- app/controllers/cms/blog_posts_controller.rb
|
27
|
+
- app/controllers/cms/blogs_controller.rb
|
28
|
+
- app/models/blog.rb
|
29
|
+
- app/models/blog_comment.rb
|
30
|
+
- app/models/blog_post.rb
|
31
|
+
- app/portlets/blog_post_portlet.rb
|
32
|
+
- app/views/cms/blog_comments/_form.html.erb
|
33
|
+
- app/views/cms/blog_comments/render.html.erb
|
34
|
+
- app/views/cms/blog_posts/_form.html.erb
|
35
|
+
- app/views/cms/blog_posts/render.html.erb
|
36
|
+
- app/views/cms/blogs/_form.html.erb
|
37
|
+
- app/views/cms/blogs/render.html.erb
|
38
|
+
- app/views/portlets/blog_post/_blog_post.html.erb
|
39
|
+
- app/views/portlets/blog_post/_form.html.erb
|
40
|
+
- app/views/portlets/blog_post/render.html.erb
|
41
|
+
- db/migrate/20090415000000_create_blogs.rb
|
42
|
+
- db/migrate/20090415000001_create_blog_posts.rb
|
43
|
+
- db/migrate/20090415000002_create_blog_comments.rb
|
44
|
+
- lib/bcms_blog.rb
|
45
|
+
- lib/bcms_blog/routes.rb
|
46
|
+
- rails/init.rb
|
47
|
+
- README.markdown
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://browsercms.org
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options:
|
52
|
+
- --charset=UTF-8
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project: browsercms
|
70
|
+
rubygems_version: 1.3.1
|
71
|
+
signing_key:
|
72
|
+
specification_version: 2
|
73
|
+
summary: The Blog Module for BrowserCMS
|
74
|
+
test_files:
|
75
|
+
- test/factories.rb
|
76
|
+
- test/functional/blog_post_test.rb
|
77
|
+
- test/functional/blog_test.rb
|
78
|
+
- test/performance/browsing_test.rb
|
79
|
+
- test/test_helper.rb
|
80
|
+
- test/test_logging.rb
|