config/initializers/commontator.rb in commontator-5.1.0 vs config/initializers/commontator.rb in commontator-6.0.0.pre.1
- old
+ new
@@ -1,34 +1,32 @@
# Change the settings below to suit your needs
# All settings are initially set to their default values
-
-# Note: Do not "return" from a Proc, use "next" instead if necessary
Commontator.configure do |config|
# Engine Configuration
# current_user_proc
# Type: Proc
- # Arguments: the current controller (ActionController::Base)
+ # Arguments: the current controller (ActionController::Base) or view (ActionView::Base)
# Returns: the current user (acts_as_commontator)
# The default works for Devise and similar authentication plugins
- # Default: ->(controller) { controller.current_user }
- config.current_user_proc = ->(controller) { controller.current_user }
+ # If you define your own custom method, make sure it is accessible to all controllers and views
+ # by adding the method and a call to helper_method to ActionController::Base
+ # Default: ->(context) { context.current_user }
+ config.current_user_proc = ->(context) { context.current_user }
# javascript_proc
# Type: Proc
# Arguments: a view (ActionView::Base)
- # Returns: a String that is appended to Commontator JS views
- # Can be used, for example, to display/clear Rails error messages
- # or to reapply JQuery UI styles after Ajax calls
+ # Returns: a String that is appended to all Commontator JS views
+ # Can be used, for example, to reapply JQuery UI styles after Ajax calls
# Objects visible in view templates can be accessed
# through the view object (for example, view.flash)
# However, the view does not include the main application's helpers
- # Default: ->(view) { '$("#error_explanation").remove();' }
- config.javascript_proc = ->(view) { '$("#error_explanation").remove();' }
+ # Default: ->(view) { '' }
+ config.javascript_proc = ->(view) { '' }
-
# User (acts_as_commontator) Configuration
# user_name_proc
# Type: Proc
# Arguments: a user (acts_as_commontator)
@@ -48,25 +46,26 @@
config.user_link_proc = ->(user, app_routes) { '' }
# user_avatar_proc
# Type: Proc
# Arguments: a user (acts_as_commontator), a view (ActionView::Base)
- # Returns: a String containing a HTML <img> tag pointing to the user's avatar image
- # The commontator_gravatar_image_tag helper takes a user object,
+ # Returns: a String containing an HTML <img> tag pointing to the user's avatar image
+ # The optional commontator_gravatar_image_tag helper takes a user object,
# a border size and an options hash for Gravatar, and produces a Gravatar image tag
- # See available options at http://en.gravatar.com/site/implement/images/)
+ # See available options at https://en.gravatar.com/site/implement/images/)
# Note: Gravatar has several security implications for your users
# It makes your users trackable across different sites and
# allows de-anonymization attacks against their email addresses
# If you absolutely want to keep users' email addresses or identities secret,
# do not use Gravatar or similar services
- # Default: ->(user, view) {
- # view.commontator_gravatar_image_tag(user, 1, s: 60, d: 'mm')
- # }
- config.user_avatar_proc = ->(user, view) {
- view.commontator_gravatar_image_tag(user, 1, s: 60, d: 'mm')
- }
+ # If you are sure you want to use Gravatar, uncomment the command inside the block.
+ # Default: ->(user, view) do
+ # # view.commontator_gravatar_image_tag(user, 1, s: 60, d: 'mm')
+ # end
+ config.user_avatar_proc = ->(user, view) do
+ # view.commontator_gravatar_image_tag(user, 1, s: 60, d: 'mm')
+ end
# user_email_proc
# Type: Proc
# Arguments: a user (acts_as_commontator), a mailer (ActionMailer::Base)
# Returns: the user's email address (String)
@@ -76,10 +75,33 @@
# If the mailer argument is not nil, then Commontator intends to send an email to
# the address returned; you can prevent it from being sent by returning a blank String
# Default: ->(user, mailer) { user.try(:email) || '' }
config.user_email_proc = ->(user, mailer) { user.try(:email) || '' }
+ # user_mentions_proc
+ # Type: Proc
+ # Arguments:
+ # the current user (acts_as_commontator)
+ # the current thread (Commontator::Thread)
+ # the search query inputted by user (String)
+ # Returns: an ActiveRecord Relation object
+ # Important notes:
+ #
+ # - This proc is only used if you enable mentions (see config below)
+ #
+ # - The proc will be called internally with an empty search string.
+ # In that case, it MUST return all users that can be mentioned.
+ #
+ # - With mentions enabled, any registered user in your app is able
+ # to call this proc with any search query >= 3 characters.
+ # Make sure to handle SQL escaping properly and that the
+ # attribute being searched does not contain sensitive information.
+ #
+ # Default: ->(current_user, query) { current_user.class.where('username LIKE ?', "#{query}%") }
+ config.user_mentions_proc = ->(current_user, thread, query) do
+ current_user.class.where('username LIKE ?', "#{query}%")
+ end
# Thread/Commontable (acts_as_commontable) Configuration
# comment_filter
@@ -142,28 +164,30 @@
config.moderator_permissions = :d
# comment_voting
# Type: Symbol
# Whether users can vote on other users' comments
+ # Any option other than :n requires the acts_as_votable gem
# Valid options:
# :n (no voting)
- # :l (likes - requires acts_as_votable gem)
- # :ld (likes/dislikes - requires acts_as_votable gem)
- # Not yet implemented:
- # :s (star ratings)
- # :r (reputation system)
+ # :l (likes)
+ # :ld (likes/dislikes)
# Default: :n
config.comment_voting = :n
# vote_count_proc
# Type: Proc
- # Arguments: a thread (Commontator::Thread), pos (Fixnum), neg (Fixnum)
+ # Arguments: a thread (Commontator::Thread), pos (Integer), neg (Integer)
# Returns: vote count to be displayed (String)
# pos is the number of likes, or the rating, or the reputation
# neg is the number of dislikes, if applicable, or 0 otherwise
- # Default: ->(thread, pos, neg) { "%+d" % (pos - neg) }
- config.vote_count_proc = ->(thread, pos, neg) { "%+d" % (pos - neg) }
+ # Default: ->(thread, pos, neg) do
+ # ((thread.config.comment_voting == :ld ? '%+d' : '%d') % (pos - neg)).sub('+0', '0')
+ # end
+ config.vote_count_proc = ->(thread, pos, neg) do
+ ((thread.config.comment_voting == :ld ? '%+d' : '%d') % (pos - neg)).sub('+0', '0')
+ end
# comment_order
# Type: Symbol
# What order to use for comments
# Valid options:
@@ -190,12 +214,24 @@
# Not yet implemented:
# :n (link to the form; opens in a new window)
# Default: :l
config.new_comment_style = :l
+ # comment_reply_style
+ # Type: Symbol
+ # How to handle replies to comments
+ # Valid options:
+ # :n (no replies, though users can still manually add <blockquote>s)
+ # :q (copies the comment being replied to into a <blockquote>)
+ # Not yet implemented:
+ # :i (indents each reply under the comment being replied to)
+ # It might be a good idea to add some CSS to hide <blockquote>s when converting from :q to :i
+ # Default: :n
+ config.comment_reply_style = :n
+
# comments_per_page
- # Type: Fixnum or nil
+ # Type: Integer or nil
# Number of comments to display in each page
# Set to nil to disable pagination
# Any other value requires the will_paginate gem
# Default: nil (no pagination)
config.comments_per_page = nil
@@ -214,71 +250,49 @@
# email_from_proc
# Type: Proc
# Arguments: a thread (Commontator::Thread)
# Returns: the address emails are sent "from" (String)
# Important: If using subscriptions, change this to at least match your domain name
- # Default: ->(thread) {
+ # Default: ->(thread) do
# "no-reply@#{Rails.application.class.parent.to_s.downcase}.com"
- # }
- config.email_from_proc = ->(thread) {
+ # end
+ config.email_from_proc = ->(thread) do
"no-reply@#{Rails.application.class.parent.to_s.downcase}.com"
- }
+ end
# commontable_name_proc
# Type: Proc
# Arguments: a thread (Commontator::Thread)
# Returns: a name that refers to the commontable object (String)
# If you have multiple commontable models, you can also pass this
# configuration value as an argument to acts_as_commontable for each one
- # Default: ->(thread) {
- # "#{thread.commontable.class.name} ##{thread.commontable.id}" }
- config.commontable_name_proc = ->(thread) {
- "#{thread.commontable.class.name} ##{thread.commontable.id}" }
+ # Default: ->(thread) do
+ # "#{thread.commontable.class.name} ##{thread.commontable.id}"
+ # end
+ config.commontable_name_proc = ->(thread) do
+ "#{thread.commontable.class.name} ##{thread.commontable.id}"
+ end
# comment_url_proc
# Type: Proc
# Arguments: a comment (Commontator::Comment),
# the app_routes (ActionDispatch::Routing::RoutesProxy)
# Returns: a String containing the url of the view that displays the given comment
# This usually is the commontable's "show" page
# The main application's routes can be accessed through the app_routes object
- # Default: ->(comment, app_routes) {
- # app_routes.polymorphic_url(comment.thread.commontable, anchor: "comment_#{comment.id}_div")
- # }
+ # Default: ->(comment, app_routes) do
+ # app_routes.polymorphic_url(comment.thread.commontable, anchor: "comment-#{comment.id}-div")
+ # end
# (defaults to the commontable's show url with an anchor pointing to the comment's div)
- config.comment_url_proc = ->(comment, app_routes) {
- app_routes.polymorphic_url(comment.thread.commontable, anchor: "comment_#{comment.id}_div")
- }
+ config.comment_url_proc = ->(comment, app_routes) do
+ app_routes.polymorphic_url(comment.thread.commontable, anchor: "comment-#{comment.id}-div")
+ end
# mentions_enabled
# Type: Boolean
# Whether users can mention other users to subscribe them to the thread
# Valid options:
# false (no mentions)
# true (mentions enabled)
# Default: false
config.mentions_enabled = false
-
- # user_mentions_proc
- # Type: Proc
- # Arguments:
- # the current user (acts_as_commontator)
- # the current thread (Commontator::Thread)
- # the search query inputted by user (String)
- # Returns: an ActiveRecord Relation object
- # Important notes:
- #
- # - The proc will be called internally with an empty search string.
- # In that case, it MUST return all users that can be mentioned.
- #
- # - With mentions enabled, any registered user in your app is able
- # to call this proc with any search query >= 3 characters.
- # Make sure to handle SQL escaping properly and that the
- # attribute being searched does not contain sensitive information.
- #
- # Default: ->(current_user, query) {
- # current_user.class.where('username LIKE ?', "#{query}%")
- # }
- config.user_mentions_proc = ->(current_user, thread, query) {
- current_user.class.where('username LIKE ?', "#{query}%")
- }
end