tamed_beast 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/README +12 -0
- data/Rakefile +2 -0
- data/app/controllers/forums_controller.rb +60 -0
- data/app/controllers/posts_controller.rb +98 -0
- data/app/controllers/topics_controller.rb +94 -0
- data/app/models/forum.rb +23 -0
- data/app/models/post.rb +26 -0
- data/app/models/topic.rb +97 -0
- data/app/views/forums/_form.html.erb +21 -0
- data/app/views/forums/edit.html.erb +12 -0
- data/app/views/forums/index.html.erb +63 -0
- data/app/views/forums/new.html.erb +10 -0
- data/app/views/forums/show.html.erb +81 -0
- data/app/views/posts/_edit.html.erb +38 -0
- data/app/views/posts/edit.html.erb +14 -0
- data/app/views/posts/index.html.erb +1 -0
- data/app/views/topics/_form.html.erb +17 -0
- data/app/views/topics/edit.html.erb +10 -0
- data/app/views/topics/index.html.erb +2 -0
- data/app/views/topics/new.html.erb +18 -0
- data/app/views/topics/show.html.erb +175 -0
- data/config/conf.rb +0 -0
- data/lib/generators/tamed_beast/install_generator.rb +56 -0
- data/lib/generators/tamed_beast/migration_generator.rb +26 -0
- data/lib/generators/tamed_beast/templates/migration.rb +57 -0
- data/lib/generators/tamed_beast/templates/routes.rb +9 -0
- data/lib/tamed_beast.rb +7 -0
- data/lib/tamed_beast/application_helper.rb +18 -0
- data/lib/tamed_beast/auth.rb +24 -0
- data/lib/tamed_beast/engine.rb +7 -0
- data/lib/tamed_beast/version.rb +3 -0
- data/tamed_beast.gemspec +23 -0
- data/test/fixtures/forums.yml +19 -0
- data/test/fixtures/posts.yml +34 -0
- data/test/fixtures/topics.yml +29 -0
- data/test/fixtures/users.yml +9 -0
- data/test/functional/forums_controller_test.rb +51 -0
- data/test/functional/posts_controller_test.rb +54 -0
- data/test/functional/topics_controller_test.rb +55 -0
- data/test/unit/forum_test.rb +10 -0
- data/test/unit/post_test.rb +32 -0
- data/test/unit/topic_test.rb +33 -0
- data/vendor/plugins/white_list/README +29 -0
- data/vendor/plugins/white_list/Rakefile +22 -0
- data/vendor/plugins/white_list/init.rb +2 -0
- data/vendor/plugins/white_list/lib/white_list_helper.rb +97 -0
- data/vendor/plugins/white_list/test/white_list_test.rb +132 -0
- data/vendor/plugins/white_list_formatted_content/init.rb +27 -0
- metadata +161 -0
data/config/conf.rb
ADDED
File without changes
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/actions'
|
3
|
+
|
4
|
+
class TamedBeast::InstallGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Actions
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
File.join(File.dirname(__FILE__), 'templates')
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_default_routes
|
12
|
+
route(File.read(File.join(File.dirname(__FILE__), 'templates/routes.rb') ), "config/routes.rb")
|
13
|
+
end
|
14
|
+
|
15
|
+
def copy_plugins
|
16
|
+
to = File.join(Rails.root, 'vendor/plugins/')
|
17
|
+
|
18
|
+
from = File.join(File.dirname(__FILE__), '../../../vendor/plugins/white_list')
|
19
|
+
copy_files(from, to, :plugin, "vendor/plugins/white_list")
|
20
|
+
|
21
|
+
from = File.join(File.dirname(__FILE__), '../../../vendor/plugins/white_list_formatted_content')
|
22
|
+
copy_files(from, to, :plugin, "vendor/plugins/white_list_formatted_content")
|
23
|
+
|
24
|
+
from = File.join(File.dirname(__FILE__), '../../../test/')
|
25
|
+
contents = Dir.glob( File.join(from, '**', '*') )
|
26
|
+
copy_files(from, Rails.root, :test, contents)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def copy_files(from, to, log_type, log_msg)
|
31
|
+
if log_msg.is_a?(String)
|
32
|
+
log log_type, log_msg
|
33
|
+
else
|
34
|
+
log_msg.each do |content|
|
35
|
+
f = content.gsub(/.*\/tamed_beast\/..\/..\/..\//,'')
|
36
|
+
if File.directory? content
|
37
|
+
log :directory, f
|
38
|
+
else
|
39
|
+
log :file, f
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
FileUtils.cp_r(from, to)
|
44
|
+
end
|
45
|
+
|
46
|
+
# overrided from https://github.com/rails/rails/blob/master/railties/lib/rails/generators/actions.rb
|
47
|
+
# we need a custom message and omit our routes.rb content
|
48
|
+
def route(routing_code, msg=nil)
|
49
|
+
log :route, msg || routing_code
|
50
|
+
sentinel = /\.routes\.draw do(?:\s*\|map\|)?\s*$/
|
51
|
+
|
52
|
+
in_root do
|
53
|
+
inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel, :verbose => false }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
require 'rails/generators/actions'
|
4
|
+
|
5
|
+
class TamedBeast::MigrationGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
include Rails::Generators::Actions
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
File.join(File.dirname(__FILE__), 'templates')
|
11
|
+
end
|
12
|
+
|
13
|
+
# Implement the required interface for Rails::Generators::Migration.
|
14
|
+
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
15
|
+
def self.next_migration_number(dirname) #:nodoc:
|
16
|
+
if ActiveRecord::Base.timestamped_migrations
|
17
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
18
|
+
else
|
19
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_migration_file
|
24
|
+
migration_template 'migration.rb', 'db/migrate/create_tamed_beast_tables.rb'
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class CreateTamedBeastTables < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table "forums" do |t|
|
4
|
+
t.string "name"
|
5
|
+
t.string "description"
|
6
|
+
t.integer "topics_count", :default => 0
|
7
|
+
t.integer "posts_count", :default => 0
|
8
|
+
t.integer "position"
|
9
|
+
t.text "description_html"
|
10
|
+
end
|
11
|
+
|
12
|
+
create_table "posts" do |t|
|
13
|
+
t.integer "user_id"
|
14
|
+
t.integer "topic_id"
|
15
|
+
t.text "body"
|
16
|
+
t.datetime "created_at"
|
17
|
+
t.datetime "updated_at"
|
18
|
+
t.integer "forum_id"
|
19
|
+
t.text "body_html"
|
20
|
+
end
|
21
|
+
|
22
|
+
add_index "posts", ["forum_id", "created_at"], :name => "index_posts_on_forum_id"
|
23
|
+
add_index "posts", ["user_id", "created_at"], :name => "index_posts_on_user_id"
|
24
|
+
add_index "posts", ["topic_id", "created_at"], :name => "index_posts_on_topic_id"
|
25
|
+
|
26
|
+
create_table "topics" do |t|
|
27
|
+
t.integer "forum_id"
|
28
|
+
t.integer "user_id"
|
29
|
+
t.string "title"
|
30
|
+
t.datetime "created_at"
|
31
|
+
t.datetime "updated_at"
|
32
|
+
t.integer "hits", :default => 0
|
33
|
+
t.integer "sticky", :default => 0
|
34
|
+
t.integer "posts_count", :default => 0
|
35
|
+
t.datetime "replied_at"
|
36
|
+
t.boolean "locked", :default => false
|
37
|
+
t.integer "replied_by"
|
38
|
+
t.integer "last_post_id"
|
39
|
+
end
|
40
|
+
|
41
|
+
add_index "topics", ["forum_id"], :name => "index_topics_on_forum_id"
|
42
|
+
add_index "topics", ["forum_id", "sticky", "replied_at"], :name => "index_topics_on_sticky_and_replied_at"
|
43
|
+
add_index "topics", ["forum_id", "replied_at"], :name => "index_topics_on_forum_id_and_replied_at"
|
44
|
+
|
45
|
+
add_column :users, :posts_count, :integer, :default => 0
|
46
|
+
add_column :users, :last_seen_at, :datetime
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.down
|
50
|
+
remove_column :users, :posts_count
|
51
|
+
remove_column :users, :last_seen_at
|
52
|
+
|
53
|
+
drop_table :topics
|
54
|
+
drop_table :posts
|
55
|
+
drop_table :forums
|
56
|
+
end
|
57
|
+
end
|
data/lib/tamed_beast.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module ApplicationHelper
|
2
|
+
def avatar_for(user, size=32)
|
3
|
+
begin
|
4
|
+
image_tag "http://www.gravatar.com/avatar.php?gravatar_id=#{MD5.md5(user.email)}&rating=PG&size=#{size}", :size => "#{size}x#{size}", :class => 'photo'
|
5
|
+
rescue
|
6
|
+
image_tag "http://www.gravatar.com/avatar.php?rating=PG&size=#{size}", :size => "#{size}x#{size}", :class => 'photo'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def topic_title_link(topic, options)
|
11
|
+
if topic.title =~ /^\[([^\]]{1,15})\]((\s+)\w+.*)/
|
12
|
+
"<span class='flag'>#{$1}</span>" +
|
13
|
+
link_to(h($2.strip), forum_topic_path(@forum, topic), options)
|
14
|
+
else
|
15
|
+
link_to(h(topic.title), forum_topic_path(@forum, topic), options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module TamedBeast::Auth
|
2
|
+
def self.included(base)
|
3
|
+
base.class_eval do
|
4
|
+
def current_user
|
5
|
+
#@current_user ||= ((session[:user_id] && User.find_by_id(session[:user_id])) || 0)
|
6
|
+
nil
|
7
|
+
end
|
8
|
+
ActionController::Base.helper_method :current_user
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
def login_required
|
13
|
+
if !current_user
|
14
|
+
# redirect to login page
|
15
|
+
false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
ActionView::Base.send :include, TamedBeast::Auth
|
22
|
+
ActionController::Base.send :include, TamedBeast::Auth
|
23
|
+
|
24
|
+
|
data/tamed_beast.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "tamed_beast/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "tamed_beast"
|
7
|
+
s.version = TamedBeast::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Luca Bonmassar, Andrea Pavoni"]
|
10
|
+
s.email = ["info@coderloop.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Bullettin board for Rails}
|
13
|
+
s.description = %q{Provides a simple bullettin board for Rails apps.}
|
14
|
+
|
15
|
+
s.add_dependency 'rails', "~> 3.0.3"
|
16
|
+
s.add_dependency 'will_paginate', "~> 3.0.beta"
|
17
|
+
s.add_dependency 'acts_as_list'
|
18
|
+
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
one:
|
2
|
+
id: 1
|
3
|
+
topic_id: 1
|
4
|
+
user_id: 1
|
5
|
+
forum_id: 1
|
6
|
+
body: "lorem ipsum dolor sit amet"
|
7
|
+
|
8
|
+
two:
|
9
|
+
id: 2
|
10
|
+
topic_id: 2
|
11
|
+
user_id: 1
|
12
|
+
forum_id: 1
|
13
|
+
body: "lorem ipsum dolor sit amet"
|
14
|
+
|
15
|
+
three:
|
16
|
+
id: 3
|
17
|
+
topic_id: 1
|
18
|
+
user_id: 1
|
19
|
+
forum_id: 1
|
20
|
+
body: "lorem ipsum dolor sit amet"
|
21
|
+
|
22
|
+
four:
|
23
|
+
id: 4
|
24
|
+
topic_id: 4
|
25
|
+
user_id: 1
|
26
|
+
forum_id: 1
|
27
|
+
body: "lorem ipsum dolor sit amet"
|
28
|
+
|
29
|
+
five:
|
30
|
+
id: 5
|
31
|
+
topic_id: 4
|
32
|
+
user_id: 1
|
33
|
+
forum_id: 1
|
34
|
+
body: "lorem ipsum dolor sit amet"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
one:
|
2
|
+
id: 1
|
3
|
+
user_id: 1
|
4
|
+
forum_id: 1
|
5
|
+
title: "lorem ipsum dolor sit amet"
|
6
|
+
|
7
|
+
two:
|
8
|
+
id: 2
|
9
|
+
user_id: 1
|
10
|
+
forum_id: 1
|
11
|
+
title: "lorem ipsum dolor sit amet"
|
12
|
+
|
13
|
+
three:
|
14
|
+
id: 3
|
15
|
+
user_id: 1
|
16
|
+
forum_id: 1
|
17
|
+
title: "lorem ipsum dolor sit amet"
|
18
|
+
|
19
|
+
four:
|
20
|
+
id: 4
|
21
|
+
user_id: 1
|
22
|
+
forum_id: 1
|
23
|
+
title: "lorem ipsum dolor sit amet"
|
24
|
+
|
25
|
+
five:
|
26
|
+
id: 5
|
27
|
+
user_id: 1
|
28
|
+
forum_id: 1
|
29
|
+
title: "lorem ipsum dolor sit amet"
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ForumsControllerTest < ActionController::TestCase
|
4
|
+
fixtures :posts
|
5
|
+
fixtures :topics
|
6
|
+
fixtures :forums
|
7
|
+
fixtures :users
|
8
|
+
|
9
|
+
test "show action redirects to ForumsController#show" do
|
10
|
+
f = forums(:one)
|
11
|
+
get :show, :id => f.id
|
12
|
+
assert_response :success
|
13
|
+
assert_equal Topic.where(:forum_id => 1).count, assigns(:forum).topics.size
|
14
|
+
end
|
15
|
+
|
16
|
+
test "create action" do
|
17
|
+
f = forums(:one)
|
18
|
+
u = users(:one)
|
19
|
+
sign_in(u)
|
20
|
+
|
21
|
+
assert_difference "Forum.count" do
|
22
|
+
post :create, :forum => {:name => 'test forum'}
|
23
|
+
f = Forum.last
|
24
|
+
assert_redirected_to forum_path(f)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
test "update action" do
|
29
|
+
f = forums(:one)
|
30
|
+
u = users(:one)
|
31
|
+
sign_in(u)
|
32
|
+
|
33
|
+
put :update, :id => f.id, :forum => {:name => 'test test'}
|
34
|
+
assert_redirected_to forum_path(f)
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
test "destroy action" do
|
39
|
+
f = forums(:one)
|
40
|
+
u = users(:one)
|
41
|
+
sign_in(u)
|
42
|
+
|
43
|
+
delete :destroy, :id => f.id
|
44
|
+
assert_redirected_to forums_path
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def sign_in(u)
|
49
|
+
session[:user_id] = u.id
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PostsControllerTest < ActionController::TestCase
|
4
|
+
fixtures :posts
|
5
|
+
fixtures :topics
|
6
|
+
fixtures :forums
|
7
|
+
fixtures :users
|
8
|
+
|
9
|
+
test "show action redirects to TopicsController#show" do
|
10
|
+
get :show, :topic_id => 1, :forum_id => 1, :id => 1
|
11
|
+
|
12
|
+
assert_redirected_to forum_topic_path(1,1)
|
13
|
+
end
|
14
|
+
|
15
|
+
test "create action" do
|
16
|
+
f = forums(:one)
|
17
|
+
t = topics(:one)
|
18
|
+
u = users(:one)
|
19
|
+
sign_in(u)
|
20
|
+
|
21
|
+
assert_difference "Post.where(:topic_id => #{t.id}).count" do
|
22
|
+
post :create, :topic_id => t.id, :forum_id => f.id, :post => {:body => 'test test'}
|
23
|
+
assert_redirected_to forum_topic_path(f,t, {:anchor => assigns(:post).dom_id, :page => 1})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
test "update action" do
|
28
|
+
f = forums(:one)
|
29
|
+
t = topics(:one)
|
30
|
+
p = posts(:one)
|
31
|
+
u = users(:one)
|
32
|
+
sign_in(u)
|
33
|
+
|
34
|
+
put :update, :topic_id => t.id, :forum_id => f.id, :id => p.id, :post => {:body => 'test test'}
|
35
|
+
assert_redirected_to forum_topic_path(f,t, {:anchor => p.dom_id, :page => 1})
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
test "destroy action" do
|
40
|
+
f = forums(:one)
|
41
|
+
t = topics(:one)
|
42
|
+
u = users(:one)
|
43
|
+
p = posts(:one)
|
44
|
+
sign_in(u)
|
45
|
+
|
46
|
+
delete :destroy, :topic_id => t.id, :forum_id => f.id, :id => p.id
|
47
|
+
assert_redirected_to forum_topic_path(f,t)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def sign_in(u)
|
52
|
+
session[:user_id] = u.id
|
53
|
+
end
|
54
|
+
end
|