simple_forum 0.0.2 → 0.0.4

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.
Files changed (50) hide show
  1. data/README.rdoc +17 -16
  2. data/app/assets/images/simple_forum/galdomedia-logo.png +0 -0
  3. data/app/assets/javascripts/simple_forum/application.js +5 -1
  4. data/app/assets/javascripts/simple_forum/moderators.js +40 -0
  5. data/app/assets/stylesheets/simple_forum/admin.css +15 -0
  6. data/app/assets/stylesheets/simple_forum/base.css +10 -0
  7. data/app/controllers/simple_forum/admin/base_controller.rb +7 -0
  8. data/app/controllers/simple_forum/admin/categories_controller.rb +70 -0
  9. data/app/controllers/simple_forum/admin/forums_controller.rb +88 -0
  10. data/app/controllers/simple_forum/application_controller.rb +29 -6
  11. data/app/controllers/simple_forum/forums_controller.rb +4 -4
  12. data/app/controllers/simple_forum/posts_controller.rb +2 -2
  13. data/app/controllers/simple_forum/topics_controller.rb +3 -3
  14. data/app/models/simple_forum/forum.rb +2 -10
  15. data/app/models/simple_forum/moderatorship.rb +1 -1
  16. data/app/models/simple_forum/post.rb +3 -3
  17. data/app/models/simple_forum/topic.rb +1 -9
  18. data/app/models/simple_forum/user_activity.rb +68 -61
  19. data/app/views/layouts/simple_forum.html.erb +22 -3
  20. data/app/views/layouts/simple_forum/admin.html.erb +70 -0
  21. data/app/views/simple_forum/admin/categories/_form.html.erb +9 -0
  22. data/app/views/simple_forum/admin/categories/edit.html.erb +18 -0
  23. data/app/views/simple_forum/admin/categories/index.html.erb +45 -0
  24. data/app/views/simple_forum/admin/categories/new.html.erb +17 -0
  25. data/app/views/simple_forum/admin/categories/show.html.erb +35 -0
  26. data/app/views/simple_forum/admin/forums/_form.html.erb +45 -0
  27. data/app/views/simple_forum/admin/forums/_moderator.html.erb +5 -0
  28. data/app/views/simple_forum/admin/forums/edit.html.erb +21 -0
  29. data/app/views/simple_forum/admin/forums/index.html.erb +77 -0
  30. data/app/views/simple_forum/admin/forums/new.html.erb +20 -0
  31. data/app/views/simple_forum/admin/forums/show.html.erb +55 -0
  32. data/app/views/simple_forum/forums/index.html.erb +4 -4
  33. data/app/views/simple_forum/forums/show.html.erb +4 -4
  34. data/app/views/simple_forum/posts/edit.html.erb +4 -10
  35. data/app/views/simple_forum/topics/_post.html.erb +4 -4
  36. data/app/views/simple_forum/topics/new.html.erb +1 -1
  37. data/app/views/simple_forum/topics/show.html.erb +3 -3
  38. data/config/locales/simple_forum.en.yml +130 -0
  39. data/config/locales/simple_forum.pl.yml +1 -0
  40. data/config/routes.rb +8 -0
  41. data/db/migrate/20110330123461_create_simple_forum_user_activities.rb +17 -0
  42. data/lib/generators/simple_forum/install_generator.rb +4 -5
  43. data/lib/generators/simple_forum/views_generator.rb +18 -0
  44. data/lib/generators/templates/simple_forum.rb +28 -24
  45. data/lib/simple_forum.rb +53 -30
  46. data/lib/simple_forum/configuration.rb +39 -0
  47. data/lib/simple_forum/engine.rb +8 -1
  48. data/lib/simple_forum/extensions/user.rb +18 -0
  49. data/lib/simple_forum/version.rb +2 -2
  50. metadata +97 -74
data/README.rdoc CHANGED
@@ -6,41 +6,42 @@ Make sure you have model representing user. Default is User class. You can chang
6
6
  User model must respond to 'name'.
7
7
 
8
8
  Add simple_forum to your Rails 3 Gemfile
9
-
10
9
  gem "simple_forum", :git => "git@github.com:galdomedia/mountable_forum.git"
11
10
 
11
+ And install gems with bundler
12
12
  bundle install
13
13
 
14
- Install the initializer
15
-
14
+ Install the initializer and mount engine in routes.rb
16
15
  rails g simple_forum:install
17
16
 
18
17
  Edit the initializer located in `config/initializers/simple_forum.rb` to satisfy your needs.
19
18
 
20
19
  Copy migrations
21
- rake simple_forum_engine:install
20
+ bundle exec rake simple_forum:install:migrations
22
21
 
23
22
  Run migrations
24
- rake db:migrate
23
+ bundle exec rake db:migrate
25
24
 
26
25
  moderator can:
27
- - close/open topics
28
- - edit posts
29
- - delete(mark as deleted) posts
26
+ - close/open topics
27
+ - edit posts
28
+ - delete(mark as deleted) posts
29
+
30
30
  TODO:
31
- - edit topics
32
- - delete topics (?)
31
+ - edit topics
32
+ - delete topics (?)
33
33
 
34
34
  signed in user can:
35
- - create posts
36
- - edit own posts(in specified period of time)
37
- - delete(mark as deleted) own posts(in specified period of time)
35
+ - create posts
36
+ - edit own posts(in specified period of time)
37
+ - delete(mark as deleted) own posts(in specified period of time)
38
38
 
39
39
  When you are using friendly_id forums and topics will be automatically using it.
40
- If not to_param method return something like "#{id}-#{name.parameterize}".
40
+ If not to_param method return something like:
41
+ "#{id}-#{name.parameterize}"
41
42
 
42
- TODO:
43
- - add generator or rake task to copy views to user application
43
+ You can copy and customize views to your application by running generator:
44
+ rails g simple_forum:views
44
45
 
45
46
 
46
47
  This project rocks and uses MIT-LICENSE.
@@ -12,4 +12,8 @@
12
12
  //
13
13
  //= require jquery
14
14
  //= require jquery_ujs
15
- //=
15
+ //= require_self
16
+
17
+ simple_forum = {
18
+ 'translations':{}
19
+ };
@@ -0,0 +1,40 @@
1
+ (function () {
2
+ var search_users_timeout;
3
+
4
+ var search_users = function (str) {
5
+ var params = {'user_name_like':str};
6
+ var $results = $('#search_users_result');
7
+ $results.html('');
8
+ $.getJSON(simple_forum.user_search_path, params, function (json) {
9
+ $.each(json, function (key, val) {
10
+ var $item = $('<li>' + val + ' <a href="#" class="add-moderator" data-user_id="' + key + '" data-user_name="' + val + '">[' + simple_forum.translations['add_moderator'] + ']</a></li>');
11
+ $results.append($item);
12
+ });
13
+ });
14
+ };
15
+
16
+ $(function () {
17
+ $('#search_users_input').keyup(function () {
18
+ var $input = $(this);
19
+ if (search_users_timeout) clearTimeout(search_users_timeout);
20
+ search_users_timeout = setTimeout(function () {
21
+ search_users($input.val());
22
+ }, 300);
23
+ });
24
+
25
+ $('a.add-moderator').live('click', function () {
26
+ var $this = $(this),
27
+ user_id = $this.data('user_id'),
28
+ user_name = $this.data('user_name');
29
+ var html = simple_forum.moderator_template.replace(/temp_user_id/g, user_id).replace(/temp_user_name/g, user_name);
30
+ $('#moderators').append(html);
31
+ return false;
32
+ });
33
+
34
+ $('a.remove-moderator').live('click', function () {
35
+ var $this = $(this);
36
+ $this.closest('li').remove();
37
+ return false;
38
+ });
39
+ });
40
+ })();
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require web-app-theme/base
12
+ *= require web-app-theme/themes/default/style
13
+ *= require formtastic.css
14
+ *= require_self
15
+ */
@@ -33,6 +33,16 @@ h2 {
33
33
  margin: 20px 0;
34
34
  }
35
35
 
36
+ body ul.links {
37
+ float: right;
38
+ }
39
+
40
+ body ul.links li {
41
+ float: right;
42
+ padding-left: 16px;
43
+ list-style: none;
44
+ }
45
+
36
46
  p, h2, pre {
37
47
  margin: 0;
38
48
  padding: 5px 20px;
@@ -0,0 +1,7 @@
1
+ class SimpleForum::Admin::BaseController < ::SimpleForum::ApplicationController
2
+ layout 'simple_forum/admin'
3
+ before_filter :forum_admin_required
4
+
5
+ protected
6
+
7
+ end
@@ -0,0 +1,70 @@
1
+ module SimpleForum
2
+ module Admin
3
+ class CategoriesController < ::SimpleForum::Admin::BaseController
4
+
5
+ def index
6
+ @categories = SimpleForum::Category.default_order.all
7
+
8
+ respond_with(@categories)
9
+ end
10
+
11
+ def show
12
+
13
+ respond_with([:admin, resource])
14
+ end
15
+
16
+ def edit
17
+
18
+ respond_with([:admin, resource])
19
+ end
20
+
21
+ def new
22
+
23
+ respond_with([:admin, resource])
24
+ end
25
+
26
+ def create
27
+ success = resource.save
28
+
29
+ respond_with([:admin, resource]) do |format|
30
+ format.html do
31
+ if success
32
+ redirect_to [:admin, resource]
33
+ else
34
+ render :new
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def update
41
+ success = resource.update_attributes(params[:category])
42
+
43
+ respond_with([:admin, resource]) do |format|
44
+ format.html do
45
+ if success
46
+ redirect_to [:admin, resource]
47
+ else
48
+ render :edit
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ def destroy
55
+ resource.destroy
56
+
57
+ respond_with([:admin, resource])
58
+ end
59
+
60
+ private
61
+
62
+ def resource
63
+ @category ||= params[:id] ? SimpleForum::Category.find(params[:id]) : SimpleForum::Category.new(params[:category])
64
+ end
65
+
66
+ helper_method :resource
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,88 @@
1
+ module SimpleForum
2
+ module Admin
3
+ class ForumsController < ::SimpleForum::Admin::BaseController
4
+
5
+ def search_users
6
+ user_class = instance_eval(&SimpleForum.invoke(:user_class))
7
+ @users = user_class.where(["#{user_class.quoted_table_name}.email LIKE ?", "%#{params[:user_name_like].to_s.gsub(/[\%\_]/) { |m| "\\#{m}" }}%"]).limit(16)
8
+
9
+ respond_to do |format|
10
+ format.json do
11
+ render :json => @users.inject({}) { |hash, u| hash[u.id] = u.name; hash }
12
+ end
13
+ end
14
+ end
15
+
16
+ def index
17
+ @categories = SimpleForum::Category.default_order.includes({:forums => [{:recent_post => [:user, :topic]}, :moderators]})
18
+
19
+ @forums = SimpleForum::Forum.default_order.includes({:recent_post => [:user, :topic]}, :moderators)
20
+ @forums_by_category = @categories.inject(ActiveSupport::OrderedHash.new) { |h, c| h[c] = []; h }
21
+ @forums.each do |f|
22
+ (@forums_by_category[@categories.detect { |c| c.try(:id) == f.category_id }] ||= []) << f
23
+ end
24
+ @forums_by_category.reject! { |c, forums| forums.blank? }
25
+
26
+ respond_with(@forums)
27
+ end
28
+
29
+ def show
30
+
31
+ respond_with([:admin, resource])
32
+ end
33
+
34
+ def edit
35
+
36
+ respond_with([:admin, resource])
37
+ end
38
+
39
+ def new
40
+
41
+ respond_with([:admin, resource])
42
+ end
43
+
44
+ def create
45
+ success = resource.save
46
+
47
+ respond_with([:admin, resource]) do |format|
48
+ format.html do
49
+ if success
50
+ redirect_to [:admin, resource]
51
+ else
52
+ render :new
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ def update
59
+ success = resource.update_attributes(params[:forum])
60
+
61
+ respond_with([:admin, resource]) do |format|
62
+ format.html do
63
+ if success
64
+ redirect_to [:admin, resource]
65
+ else
66
+ render :edit
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ def destroy
73
+ resource.destroy
74
+
75
+ respond_with([:admin, resource])
76
+ end
77
+
78
+ private
79
+
80
+ def resource
81
+ @forum ||= params[:id] ? SimpleForum::Forum.find(params[:id]) : SimpleForum::Forum.new(params[:forum])
82
+ end
83
+
84
+ helper_method :resource
85
+
86
+ end
87
+ end
88
+ end
@@ -1,27 +1,50 @@
1
1
  module SimpleForum
2
2
  class ApplicationController < ::ApplicationController #::ActionController::Base
3
3
  respond_to :html
4
- protect_from_forgery
4
+ #protect_from_forgery
5
5
 
6
6
  layout SimpleForum.layout
7
7
 
8
- helper_method :authenticated_user, :user_authenticated?
8
+ helper_method :authenticated_user, :user_authenticated?, :forum_admin?
9
+ helper_method :simple_forum_recent_activity?
9
10
 
10
11
  private
11
12
 
12
13
  def authenticated_user
13
- instance_eval &AbstractAuth.invoke(:authenticated_user)
14
+ instance_eval &SimpleForum.invoke(:authenticated_user)
14
15
  end
15
16
 
16
17
  def user_authenticated?
17
- instance_eval &AbstractAuth.invoke(:user_authenticated?)
18
+ instance_eval &SimpleForum.invoke(:user_authenticated?)
18
19
  end
19
20
 
20
21
  def authenticate_user
21
- redirect_to :back, :alert => "You have to be logged in" unless user_authenticated?
22
+ redirect_to :back, :alert => t('simple_forum.controllers.you_have_to_be_signed_in_to_perform_this_action') unless user_authenticated?
23
+ end
24
+
25
+ def forum_admin?
26
+ instance_eval(&SimpleForum.invoke(:forum_admin?))
27
+ end
28
+
29
+ def forum_admin_required
30
+ redirect_to simple_forum.root_path unless forum_admin?
31
+ end
32
+
33
+ def simple_forum_activity_checker
34
+ @_simple_forum_activity_checker ||= SimpleForum::UserActivity.recent_activity_for_user(authenticated_user)
35
+ end
36
+
37
+ def simple_forum_recent_activity?(forum_or_topic)
38
+ return false unless user_authenticated?
39
+ simple_forum_activity_checker.recent_activity?(forum_or_topic)
22
40
  end
23
- end
24
41
 
42
+ def bang_simple_forum_recent_activity(forum_or_topic)
43
+ return unless user_authenticated?
44
+ simple_forum_activity_checker.bang(forum_or_topic)
45
+ end
46
+
47
+ end
25
48
  end
26
49
 
27
50
 
@@ -1,5 +1,5 @@
1
1
  module SimpleForum
2
- class ForumsController < ApplicationController
2
+ class ForumsController < ::SimpleForum::ApplicationController
3
3
 
4
4
  before_filter :find_forum, :except => [:index]
5
5
 
@@ -10,8 +10,8 @@ module SimpleForum
10
10
  end
11
11
 
12
12
  def show
13
- @forum.bang_recent_activity(authenticated_user)
14
-
13
+ bang_simple_forum_recent_activity(@forum)
14
+
15
15
  scope = @forum.topics.includes([:user, {:recent_post => :user}])
16
16
  @topics = scope.respond_to?(:paginate) ? scope.paginate(:page => params[:page], :per_page => params[:per_page]) : scope.all
17
17
 
@@ -25,4 +25,4 @@ module SimpleForum
25
25
  end
26
26
 
27
27
  end
28
- end
28
+ end
@@ -1,5 +1,5 @@
1
1
  module SimpleForum
2
- class PostsController < ApplicationController
2
+ class PostsController < ::SimpleForum::ApplicationController
3
3
 
4
4
  before_filter :authenticate_user, :except => [:index, :show]
5
5
 
@@ -111,4 +111,4 @@ module SimpleForum
111
111
  end
112
112
 
113
113
  end
114
- end
114
+ end
@@ -1,5 +1,5 @@
1
1
  module SimpleForum
2
- class TopicsController < ApplicationController
2
+ class TopicsController < ::SimpleForum::ApplicationController
3
3
  respond_to :html
4
4
 
5
5
  before_filter :authenticate_user, :only => [:new, :create, :open, :close]
@@ -20,7 +20,7 @@ module SimpleForum
20
20
  end
21
21
 
22
22
  def show
23
- @topic.bang_recent_activity(authenticated_user)
23
+ bang_simple_forum_recent_activity(@topic)
24
24
  @topic.increment_views_count
25
25
 
26
26
  @posts_search = @topic.posts.includes([:user, :deleted_by, :edited_by])
@@ -113,4 +113,4 @@ module SimpleForum
113
113
  end
114
114
 
115
115
  end
116
- end
116
+ end
@@ -27,12 +27,12 @@ module SimpleForum
27
27
  :through => :moderatorships,
28
28
  :source => :user
29
29
 
30
- scope :default_order, order("#{quoted_table_name}.position ASC")
30
+ scope :default_order, order("#{quoted_table_name}.position ASC, #{quoted_table_name}.id ASC")
31
31
 
32
32
  validates :name, :presence => true
33
33
  validates :position, :presence => true, :numericality => {:only_integer => true, :allow_nil => true}
34
34
 
35
- attr_accessible :name, :body, :parent_id, :position, :moderator_ids, :category_id
35
+ attr_accessible :name, :body, :parent_id, :position, :moderator_ids, :category_id, :is_topicable
36
36
 
37
37
  if respond_to?(:has_friendly_id)
38
38
  has_friendly_id :name, :use_slug => true, :approximate_ascii => true
@@ -42,14 +42,6 @@ module SimpleForum
42
42
  end
43
43
  end
44
44
 
45
- def recent_activity?(user)
46
- SimpleForum::UserActivity.new(user).recent_activity?(self)
47
- end
48
-
49
- def bang_recent_activity(user)
50
- SimpleForum::UserActivity.new(user).bang(self)
51
- end
52
-
53
45
  def moderated_by?(user)
54
46
  return false unless user
55
47
  @moderated_by_cache ||= {}