config/initializers/commontator.rb in commontator-4.11.1 vs config/initializers/commontator.rb in commontator-5.0.0
- old
+ new
@@ -1,54 +1,53 @@
# 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
-# "return" in a lambda is OK
Commontator.configure do |config|
# Engine Configuration
# current_user_proc
# Type: Proc
# Arguments: the current controller (ActionController::Base)
# Returns: the current user (acts_as_commontator)
# The default works for Devise and similar authentication plugins
- # Default: lambda { |controller| controller.current_user }
- config.current_user_proc = lambda { |controller| controller.current_user }
+ # Default: ->(controller) { controller.current_user }
+ config.current_user_proc = ->(controller) { controller.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
# 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: lambda { |view| '$("#error_explanation").remove();' }
- config.javascript_proc = lambda { |view| '$("#error_explanation").remove();' }
+ # Default: ->(view) { '$("#error_explanation").remove();' }
+ config.javascript_proc = ->(view) { '$("#error_explanation").remove();' }
# User (acts_as_commontator) Configuration
# user_name_proc
# Type: Proc
# Arguments: a user (acts_as_commontator)
# Returns: the user's name (String)
- # Default: lambda { |user| I18n.t('commontator.anonymous') } (all users are anonymous)
- config.user_name_proc = lambda { |user| I18n.t('commontator.anonymous') }
+ # Default: ->(user) { I18n.t('commontator.anonymous') } (all users are anonymous)
+ config.user_name_proc = ->(user) { I18n.t('commontator.anonymous') }
# user_link_proc
# Type: Proc
# Arguments: a user (acts_as_commontator),
# the app_routes (ActionDispatch::Routing::RoutesProxy)
# Returns: a path to the user's `show` page (String)
# If anything non-blank is returned, the user's name in comments
# comments will become a hyperlink pointing to this path
# The main application's routes can be accessed through the app_routes object
- # Default: lambda { |user, app_routes| '' } (no link)
- config.user_link_proc = lambda { |user, app_routes| '' }
+ # Default: ->(user, app_routes) { '' } (no link)
+ 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
@@ -58,28 +57,28 @@
# 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: lambda { |user, view|
- # view.commontator_gravatar_image_tag(
- # user, 1, :s => 60, :d => 'mm') }
- config.user_avatar_proc = lambda { |user, view|
- view.commontator_gravatar_image_tag(
- user, 1, :s => 60, :d => 'mm') }
+ # 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')
+ }
# user_email_proc
# Type: Proc
# Arguments: a user (acts_as_commontator), a mailer (ActionMailer::Base)
# Returns: the user's email address (String)
# The default works for Devise's defaults
# If the mailer argument is nil, Commontator intends to hash the email and send the hash
# to Gravatar, so you should always return the user's email address (if using Gravatar)
# 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: lambda { |user, mailer| user.try(:email) || '' }
- config.user_email_proc = lambda { |user, mailer| user.try(:email) || '' }
+ # Default: ->(user, mailer) { user.try(:email) || '' }
+ config.user_email_proc = ->(user, mailer) { user.try(:email) || '' }
# Thread/Commontable (acts_as_commontable) Configuration
@@ -98,20 +97,20 @@
# thread_read_proc
# Type: Proc
# Arguments: a thread (Commontator::Thread), a user (acts_as_commontator)
# Returns: a Boolean, true if and only if the user should be allowed to read that thread
# Note: can be called with a user object that is nil (if they are not logged in)
- # Default: lambda { |thread, user| true } (anyone can read any thread)
- config.thread_read_proc = lambda { |thread, user| true }
+ # Default: ->(thread, user) { true } (anyone can read any thread)
+ config.thread_read_proc = ->(thread, user) { true }
# thread_moderator_proc
# Type: Proc
# Arguments: a thread (Commontator::Thread), a user (acts_as_commontator)
# Returns: a Boolean, true if and only if the user is a moderator for that thread
# If you want global moderators, make this proc true for them regardless of thread
- # Default: lambda { |thread, user| false } (no moderators)
- config.thread_moderator_proc = lambda { |thread, user| false }
+ # Default: ->(thread, user) { false } (no moderators)
+ config.thread_moderator_proc = ->(thread, user) { false }
# comment_editing
# Type: Symbol
# Whether users can edit their own comments
# Valid options:
@@ -159,12 +158,12 @@
# Type: Proc
# Arguments: a thread (Commontator::Thread), pos (Fixnum), neg (Fixnum)
# 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: lambda { |thread, pos, neg| "%+d" % (pos - neg) }
- config.vote_count_proc = lambda { |thread, pos, neg| "%+d" % (pos - neg) }
+ # Default: ->(thread, pos, neg) { "%+d" % (pos - neg) }
+ config.vote_count_proc = ->(thread, pos, neg) { "%+d" % (pos - neg) }
# comment_order
# Type: Symbol
# What order to use for comments
# Valid options:
@@ -215,39 +214,42 @@
# 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: lambda { |thread|
- # "no-reply@#{Rails.application.class.parent.to_s.downcase}.com" }
- config.email_from_proc = lambda { |thread|
- "no-reply@#{Rails.application.class.parent.to_s.downcase}.com" }
+ # Default: ->(thread) {
+ # "no-reply@#{Rails.application.class.parent.to_s.downcase}.com"
+ # }
+ config.email_from_proc = ->(thread) {
+ "no-reply@#{Rails.application.class.parent.to_s.downcase}.com"
+ }
# 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: lambda { |thread|
+ # Default: ->(thread) {
# "#{thread.commontable.class.name} ##{thread.commontable.id}" }
- config.commontable_name_proc = lambda { |thread|
+ config.commontable_name_proc = ->(thread) {
"#{thread.commontable.class.name} ##{thread.commontable.id}" }
# 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: lambda { |comment, app_routes|
- # app_routes.polymorphic_url(comment.thread.commontable,
- # anchor: "comment_#{comment.id}_div") }
+ # Default: ->(comment, app_routes) {
+ # app_routes.polymorphic_url(comment.thread.commontable, anchor: "comment_#{comment.id}_div")
+ # }
# (defaults to the commontable's show url with an anchor pointing to the comment's div)
- config.comment_url_proc = lambda { |comment, app_routes|
- app_routes.polymorphic_url(comment.thread.commontable, anchor: "comment_#{comment.id}_div") }
+ config.comment_url_proc = ->(comment, app_routes) {
+ app_routes.polymorphic_url(comment.thread.commontable, anchor: "comment_#{comment.id}_div")
+ }
# mentions_enabled
# Type: Boolean
# Whether users can mention other users to subscribe them to the thread
# Valid options:
@@ -258,10 +260,11 @@
# 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.
@@ -270,10 +273,12 @@
# - 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: lambda { |current_user, query|
- # current_user.class.where('username LIKE ?', "#{query}%") }
- config.user_mentions_proc = lambda { |current_user, query|
- current_user.class.where('username LIKE ?', "#{query}%") }
+ # 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