simple_forum 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +18 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +49 -0
- data/Rakefile +27 -0
- data/app/controllers/simple_forum/application_controller.rb +27 -0
- data/app/controllers/simple_forum/forums_controller.rb +29 -0
- data/app/controllers/simple_forum/posts_controller.rb +114 -0
- data/app/controllers/simple_forum/topics_controller.rb +116 -0
- data/app/models/simple_forum.rb +6 -0
- data/app/models/simple_forum/category.rb +28 -0
- data/app/models/simple_forum/forum.rb +69 -0
- data/app/models/simple_forum/moderatorship.rb +18 -0
- data/app/models/simple_forum/post.rb +105 -0
- data/app/models/simple_forum/topic.rb +134 -0
- data/app/models/simple_forum/user_activity.rb +80 -0
- data/app/views/layouts/simple_forum.html.erb +50 -0
- data/app/views/simple_forum/forums/index.html.erb +76 -0
- data/app/views/simple_forum/forums/show.html.erb +92 -0
- data/app/views/simple_forum/posts/edit.html.erb +41 -0
- data/app/views/simple_forum/topics/_post.html.erb +73 -0
- data/app/views/simple_forum/topics/new.html.erb +23 -0
- data/app/views/simple_forum/topics/show.html.erb +68 -0
- data/config/locales/simple_forum.pl.yml +121 -0
- data/config/routes.rb +44 -0
- data/lib/bb-ruby/bb-ruby.rb +57 -0
- data/lib/generators/simple_forum/install_generator.rb +19 -0
- data/lib/generators/templates/simple_forum.rb +34 -0
- data/lib/simple_forum.rb +52 -0
- data/lib/simple_forum/engine.rb +15 -0
- data/lib/simple_forum/tasks/railties.rake +66 -0
- data/lib/simple_forum/version.rb +4 -0
- metadata +114 -0
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "rails", "3.1.0"
|
4
|
+
#gem "rails", :git => "git://github.com/rails/rails.git"
|
5
|
+
#gem "arel", :git => "git://github.com/rails/arel.git"
|
6
|
+
#gem "rack", :git => "git://github.com/rack/rack.git"
|
7
|
+
|
8
|
+
gem "devise"
|
9
|
+
|
10
|
+
gem "sqlite3"
|
11
|
+
|
12
|
+
#group :development, :test do
|
13
|
+
gem "capybara", ">= 0.4.0"
|
14
|
+
gem "rspec-rails", ">= 2.0.0.beta"
|
15
|
+
gem "factory_girl"
|
16
|
+
#end
|
17
|
+
|
18
|
+
gemspec
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= SimpleForum
|
2
|
+
|
3
|
+
### Instalation
|
4
|
+
|
5
|
+
Make sure you have model representing user. Default is User class. You can change this.
|
6
|
+
User model must respond to 'name'.
|
7
|
+
|
8
|
+
Add simple_forum to your Rails 3 Gemfile
|
9
|
+
|
10
|
+
gem "simple_forum", :git => "git@github.com:galdomedia/mountable_forum.git"
|
11
|
+
|
12
|
+
bundle install
|
13
|
+
|
14
|
+
Install the initializer
|
15
|
+
|
16
|
+
rails g simple_forum:install
|
17
|
+
|
18
|
+
Edit the initializer located in `config/initializers/simple_forum.rb` to satisfy your needs.
|
19
|
+
|
20
|
+
Copy assets & migrations
|
21
|
+
rake simple_forum_engine:install
|
22
|
+
|
23
|
+
or rake simple_forum:install if rake simple_forum_engine:install doesn't work(rails version < 3.1)
|
24
|
+
|
25
|
+
Run migrations
|
26
|
+
rake db:migrate
|
27
|
+
|
28
|
+
|
29
|
+
moderator can:
|
30
|
+
- close/open topics
|
31
|
+
- edit posts
|
32
|
+
- delete(mark as deleted) posts
|
33
|
+
TODO:
|
34
|
+
- edit topics
|
35
|
+
- delete topics (?)
|
36
|
+
|
37
|
+
signed in user can:
|
38
|
+
- create posts
|
39
|
+
- edit own posts(in specified period of time)
|
40
|
+
- delete(mark as deleted) own posts(in specified period of time)
|
41
|
+
|
42
|
+
When you are using friendly_id forums and topics will be automatically using it.
|
43
|
+
If not to_param method return something like "#{id}-#{name.parameterize}".
|
44
|
+
|
45
|
+
TODO:
|
46
|
+
- add generator or rake task to copy views to user application
|
47
|
+
|
48
|
+
|
49
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
|
12
|
+
require 'rspec/core'
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
|
17
|
+
task :default => :spec
|
18
|
+
|
19
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = 'SimpleForum'
|
22
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
23
|
+
rdoc.rdoc_files.include('README.rdoc')
|
24
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
|
+
end
|
26
|
+
|
27
|
+
Bundler::GemHelper.install_tasks
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module SimpleForum
|
2
|
+
class ApplicationController < ::ApplicationController #::ActionController::Base
|
3
|
+
protect_from_forgery
|
4
|
+
|
5
|
+
layout SimpleForum.layout
|
6
|
+
|
7
|
+
helper_method :authenticated_user, :user_authenticated?
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def authenticated_user
|
12
|
+
instance_eval &AbstractAuth.invoke(:authenticated_user)
|
13
|
+
end
|
14
|
+
|
15
|
+
def user_authenticated?
|
16
|
+
instance_eval &AbstractAuth.invoke(:user_authenticated?)
|
17
|
+
end
|
18
|
+
|
19
|
+
def authenticate_user
|
20
|
+
redirect_to :back, :alert => "You have to be logged in" unless user_authenticated?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module SimpleForum
|
2
|
+
class ForumsController < ApplicationController
|
3
|
+
respond_to :html
|
4
|
+
|
5
|
+
before_filter :find_forum, :except => [:index]
|
6
|
+
|
7
|
+
def index
|
8
|
+
@categories = SimpleForum::Category.default_order.includes({:forums => [{:recent_post => [:user, :topic]}, :moderators]})
|
9
|
+
|
10
|
+
respond_to :html
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
@forum.bang_recent_activity(authenticated_user)
|
15
|
+
|
16
|
+
scope = @forum.topics.includes([:user, {:recent_post => :user}])
|
17
|
+
@topics = scope.respond_to?(:paginate) ? scope.paginate(:page => params[:page], :per_page => params[:per_page]) : scope.all
|
18
|
+
|
19
|
+
respond_to :html
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def find_forum
|
25
|
+
@forum = SimpleForum::Forum.find params[:id]
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module SimpleForum
|
2
|
+
class PostsController < ApplicationController
|
3
|
+
|
4
|
+
before_filter :authenticate_user, :except => [:index, :show]
|
5
|
+
|
6
|
+
before_filter :find_forum
|
7
|
+
before_filter :find_topic
|
8
|
+
before_filter :find_post, :except => [:index, :new, :create, :preview]
|
9
|
+
before_filter :build_post, :only => [:new, :create, :preview]
|
10
|
+
before_filter :post_must_be_editable_by_authenticate_user, :only => [:edit, :update]
|
11
|
+
|
12
|
+
def index
|
13
|
+
|
14
|
+
respond_to do |format|
|
15
|
+
format.html do
|
16
|
+
redirect_to simple_forum_forum_topic_url(@forum, @topic), :status => :moved_permanently
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def show
|
22
|
+
|
23
|
+
respond_to do |format|
|
24
|
+
format.html { redirect_to simple_forum_forum_topic_url(@forum, @topic, :page => @post.on_page, :anchor => "post-#{@post.id}") }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def create
|
29
|
+
success = @post.save
|
30
|
+
|
31
|
+
respond_to do |format|
|
32
|
+
format.html do
|
33
|
+
if success
|
34
|
+
redirect_to simple_forum_forum_topic_url(@forum, @topic, :page => @post.on_page, :anchor => "post-#{@post.id}"),
|
35
|
+
:notice => t('simple_forum.controllers.posts.post_created')
|
36
|
+
else
|
37
|
+
redirect_to simple_forum_forum_topic_url(@forum, @topic, :page => @topic.last_page, :anchor => (@topic.recent_post ? "post-#{@topic.recent_post.id}" : nil)),
|
38
|
+
:alert => @post.errors.full_messages.join(', ')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def preview
|
45
|
+
@post.created_at, @post.updated_at = Time.now
|
46
|
+
|
47
|
+
respond_to do |format|
|
48
|
+
format.js { render :partial => 'simple_forum/topics/post', :locals => {:post => @post, :preview => true} }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def edit
|
53
|
+
|
54
|
+
respond_to :html
|
55
|
+
end
|
56
|
+
|
57
|
+
def update
|
58
|
+
@post.edited_by = authenticated_user
|
59
|
+
@post.edited_at = Time.now
|
60
|
+
success = @post.update_attributes(params[:post])
|
61
|
+
|
62
|
+
respond_to do |format|
|
63
|
+
format.html do
|
64
|
+
if success
|
65
|
+
redirect_to simple_forum_forum_topic_url(@forum, @topic, :page => @post.on_page, :anchor => "post-#{@post.id}"),
|
66
|
+
:notice => t('simple_forum.controllers.posts.post_updated')
|
67
|
+
else
|
68
|
+
redirect_to :back, :alert => @post.errors.full_messages.join(', ')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def delete
|
76
|
+
success = @post.mark_as_deleted_by(authenticated_user) #check if post is deletable by authenticated_user in mark_as_deleted_by method
|
77
|
+
|
78
|
+
respond_to do |format|
|
79
|
+
format.html do
|
80
|
+
if success
|
81
|
+
redirect_to :back, :notice => t('simple_forum.controllers.posts.post_deleted')
|
82
|
+
else
|
83
|
+
redirect_to :back, :alert => t('simple_forum.controllers.posts.post_cant_be_deleted')
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def find_forum
|
92
|
+
@forum = SimpleForum::Forum.find params[:forum_id]
|
93
|
+
end
|
94
|
+
|
95
|
+
def find_topic
|
96
|
+
@topic = @forum.topics.find params[:topic_id]
|
97
|
+
end
|
98
|
+
|
99
|
+
def find_post
|
100
|
+
@post = @topic.posts.find params[:id]
|
101
|
+
end
|
102
|
+
|
103
|
+
def build_post
|
104
|
+
@post = @topic.posts.new params[:post] do |post|
|
105
|
+
post.user = authenticated_user
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def post_must_be_editable_by_authenticate_user
|
110
|
+
redirect_to :back, :alert => t('simple_forum.controllers.posts.post_cant_be_edited') unless @post.editable_by?(authenticated_user, nil)
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module SimpleForum
|
2
|
+
class TopicsController < ApplicationController
|
3
|
+
respond_to :html
|
4
|
+
|
5
|
+
before_filter :authenticate_user, :only => [:new, :create, :open, :close]
|
6
|
+
|
7
|
+
before_filter :find_forum
|
8
|
+
before_filter :find_topic, :except => [:index, :new, :create]
|
9
|
+
before_filter :build_topic, :only => [:new, :create]
|
10
|
+
|
11
|
+
before_filter :moderator_required, :only => [:open, :close]
|
12
|
+
|
13
|
+
def index
|
14
|
+
|
15
|
+
respond_to do |format|
|
16
|
+
format.html do
|
17
|
+
redirect_to simple_forum_forum_url(@forum), :status => :moved_permanently
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def show
|
23
|
+
@topic.bang_recent_activity(authenticated_user)
|
24
|
+
@topic.increment_views_count
|
25
|
+
|
26
|
+
@posts_search = @topic.posts.includes([:user, :deleted_by, :edited_by])
|
27
|
+
@posts = @posts_search.respond_to?(:paginate) ?
|
28
|
+
@posts_search.paginate(:page => params[:page], :per_page => params[:per_page] || SimpleForum::Post.per_page) :
|
29
|
+
@posts_search.all
|
30
|
+
|
31
|
+
@post = SimpleForum::Post.new
|
32
|
+
|
33
|
+
respond_with(@topic)
|
34
|
+
end
|
35
|
+
|
36
|
+
def new
|
37
|
+
|
38
|
+
respond_with(@topic)
|
39
|
+
end
|
40
|
+
|
41
|
+
def create
|
42
|
+
success = @topic.save
|
43
|
+
|
44
|
+
respond_to do |format|
|
45
|
+
format.html do
|
46
|
+
if success
|
47
|
+
flash[:notice] = t('simple_forum.controllers.topics.topic_created')
|
48
|
+
redirect_to simple_forum_forum_topic_url(@forum, @topic)
|
49
|
+
else
|
50
|
+
flash.now[:alert] = @topic.errors.full_messages.join(' ')
|
51
|
+
render :new
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def open
|
58
|
+
success = if @topic.is_open?
|
59
|
+
false
|
60
|
+
else
|
61
|
+
@topic.open!
|
62
|
+
true
|
63
|
+
end
|
64
|
+
|
65
|
+
respond_to do |format|
|
66
|
+
format.html do
|
67
|
+
if success
|
68
|
+
redirect_to :back, :notice => t('simple_forum.controllers.topics.topic_opened')
|
69
|
+
else
|
70
|
+
redirect_to :back, :alert => t('simple_forum.controllers.topics.topic_already_opened')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def close
|
77
|
+
success = if @topic.is_open?
|
78
|
+
@topic.close!
|
79
|
+
true
|
80
|
+
else
|
81
|
+
false
|
82
|
+
end
|
83
|
+
|
84
|
+
respond_to do |format|
|
85
|
+
format.html do
|
86
|
+
if success
|
87
|
+
redirect_to :back, :notice => t('simple_forum.controllers.topics.topic_closed')
|
88
|
+
else
|
89
|
+
redirect_to :back, :alert => t('simple_forum.controllers.topics.topic_already_closed')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def find_forum
|
98
|
+
@forum = SimpleForum::Forum.find params[:forum_id]
|
99
|
+
end
|
100
|
+
|
101
|
+
def find_topic
|
102
|
+
@topic = @forum.topics.find params[:id]
|
103
|
+
end
|
104
|
+
|
105
|
+
def build_topic
|
106
|
+
@topic = @forum.topics.new params[:topic] do |topic|
|
107
|
+
topic.user = authenticated_user
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def moderator_required
|
112
|
+
redirect_to :back, :alert => t('simple_forum.controllers.you_are_not_permitted_to_perform_this_action') unless @forum.moderated_by?(authenticated_user)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SimpleForum
|
2
|
+
class Category < ::ActiveRecord::Base
|
3
|
+
|
4
|
+
set_table_name 'simple_forum_categories' #should work table_name_prefix in SimpleForum module but it's not!'
|
5
|
+
|
6
|
+
has_many :forums,
|
7
|
+
:order => "#{SimpleForum::Forum.quoted_table_name}.position ASC",
|
8
|
+
:dependent => :nullify,
|
9
|
+
:class_name => "SimpleForum::Forum"
|
10
|
+
|
11
|
+
|
12
|
+
scope :default_order, order("#{quoted_table_name}.position ASC")
|
13
|
+
|
14
|
+
validates :name, :presence => true
|
15
|
+
validates :position, :presence => true, :numericality => {:only_integer => true, :allow_nil => true}
|
16
|
+
|
17
|
+
attr_accessible :name, :body, :position
|
18
|
+
|
19
|
+
if respond_to?(:has_friendly_id)
|
20
|
+
has_friendly_id :name, :use_slug => true, :approximate_ascii => true
|
21
|
+
else
|
22
|
+
def to_param
|
23
|
+
"#{id}-#{name.to_s.parameterize}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|