simple_discussion 0.9.4 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +12 -0
  3. data/.github/workflows/ci.yml +44 -0
  4. data/Appraisals +16 -0
  5. data/CHANGELOG.md +13 -0
  6. data/Gemfile +8 -1
  7. data/README.md +5 -3
  8. data/Rakefile +25 -3
  9. data/app/assets/stylesheets/simple_discussion.scss +40 -2
  10. data/app/controllers/simple_discussion/application_controller.rb +15 -3
  11. data/app/controllers/simple_discussion/forum_categories_controller.rb +5 -5
  12. data/app/controllers/simple_discussion/forum_posts_controller.rb +20 -14
  13. data/app/controllers/simple_discussion/forum_threads_controller.rb +10 -10
  14. data/app/controllers/simple_discussion/notifications_controller.rb +3 -3
  15. data/app/helpers/simple_discussion/forum_posts_helper.rb +7 -1
  16. data/app/helpers/simple_discussion/forum_threads_helper.rb +4 -4
  17. data/app/jobs/simple_discussion/forum_post_notification_job.rb +3 -3
  18. data/app/jobs/simple_discussion/forum_thread_notification_job.rb +2 -2
  19. data/app/mailers/simple_discussion/user_mailer.rb +4 -4
  20. data/app/models/forum_category.rb +1 -1
  21. data/app/models/forum_post.rb +1 -2
  22. data/app/models/forum_subscription.rb +4 -4
  23. data/app/models/forum_thread.rb +12 -12
  24. data/app/views/layouts/simple_discussion.html.erb +61 -18
  25. data/app/views/simple_discussion/forum_posts/_form.html.erb +2 -2
  26. data/app/views/simple_discussion/forum_posts/_forum_post.html.erb +16 -9
  27. data/app/views/simple_discussion/forum_posts/edit.html.erb +7 -3
  28. data/app/views/simple_discussion/forum_threads/_form.html.erb +8 -8
  29. data/app/views/simple_discussion/forum_threads/_forum_thread.html.erb +5 -5
  30. data/app/views/simple_discussion/forum_threads/edit.html.erb +1 -1
  31. data/app/views/simple_discussion/forum_threads/index.html.erb +11 -9
  32. data/app/views/simple_discussion/forum_threads/new.html.erb +1 -1
  33. data/app/views/simple_discussion/forum_threads/show.html.erb +15 -10
  34. data/bin/rails +14 -0
  35. data/config/locales/en.yml +46 -0
  36. data/config/locales/es.yml +41 -0
  37. data/config/locales/fr.yml +47 -0
  38. data/db/migrate/20170417012930_create_forum_categories.rb +6 -6
  39. data/db/migrate/20170417012931_create_forum_threads.rb +1 -1
  40. data/db/migrate/20170417012932_create_forum_posts.rb +3 -3
  41. data/db/migrate/20170417012933_create_forum_subscriptions.rb +2 -2
  42. data/gemfiles/.bundle/config +2 -0
  43. data/gemfiles/rails_5_2.gemfile +12 -0
  44. data/gemfiles/rails_5_2.gemfile.lock +191 -0
  45. data/gemfiles/rails_6.gemfile +12 -0
  46. data/gemfiles/rails_6.gemfile.lock +207 -0
  47. data/gemfiles/rails_6_1.gemfile +12 -0
  48. data/gemfiles/rails_6_1.gemfile.lock +210 -0
  49. data/gemfiles/rails_master.gemfile +12 -0
  50. data/gemfiles/rails_master.gemfile.lock +222 -0
  51. data/lib/generators/simple_discussion/controllers_generator.rb +2 -2
  52. data/lib/generators/simple_discussion/helpers_generator.rb +2 -2
  53. data/lib/generators/simple_discussion/views_generator.rb +2 -2
  54. data/lib/simple_discussion.rb +8 -9
  55. data/lib/simple_discussion/engine.rb +1 -1
  56. data/lib/simple_discussion/slack.rb +6 -6
  57. data/lib/simple_discussion/version.rb +1 -1
  58. data/lib/simple_discussion/will_paginate.rb +12 -12
  59. data/simple_discussion.gemspec +15 -17
  60. metadata +27 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 834ccd97ab1cd0bbbe2aeade6fd0ca57dbbb9239
4
- data.tar.gz: cdba66f70c1574b9cfca22c31d97f8004994ffd8
2
+ SHA256:
3
+ metadata.gz: a6d8a256590a5124e9207664dbe478583fb9cf184f14f84703e147cbe5772d8f
4
+ data.tar.gz: 0d75642a89aeadb6157d20c2a7825b1c780d76edc165fc03010afc7eaaf1632f
5
5
  SHA512:
6
- metadata.gz: 2efe0ca3c21542774ee8398cfaec7c5e3c03674c0976c42146769bc1762237f8d2d70dbd9700f25f6d11663665b8423e15903e2e4ef8a6d87b9fb75495514f4d
7
- data.tar.gz: 0bd0377abdf023db1527498d353d819d30de644f19ff909cc6b3e74d774aa53119418f0677fd77cf64c13b83e817060b398511a13143dbeda7c9d74258405924
6
+ metadata.gz: a731f814d38e2b48455a0239745e2d896a7369c19fbeb595de4d60a003eac9238ecfbbe1674ce4c655bd85f7aaea68d88d0f9de542282af50469a378c58575bc
7
+ data.tar.gz: 150c26dc9b91a30c2e497bc01d72637ab8b75f3f7d4c6fe5ba644e21c86d001a5e1b4f232ea1484e76c82edd7aa95649b6476ce7b86cf46a38626dace2a2bc80
@@ -0,0 +1,12 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [excid3] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ otechie: # Replace with a single Otechie username
12
+ custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
@@ -0,0 +1,44 @@
1
+ name: Tests
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - '*'
7
+ push:
8
+ branches:
9
+ - master
10
+ jobs:
11
+ sqlite:
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ ruby: ['2.7', '3.0']
16
+ gemfile:
17
+ - rails_5_2
18
+ - rails_6
19
+ - rails_6_1
20
+ - rails_master
21
+ exclude:
22
+ - ruby: '3.0'
23
+ gemfile: 'rails_5_2'
24
+ env:
25
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
26
+ BUNDLE_PATH_RELATIVE_TO_CWD: true
27
+
28
+ steps:
29
+ - uses: actions/checkout@master
30
+ - name: Set up Ruby
31
+ uses: ruby/setup-ruby@v1
32
+ with:
33
+ ruby-version: ${{ matrix.ruby }}
34
+ bundler: default
35
+ bundler-cache: true
36
+ - name: StandardRb check
37
+ run: bundle exec standardrb
38
+ - name: Run tests
39
+ env:
40
+ DATABASE_URL: "sqlite3:noticed_test"
41
+ STRIPE_PRIVATE_KEY: ${{ secrets.STRIPE_PRIVATE_KEY }}
42
+ run: |
43
+ bin/rails db:test:prepare
44
+ bin/rails test
data/Appraisals ADDED
@@ -0,0 +1,16 @@
1
+ appraise "rails-5-2" do
2
+ gem "rails", "~> 5.2.0"
3
+ end
4
+
5
+ appraise "rails-6" do
6
+ gem "rails", "~> 6.0.0"
7
+ end
8
+
9
+ appraise "rails-6-1" do
10
+ gem "rails", "~> 6.1.0"
11
+ end
12
+
13
+ appraise "rails-master" do
14
+ gem "rails", github: "rails/rails", branch: "main"
15
+ gem "devise", github: "ghiculescu/devise", branch: "patch-2"
16
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ ### Unreleased
2
+
3
+ ### 1.3.0
4
+
5
+ * Drop gravatar dependency
6
+ * Test against Rails 5.2, 6.0, 6.1, and Rails master
7
+ * Fix nested layout rendering
8
+ * Add dummy app for testing
9
+ * Relax Font Awesome dependency
10
+
11
+ ### 1.2.0
12
+
13
+ * Update to require Font Awesome 5.x+
data/Gemfile CHANGED
@@ -1,6 +1,13 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in simple_discussion.gemspec
6
6
  gemspec
7
+
8
+ gem "appraisal"
9
+ gem "standardrb"
10
+
11
+ gem "devise"
12
+ gem "puma"
13
+ gem "sqlite3"
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # SimpleDiscussion
1
+ # SimpleDiscussion - Forum engine for Ruby on Rails
2
2
 
3
- SimpleDiscussion is a Rails forum gem extracting the [forum from GoRails](https://gorails.com/forum). It includes categories, simple moderation, the ability to mark threads as solved, and more.
3
+ [![Build Status](https://github.com/excid3/simple_discussion/workflows/Tests/badge.svg)](https://github.com/excid3/simple_discussion/actions) [![Gem Version](https://badge.fury.io/rb/simple_discussion.svg)](https://badge.fury.io/rb/simple_discussion)
4
4
 
5
- Out of the box, SimpleDiscussion comes with styling for Boostrap v4 but you're free to customize the UI as much as you like by installing the views and tweaking the HTML.
5
+ SimpleDiscussion is a Rails forum gem extracting the [GoRails forum](https://gorails.com/forum). It includes categories, simple moderation, the ability to mark threads as solved, and more.
6
+
7
+ Out of the box, SimpleDiscussion comes with styling for Bootstrap v4 but you're free to customize the UI as much as you like by installing the views and tweaking the HTML.
6
8
 
7
9
  [![GoRails Forum](https://d3vv6lp55qjaqc.cloudfront.net/items/3j2p3o1j0d1O0R1w2j1Y/Screen%20Shot%202017-08-08%20at%203.12.01%20PM.png?X-CloudApp-Visitor-Id=51470&v=d439dcae)](https://d3vv6lp55qjaqc.cloudfront.net/items/3j2p3o1j0d1O0R1w2j1Y/Screen%20Shot%202017-08-08%20at%203.12.01%20PM.png?X-CloudApp-Visitor-Id=51470&v=d439dcae)
8
10
 
data/Rakefile CHANGED
@@ -1,10 +1,32 @@
1
+ begin
2
+ require "bundler/setup"
3
+ rescue LoadError
4
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
+ end
6
+
1
7
  require "bundler/gem_tasks"
8
+
9
+ require "rdoc/task"
10
+
11
+ RDoc::Task.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = "rdoc"
13
+ rdoc.title = "SimpleDiscussion"
14
+ rdoc.options << "--line-numbers"
15
+ rdoc.rdoc_files.include("README.md")
16
+ rdoc.rdoc_files.include("lib/**/*.rb")
17
+ end
18
+
19
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
20
+ load "rails/tasks/engine.rake"
21
+
22
+ load "rails/tasks/statistics.rake"
23
+
2
24
  require "rake/testtask"
3
25
 
4
26
  Rake::TestTask.new(:test) do |t|
5
27
  t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
28
+ t.pattern = "test/**/*_test.rb"
29
+ t.verbose = false
8
30
  end
9
31
 
10
- task :default => :test
32
+ task default: :test
@@ -20,8 +20,28 @@
20
20
 
21
21
  /* Formatting for the forum threads */
22
22
  .forum-thread {
23
- h4 a {
24
- color: #222;
23
+ margin-bottom: -20px;
24
+
25
+ h4 {
26
+ margin-bottom: 4px;
27
+
28
+ a {
29
+ color: #222;
30
+ font-size: 16px;
31
+ font-weight: normal;
32
+ line-height: 1.1;
33
+ }
34
+ }
35
+ }
36
+
37
+ .forum-thread-filters a {
38
+ color: #555555;
39
+ display: block;
40
+
41
+ &:hover {
42
+ color: #222222;
43
+ font-weight: bold;
44
+ text-decoration: none
25
45
  }
26
46
  }
27
47
 
@@ -45,6 +65,11 @@
45
65
  font-weight: 300;
46
66
  line-height: 1em;
47
67
  }
68
+
69
+ &:hover {
70
+ color: #222;
71
+ text-decoration: none;
72
+ }
48
73
  }
49
74
 
50
75
  /* Formatting for the forum posts themselves */
@@ -64,3 +89,16 @@
64
89
  border: 2px solid #5cb85c;
65
90
  }
66
91
  }
92
+
93
+ /* Formatting for the forum hr to match card border */
94
+ .simple_discussion hr {
95
+ border: 0;
96
+ border-top: 1px solid rgba(0, 0, 0, 0.125);
97
+ margin: 24px -20px;
98
+ }
99
+
100
+ .simple_discussion .text-muted {
101
+ color: #999;
102
+ margin-top: 6px;
103
+ font-size: 13px;
104
+ }
@@ -2,7 +2,7 @@ class SimpleDiscussion::ApplicationController < ::ApplicationController
2
2
  layout "simple_discussion"
3
3
 
4
4
  def page_number
5
- page = params.fetch(:page, '').gsub(/[^0-9]/, '').to_i
5
+ page = params.fetch(:page, "").gsub(/[^0-9]/, "").to_i
6
6
  page = "1" if page.zero?
7
7
  page
8
8
  end
@@ -17,9 +17,21 @@ class SimpleDiscussion::ApplicationController < ::ApplicationController
17
17
  end
18
18
  helper_method :is_moderator?
19
19
 
20
- def require_moderator_or_author!
20
+ def require_mod_or_author_for_post!
21
+ unless is_moderator_or_owner?(@forum_post)
22
+ redirect_to_root
23
+ end
24
+ end
25
+
26
+ def require_mod_or_author_for_thread!
21
27
  unless is_moderator_or_owner?(@forum_thread)
22
- redirect_to simple_discussion.root_path, alert: "You aren't allowed to do that."
28
+ redirect_to_root
23
29
  end
24
30
  end
31
+
32
+ private
33
+
34
+ def redirect_to_root
35
+ redirect_to simple_discussion.root_path, alert: "You aren't allowed to do that."
36
+ end
25
37
  end
@@ -9,9 +9,9 @@ class SimpleDiscussion::ForumCategoriesController < SimpleDiscussion::Applicatio
9
9
 
10
10
  private
11
11
 
12
- def set_category
13
- @category = ForumCategory.friendly.find(params[:id])
14
- rescue ActiveRecord::RecordNotFound
15
- redirect_to simple_discussion.forum_threads_path
16
- end
12
+ def set_category
13
+ @category = ForumCategory.friendly.find(params[:id])
14
+ rescue ActiveRecord::RecordNotFound
15
+ redirect_to simple_discussion.forum_threads_path
16
+ end
17
17
  end
@@ -1,8 +1,9 @@
1
1
  class SimpleDiscussion::ForumPostsController < SimpleDiscussion::ApplicationController
2
2
  before_action :authenticate_user!
3
3
  before_action :set_forum_thread
4
- before_action :set_forum_post, only: [:edit, :update]
5
- before_action :require_moderator_or_author!, only: [:edit, :update, :solved, :unsolved]
4
+ before_action :set_forum_post, only: [:edit, :update, :destroy]
5
+ before_action :require_mod_or_author_for_post!, only: [:edit, :update, :destroy]
6
+ before_action :require_mod_or_author_for_thread!, only: [:solved, :unsolved]
6
7
 
7
8
  def create
8
9
  @forum_post = @forum_thread.forum_posts.new(forum_post_params)
@@ -27,6 +28,11 @@ class SimpleDiscussion::ForumPostsController < SimpleDiscussion::ApplicationCont
27
28
  end
28
29
  end
29
30
 
31
+ def destroy
32
+ @forum_post.destroy!
33
+ redirect_to simple_discussion.forum_thread_path(@forum_thread)
34
+ end
35
+
30
36
  def solved
31
37
  @forum_post = @forum_thread.forum_posts.find(params[:id])
32
38
 
@@ -48,19 +54,19 @@ class SimpleDiscussion::ForumPostsController < SimpleDiscussion::ApplicationCont
48
54
 
49
55
  private
50
56
 
51
- def set_forum_thread
52
- @forum_thread = ForumThread.friendly.find(params[:forum_thread_id])
53
- end
57
+ def set_forum_thread
58
+ @forum_thread = ForumThread.friendly.find(params[:forum_thread_id])
59
+ end
54
60
 
55
- def set_forum_post
56
- if is_moderator?
57
- @forum_post = @forum_thread.forum_posts.find(params[:id])
58
- else
59
- @forum_post = current_user.forum_posts.find(params[:id])
60
- end
61
+ def set_forum_post
62
+ @forum_post = if is_moderator?
63
+ @forum_thread.forum_posts.find(params[:id])
64
+ else
65
+ current_user.forum_posts.find(params[:id])
61
66
  end
67
+ end
62
68
 
63
- def forum_post_params
64
- params.require(:forum_post).permit(:body)
65
- end
69
+ def forum_post_params
70
+ params.require(:forum_post).permit(:body)
71
+ end
66
72
  end
@@ -1,7 +1,7 @@
1
1
  class SimpleDiscussion::ForumThreadsController < SimpleDiscussion::ApplicationController
2
2
  before_action :authenticate_user!, only: [:mine, :participating, :new, :create]
3
3
  before_action :set_forum_thread, only: [:show, :edit, :update]
4
- before_action :require_moderator_or_author!, only: [:edit, :update]
4
+ before_action :require_mod_or_author_for_thread!, only: [:edit, :update]
5
5
 
6
6
  def index
7
7
  @forum_threads = ForumThread.pinned_first.sorted.includes(:user, :forum_category).paginate(page: page_number)
@@ -23,7 +23,7 @@ class SimpleDiscussion::ForumThreadsController < SimpleDiscussion::ApplicationCo
23
23
  end
24
24
 
25
25
  def participating
26
- @forum_threads = ForumThread.includes(:user, :forum_category).joins(:forum_posts).where(forum_posts: { user_id: current_user.id }).distinct(forum_posts: :id).sorted.paginate(page: page_number)
26
+ @forum_threads = ForumThread.includes(:user, :forum_category).joins(:forum_posts).where(forum_posts: {user_id: current_user.id}).distinct(forum_posts: :id).sorted.paginate(page: page_number)
27
27
  render action: :index
28
28
  end
29
29
 
@@ -39,7 +39,7 @@ class SimpleDiscussion::ForumThreadsController < SimpleDiscussion::ApplicationCo
39
39
 
40
40
  def create
41
41
  @forum_thread = current_user.forum_threads.new(forum_thread_params)
42
- @forum_thread.forum_posts.each{ |post| post.user_id = current_user.id }
42
+ @forum_thread.forum_posts.each { |post| post.user_id = current_user.id }
43
43
 
44
44
  if @forum_thread.save
45
45
  SimpleDiscussion::ForumThreadNotificationJob.perform_later(@forum_thread)
@@ -54,7 +54,7 @@ class SimpleDiscussion::ForumThreadsController < SimpleDiscussion::ApplicationCo
54
54
 
55
55
  def update
56
56
  if @forum_thread.update(forum_thread_params)
57
- redirect_to simple_discussion.forum_thread_path(@forum_thread), notice: "Your changes were saved."
57
+ redirect_to simple_discussion.forum_thread_path(@forum_thread), notice: I18n.t("your_changes_were_saved")
58
58
  else
59
59
  render action: :edit
60
60
  end
@@ -62,11 +62,11 @@ class SimpleDiscussion::ForumThreadsController < SimpleDiscussion::ApplicationCo
62
62
 
63
63
  private
64
64
 
65
- def set_forum_thread
66
- @forum_thread = ForumThread.friendly.find(params[:id])
67
- end
65
+ def set_forum_thread
66
+ @forum_thread = ForumThread.friendly.find(params[:id])
67
+ end
68
68
 
69
- def forum_thread_params
70
- params.require(:forum_thread).permit(:title, :forum_category_id, forum_posts_attributes: [:body])
71
- end
69
+ def forum_thread_params
70
+ params.require(:forum_thread).permit(:title, :forum_category_id, forum_posts_attributes: [:body])
71
+ end
72
72
  end
@@ -13,7 +13,7 @@ class SimpleDiscussion::NotificationsController < SimpleDiscussion::ApplicationC
13
13
 
14
14
  private
15
15
 
16
- def set_forum_thread
17
- @forum_thread = ForumThread.friendly.find(params[:forum_thread_id])
18
- end
16
+ def set_forum_thread
17
+ @forum_thread = ForumThread.friendly.find(params[:forum_thread_id])
18
+ end
19
19
  end
@@ -1,7 +1,7 @@
1
1
  module SimpleDiscussion::ForumPostsHelper
2
2
  # Override this to use avatars from other places than Gravatar
3
3
  def avatar_tag(email)
4
- gravatar_image_tag(email, gravatar: { size: 40 }, class: "rounded avatar")
4
+ image_tag gravatar_url_for(email, size: 40), class: "rounded avatar"
5
5
  end
6
6
 
7
7
  def category_link(category)
@@ -26,4 +26,10 @@ module SimpleDiscussion::ForumPostsHelper
26
26
  content_tag :span, "Mod", class: "badge badge-default"
27
27
  end
28
28
  end
29
+
30
+ def gravatar_url_for(email, **options)
31
+ hash = Digest::MD5.hexdigest(email&.downcase || "")
32
+ options.reverse_merge!(default: :mp, rating: :pg, size: 48)
33
+ "https://secure.gravatar.com/avatar/#{hash}.png?#{options.to_param}"
34
+ end
29
35
  end
@@ -1,13 +1,13 @@
1
1
  module SimpleDiscussion::ForumThreadsHelper
2
2
  # Used for flagging links in the navbar as active
3
- def forum_link_to(path, opts={}, &block)
3
+ def forum_link_to(path, opts = {}, &block)
4
4
  link_to path, class: forum_link_class(path, opts), &block
5
5
  end
6
6
 
7
- def forum_link_class(matches, opts={})
7
+ def forum_link_class(matches, opts = {})
8
8
  case matches
9
9
  when Array
10
- "active" if matches.any?{ |m| request.path.starts_with?(m) }
10
+ "active" if matches.any? { |m| request.path.starts_with?(m) }
11
11
  when String
12
12
  "active" if opts.fetch(:exact, false) ? request.path == matches : request.path.starts_with?(matches)
13
13
  end
@@ -22,7 +22,7 @@ module SimpleDiscussion::ForumThreadsHelper
22
22
  #
23
23
  def parent_layout(layout)
24
24
  @view_flow.set(:layout, output_buffer)
25
- output = render(file: "layouts/#{layout}")
25
+ output = render(template: "layouts/#{layout}")
26
26
  self.output_buffer = ActionView::OutputBuffer.new(output)
27
27
  end
28
28
  end