From 267b5615c9857c24d0cf9a9a5bf64ddfaac02336 Mon Sep 17 00:00:00 2001 From: Waishnav Date: Thu, 22 Aug 2024 23:52:00 +0530 Subject: [PATCH 1/4] feat: improvise documentation --- README.md | 231 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 148 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index e07c58b..95acdbf 100644 --- a/README.md +++ b/README.md @@ -1,160 +1,225 @@ -# SimpleDiscussion - Forum engine for Ruby on Rails +# SimpleDiscussion - A Powerful Forum Engine for Ruby on Rails -[![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) +[![Build Status](https://github.com/circuitverse/simple_discussion/workflows/Tests/badge.svg)](https://github.com/circuitverse/simple_discussion/actions) [![Gem Version](https://badge.fury.io/rb/simple_discussion.svg)](https://badge.fury.io/rb/simple_discussion) -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. +SimpleDiscussion is a comprehensive Rails forum gem, inspired by the [GoRails forum](https://gorails.com/forum). It is being used in production by CircuitVerse currently. You can check it out [here](https://circuitverse.org/forum). It offers a rich set of features including categories, markdown editor like GitHub, moderation tools, solved thread marking, and more. -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. +## Key Features -[![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) +- Markdown editor for posts and threads +- Category organization +- Simple moderation system +- Spam reporting and moderation tools +- Ability to mark threads as solved +- Topic search functionality +- Email and Slack notifications +- Customizable styling (Bootstrap v4 compatible out-of-the-box) + +![GoRails Forum Screenshot](https://d3vv6lp55qjaqc.cloudfront.net/items/3j2p3o1j0d1O0R1w2j1Y/Screen%20Shot%202017-08-08%20at%203.12.01%20PM.png?X-CloudApp-Visitor-Id=51470&v=d439dcae) + +## Table of Contents + +1. [Installation](#installation) +2. [Configuration](#configuration) +3. [Usage](#usage) +4. [Customization](#customization) +5. [Advanced Features](#advanced-features) + - [Markdown Editor](#markdown-editor) + - [Profanity Checks and Language Filter](#profanity-check-and-language-filter) + - [Topic Search](#topic-search) + - [Slack and Email Notifications](#slack-and-email-notifications) +6. [Development](#development) +7. [Contributing](#contributing) +8. [License](#license) +9. [Code of Conduct](#code-of-conduct) ## Installation -Before you get started, SimpleDiscussion requires a `User` model in your application (for now). +1. Add SimpleDiscussion to your Gemfile: -Add this line to your application's Gemfile: + ```ruby + gem 'simple_discussion' + ``` -```ruby -gem 'simple_discussion' -``` +2. Install the gem: -And then execute: + ```bash + bundle install + ``` -```bash -bundle -``` +3. Install and run migrations: -Install the migrations and migrate: + ```bash + rails simple_discussion:install:migrations + rails db:migrate + ``` -```bash -rails simple_discussion:install:migrations -rails db:migrate -``` +4. Mount the engine in `config/routes.rb`: -Add SimpleDiscussion to your `User` model. The model **must** have `name` method which will be used to display the user's name on the forum. Currently only a model named `User` will work, but this will be fixed shortly. + ```ruby + mount SimpleDiscussion::Engine => "/forum" + ``` -```ruby -class User < ActiveRecord::Base - include SimpleDiscussion::ForumUser +5. Add the CSS to your `application.css`: - def name - "#{first_name} #{last_name}" - end -end -``` + ```scss + *= require simple_discussion + ``` -Optionally, you can add a `moderator` flag to the `User` model to allow users to edit threads and posts they didn't write. +## Configuration -```bash -rails g migration AddModeratorToUsers moderator:boolean -rails db:migrate -``` +1. Include SimpleDiscussion in your `User` model: -Add the following line to your `config/routes.rb` file: + ```ruby + class User < ApplicationRecord + include SimpleDiscussion::ForumUser + + def name + "#{first_name} #{last_name}" + end + end + ``` + +2. (Optional) Add a moderator flag to your `User` model: + + ```bash + rails g migration AddModeratorToUsers moderator:boolean + rails db:migrate + ``` + +3. Create an initializer file `config/initializers/simple_discussion.rb`: ```ruby -mount SimpleDiscussion::Engine => "/forum" -``` +SimpleDiscussion.setup do |config| + config.profanity_filter = true # Default: true + config.topic_search = true # Default: false -Lastly, add the CSS to your `application.css` to load some default styles. + config.markdown_editor= true # Default: true + config.markdown_circuit_embed = false # Default: true + config.markdown_user_tagging = false # Default: true + config.markdown_video_embed = false # Default: true -```scss -*= require simple_discussion + config.send_email_notifications = true # Default: true + config.send_slack_notifications = false # Default: true + +end ``` ## Usage -To get all the basic functionality, the only thing you need to do is add a link to SimpleDiscussion in your navbar. +Add a link to the forum in your application's navbar: ```erb <%= link_to "Forum", simple_discussion_path %> ``` -This will take the user to the views inside the Rails engine and that's all you have to do! +## Customization -### Customizing All The Things! +### Styling + +To customize colors, create `simple_discussion_override_color.scss`: -If you'd like to customize the color schemas , then you can follow these steps -- Create an scss file [simple_discussion_override_color.scss] and add the following code to it ```scss -// Colors of the button is depend on this brand-color -$brand-color: #42b983; -// Color for icon and text of `Closed` / `solved` tag -$thread-solved-color: #42b983; -// Color for icon and text of `Opened` / `Unsolved` tag -$thread-unsolved-color: #f29d38; -// Button background color for primary buttons +$brand-color: #42b983; +$thread-solved-color: #42b983; +$thread-unsolved-color: #f29d38; $button-background-color: #fff; -// Shadown color when hovering over the buttons -$button-hover-shadow-color: rgba(77, 219, 155, .5); -// active links color +$button-hover-shadow-color: rgba(77, 219, 155, .5); $link-active-color: #000; -// inactive links color $link-inactive-color: #555; -// Color for thread filter buttons on hover $forum-thread-filter-btn-link-hover-background: #f3f4f6; ``` -- Add the scss file to application.scss. - > Note : Make sure that the file is imported before the simple_discussion.scss file + +Import this file before `simple_discussion` in your `application.scss`: + ```scss -... -@import 'simple_discussion_override_color.scss'; +@import 'simple_discussion_override_color'; @import 'simple_discussion'; -... ``` -- Now, you can customize the colors, as per your need -If you'd like to customize the views that SimpleDiscussion uses, you can install the views to your Rails app: +### Views and Controllers + +To customize views or controllers: ```bash rails g simple_discussion:views +rails g simple_discussion:controllers +rails g simple_discussion:helpers ``` -You can also install a copy of the SimpleDiscussion controllers for advanced customization: +## Advanced Features -```bash -rails g simple_discussion:controllers +### Markdown Editor + +By default markdown editor for drafting forum post and forum threads is enable. You can disable it like this. + +```ruby +SimpleDiscussion.setup do |config| + config.markdown_editor = false # Default: true +end ``` -Helpers are available for override as well. They are used for rendering the user avatars, text formatting, and more. +Also we have introduced the markdown extension to embed the CircuitVerse Circuits, YouTube video, User tagging for CircuitVerse usecase. +You can toggle these features as well using following config. -```bash -rails g simple_discussion:helpers +```ruby +SimpleDiscussion.setup do |config| + config.markdown_circuit_embed = false # Default: true + config.markdown_user_tagging = false # Default: true + config.markdown_video_embed = false # Default: true +end ``` +### Profanity Check and Language Filter -**NOTE:** Keep in mind that the more customization you do, the tougher gem upgrades will be in the future. +By default profanity check is enabled you can disable it from your initilizer file: + +```ruby +SimpleDiscussion.setup do |config| + config.profanity_filter = true # Default: true +end +``` -### Email And Slack Notifications +### Topic Search -By default, SimpleDiscussion will attempt to send email and slack notifications for users subscribed to threads. To turn these off you can do the following in `config/initializers/simple_discussion.rb` +Enable topic search in the initializer: ```ruby SimpleDiscussion.setup do |config| - config.send_email_notifications = false # Default: true - config.send_slack_notifications = false # Default: true + config.topic_search = true # Default: true +end +``` - config.markdown_circuit_embed = false # Default: false - config.markdown_user_tagging = false # Default: false - config.markdown_video_embed = false # Default false +Implement the `topic_search` helper method in your rails application: + +Following is the example implementation of `topic_search` helper, You can go as complex as you want. You can introduce ElasticSearch, MilliSerach or Postgres's FTS. +```ruby +def topic_search(query) + ForumThread.joins(:forum_posts) + .where("forum_threads.title LIKE :query OR forum_posts.body LIKE :query", query: "%#{query}%") + .distinct end ``` -Slack notifications require you to set `simple_discussion_slack_url` in your `config/secrets.yml`. If you don't have this value set, it will not attempt Slack notifications even if they are enabled. +### Slack and Email Notifications + +Configure email and Slack notifications in the initializer. For Slack, set `simple_discussion_slack_url` in `config/secrets.yml`. ## Development -After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. +To set up the development environment: -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). +1. Check out the repo +2. Run `bin/setup` to install dependencies +3. Run `rake test` to run the tests ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/excid3/simple_discussion. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. +We welcome bug reports and pull requests on GitHub at https://github.com/excid3/simple_discussion. Please adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. ## License -The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). +This gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). ## Code of Conduct -Everyone interacting in the SimpleDiscussion project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/excid3/simple_discussion/blob/master/CODE_OF_CONDUCT.md). +All contributors are expected to follow our [code of conduct](https://github.com/excid3/simple_discussion/blob/master/CODE_OF_CONDUCT.md). From baa957d9b0ac618fb987e5984d1491e74809aab2 Mon Sep 17 00:00:00 2001 From: Waishnav Date: Fri, 23 Aug 2024 01:26:23 +0530 Subject: [PATCH 2/4] fix: repeatation in readme --- README.md | 60 ++++++++++++++++--------------------------------------- 1 file changed, 17 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 95acdbf..66893c8 100644 --- a/README.md +++ b/README.md @@ -87,24 +87,23 @@ SimpleDiscussion is a comprehensive Rails forum gem, inspired by the [GoRails fo rails db:migrate ``` -3. Create an initializer file `config/initializers/simple_discussion.rb`: +3. (Optional) Create an initializer file `config/initializers/simple_discussion.rb`. Using this file, you can toggle these [advanced features](#advanced-features) using the following flags. -```ruby -SimpleDiscussion.setup do |config| - config.profanity_filter = true # Default: true - config.topic_search = true # Default: false - - config.markdown_editor= true # Default: true - config.markdown_circuit_embed = false # Default: true - config.markdown_user_tagging = false # Default: true - config.markdown_video_embed = false # Default: true + ```ruby + SimpleDiscussion.setup do |config| + config.profanity_filter = true # Default: true + config.topic_search = true # Default: false - config.send_email_notifications = true # Default: true - config.send_slack_notifications = false # Default: true + config.markdown_editor= true # Default: true + config.markdown_circuit_embed = false # Default: true + config.markdown_user_tagging = false # Default: true + config.markdown_video_embed = false # Default: true -end -``` + config.send_email_notifications = true # Default: true + config.send_slack_notifications = false # Default: true + end + ``` ## Usage Add a link to the forum in your application's navbar: @@ -151,43 +150,18 @@ rails g simple_discussion:helpers ### Markdown Editor -By default markdown editor for drafting forum post and forum threads is enable. You can disable it like this. - -```ruby -SimpleDiscussion.setup do |config| - config.markdown_editor = false # Default: true -end -``` +By Markdown editor for drafting forum post and forum threads is enable. You can disable it from initilizer file. Also we have introduced the markdown extension to embed the CircuitVerse Circuits, YouTube video, User tagging for CircuitVerse usecase. -You can toggle these features as well using following config. +You can toggle these features as well using following feature flags. -```ruby -SimpleDiscussion.setup do |config| - config.markdown_circuit_embed = false # Default: true - config.markdown_user_tagging = false # Default: true - config.markdown_video_embed = false # Default: true -end -``` ### Profanity Check and Language Filter -By default profanity check is enabled you can disable it from your initilizer file: - -```ruby -SimpleDiscussion.setup do |config| - config.profanity_filter = true # Default: true -end -``` +By default profanity check and language filter on forum post is enable, you can disable it from your initilizer file. ### Topic Search -Enable topic search in the initializer: - -```ruby -SimpleDiscussion.setup do |config| - config.topic_search = true # Default: true -end -``` +Enable topic search from the initializer file: Implement the `topic_search` helper method in your rails application: From fe9c6dba12bd9c99f623d03255c9ec27e56c45ec Mon Sep 17 00:00:00 2001 From: Waishnav Date: Sat, 24 Aug 2024 16:37:02 +0530 Subject: [PATCH 3/4] fix: doc for topic search changed --- README.md | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 66893c8..918a2f7 100644 --- a/README.md +++ b/README.md @@ -92,9 +92,7 @@ SimpleDiscussion is a comprehensive Rails forum gem, inspired by the [GoRails fo ```ruby SimpleDiscussion.setup do |config| config.profanity_filter = true # Default: true - config.topic_search = true # Default: false - config.markdown_editor= true # Default: true config.markdown_circuit_embed = false # Default: true config.markdown_user_tagging = false # Default: true config.markdown_video_embed = false # Default: true @@ -150,9 +148,7 @@ rails g simple_discussion:helpers ### Markdown Editor -By Markdown editor for drafting forum post and forum threads is enable. You can disable it from initilizer file. - -Also we have introduced the markdown extension to embed the CircuitVerse Circuits, YouTube video, User tagging for CircuitVerse usecase. +Markdown Editor for drafting forum post and forum thread will be shown by default. but also we have introduced the markdown extension to embed the CircuitVerse Circuits, YouTube video, User tagging for CircuitVerse usecase. You can toggle these features as well using following feature flags. ### Profanity Check and Language Filter @@ -161,16 +157,25 @@ By default profanity check and language filter on forum post is enable, you can ### Topic Search -Enable topic search from the initializer file: - -Implement the `topic_search` helper method in your rails application: +By defualt, we have basic implementation for the search across the forum thread. -Following is the example implementation of `topic_search` helper, You can go as complex as you want. You can introduce ElasticSearch, MilliSerach or Postgres's FTS. +Following is the basic implementation of `search` method on our ForumThread model, You can go as complex as you want and introduce ElasticSearch, MilliSerach or Postgres's FTS by overriding the ForumThread Model in your rails application. +```ruby +class ForumThread < ApplicationRecord + def self.search(query) + ForumThread.joins(:forum_posts) + .where("forum_threads.title LIKE :query OR forum_posts.body LIKE :query", query: "%#{query}%") + .distinct + end +end +``` +Override the `ForumThread` Model from your rails application and introduce your search like this. +Note: Make sure you name the method on ForumThread model as `search` ```ruby -def topic_search(query) - ForumThread.joins(:forum_posts) - .where("forum_threads.title LIKE :query OR forum_posts.body LIKE :query", query: "%#{query}%") - .distinct +ForumThread.class_eval do + include PgSearch::Model + pg_search_scope :search, + against: :title end ``` From c612f8ff7c6781cb5d4f7a76259473198a451025 Mon Sep 17 00:00:00 2001 From: Waishnav Date: Sat, 24 Aug 2024 16:48:04 +0530 Subject: [PATCH 4/4] fix: grammer and improved flow of doc --- README.md | 88 ++++++++++++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 918a2f7..4bff8e7 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,49 @@ -# SimpleDiscussion - A Powerful Forum Engine for Ruby on Rails +# SimpleDiscussion: A Powerful Forum Engine for Ruby on Rails [![Build Status](https://github.com/circuitverse/simple_discussion/workflows/Tests/badge.svg)](https://github.com/circuitverse/simple_discussion/actions) [![Gem Version](https://badge.fury.io/rb/simple_discussion.svg)](https://badge.fury.io/rb/simple_discussion) -SimpleDiscussion is a comprehensive Rails forum gem, inspired by the [GoRails forum](https://gorails.com/forum). It is being used in production by CircuitVerse currently. You can check it out [here](https://circuitverse.org/forum). It offers a rich set of features including categories, markdown editor like GitHub, moderation tools, solved thread marking, and more. - -## Key Features - -- Markdown editor for posts and threads -- Category organization -- Simple moderation system -- Spam reporting and moderation tools -- Ability to mark threads as solved -- Topic search functionality -- Email and Slack notifications -- Customizable styling (Bootstrap v4 compatible out-of-the-box) +SimpleDiscussion is a comprehensive Rails forum gem, inspired by the [GoRails forum](https://gorails.com/forum). It's currently in production use by CircuitVerse, which you can see in action [here](https://circuitverse.org/forum). ![GoRails Forum Screenshot](https://d3vv6lp55qjaqc.cloudfront.net/items/3j2p3o1j0d1O0R1w2j1Y/Screen%20Shot%202017-08-08%20at%203.12.01%20PM.png?X-CloudApp-Visitor-Id=51470&v=d439dcae) ## Table of Contents -1. [Installation](#installation) -2. [Configuration](#configuration) -3. [Usage](#usage) -4. [Customization](#customization) -5. [Advanced Features](#advanced-features) - - [Markdown Editor](#markdown-editor) - - [Profanity Checks and Language Filter](#profanity-check-and-language-filter) - - [Topic Search](#topic-search) - - [Slack and Email Notifications](#slack-and-email-notifications) -6. [Development](#development) -7. [Contributing](#contributing) -8. [License](#license) -9. [Code of Conduct](#code-of-conduct) +1. [Features](#features) +2. [Installation](#installation) +3. [Configuration](#configuration) +4. [Usage](#usage) +5. [Customization](#customization) + - [Styling](#styling) + - [Views and Controllers](#views-and-controllers) +6. [Advanced Features](#advanced-features) + - [Markdown Editor](#markdown-editor) + - [Profanity Check and Language Filter](#profanity-check-and-language-filter) + - [Topic Search](#topic-search) + - [Notifications](#notifications) +7. [Development](#development) +8. [Contributing](#contributing) +9. [License](#license) +10. [Code of Conduct](#code-of-conduct) + +## Features + +SimpleDiscussion offers a rich set of features to create a fully-functional forum: + +- **Markdown Editor**: GitHub-like editor for posts and threads +- **Category Organization**: Easily categorize discussions +- **Moderation System**: Simple yet effective moderation tools +- **Spam Reporting**: Allow users to report spam +- **Thread Solving**: Mark threads as solved +- **Topic Search**: Built-in search functionality (can be overridable) +- **Notifications**: Email and Slack notifications +- **Customizable Styling**: Bootstrap v4 compatible out-of-the-box ## Installation 1. Add SimpleDiscussion to your Gemfile: ```ruby - gem 'simple_discussion' + gem 'simple_discussion', github: "CircuitVerse/simple_discussion" ``` 2. Install the gem: @@ -87,21 +92,19 @@ SimpleDiscussion is a comprehensive Rails forum gem, inspired by the [GoRails fo rails db:migrate ``` -3. (Optional) Create an initializer file `config/initializers/simple_discussion.rb`. Using this file, you can toggle these [advanced features](#advanced-features) using the following flags. +3. (Optional) Create an initializer file `config/initializers/simple_discussion.rb`: ```ruby SimpleDiscussion.setup do |config| config.profanity_filter = true # Default: true - config.markdown_circuit_embed = false # Default: true config.markdown_user_tagging = false # Default: true config.markdown_video_embed = false # Default: true - config.send_email_notifications = true # Default: true config.send_slack_notifications = false # Default: true - end ``` + ## Usage Add a link to the forum in your application's navbar: @@ -148,18 +151,16 @@ rails g simple_discussion:helpers ### Markdown Editor -Markdown Editor for drafting forum post and forum thread will be shown by default. but also we have introduced the markdown extension to embed the CircuitVerse Circuits, YouTube video, User tagging for CircuitVerse usecase. -You can toggle these features as well using following feature flags. +The Markdown Editor for drafting forum posts and threads is enabled by default. It includes extensions for embedding CircuitVerse Circuits, YouTube videos, and user tagging. These features can be toggled in the initializer. ### Profanity Check and Language Filter -By default profanity check and language filter on forum post is enable, you can disable it from your initilizer file. +Profanity checking and language filtering on forum posts are enabled by default. You can disable this feature in the initializer file. ### Topic Search -By defualt, we have basic implementation for the search across the forum thread. +A basic implementation for searching across forum threads is included. You can enhance this by overriding the `ForumThread` model in your Rails application: -Following is the basic implementation of `search` method on our ForumThread model, You can go as complex as you want and introduce ElasticSearch, MilliSerach or Postgres's FTS by overriding the ForumThread Model in your rails application. ```ruby class ForumThread < ApplicationRecord def self.search(query) @@ -169,19 +170,12 @@ class ForumThread < ApplicationRecord end end ``` -Override the `ForumThread` Model from your rails application and introduce your search like this. -Note: Make sure you name the method on ForumThread model as `search` -```ruby -ForumThread.class_eval do - include PgSearch::Model - pg_search_scope :search, - against: :title -end -``` -### Slack and Email Notifications +For more advanced search capabilities, you can integrate with ElasticSearch, MilliSearch, or Postgres's FTS. + +### Notifications -Configure email and Slack notifications in the initializer. For Slack, set `simple_discussion_slack_url` in `config/secrets.yml`. +Email and Slack notifications can be configured in the initializer. For Slack notifications, set `simple_discussion_slack_url` in `config/secrets.yml`. ## Development