Simplify using helper methods in components

The `use_helpers` method was added in ViewComponent 3.8.0, and it's
included by default in all components since version 3.11.0.

Note we sometimes delegated the `can?` method to the controller instead
of the helpers, for no particularly reason. We're unifying that code as
well.
This commit is contained in:
Javi Martín
2024-02-23 22:34:01 +01:00
parent 52ec5094f0
commit 1d955b7a20
70 changed files with 70 additions and 70 deletions

View File

@@ -1,6 +1,6 @@
class Shared::AgreeWithTermsOfServiceFieldComponent < ApplicationComponent
attr_reader :form
delegate :new_window_link_to, to: :helpers
use_helpers :new_window_link_to
def initialize(form)
@form = form

View File

@@ -1,6 +1,6 @@
class Shared::AvatarComponent < ApplicationComponent
attr_reader :record, :given_options
delegate :avatar_image, to: :helpers
use_helpers :avatar_image
def initialize(record, **given_options)
@record = record

View File

@@ -1,6 +1,6 @@
class Shared::CommentsComponent < ApplicationComponent
attr_reader :record, :comment_tree
delegate :current_user, :current_order, :locale_and_user_status, :commentable_cache_key, to: :helpers
use_helpers :current_user, :current_order, :locale_and_user_status, :commentable_cache_key
def initialize(record, comment_tree)
@record = record

View File

@@ -1,6 +1,6 @@
class Shared::GeozoneLinkComponent < ApplicationComponent
attr_reader :geozonable, :link
delegate :geozone_name, to: :helpers
use_helpers :geozone_name
def initialize(geozonable, link)
@geozonable = geozonable

View File

@@ -1,6 +1,6 @@
class Shared::InFavorAgainstComponent < ApplicationComponent
attr_reader :votable
delegate :votes_percentage, to: :helpers
use_helpers :votes_percentage
def initialize(votable)
@votable = votable

View File

@@ -1,6 +1,6 @@
class Shared::ModerationActionsComponent < ApplicationComponent
attr_reader :record
delegate :can?, to: :helpers
use_helpers :can?
def initialize(record)
@record = record

View File

@@ -1,6 +1,6 @@
class Shared::OrderLinksComponent < ApplicationComponent
attr_reader :i18n_namespace, :anchor
delegate :current_path_with_query_params, :current_order, :valid_orders, to: :helpers
use_helpers :current_path_with_query_params, :current_order, :valid_orders
def initialize(i18n_namespace, anchor: nil)
@i18n_namespace = i18n_namespace

View File

@@ -1,6 +1,6 @@
class Shared::ParticipationNotAllowedComponent < ApplicationComponent
attr_reader :votable, :cannot_vote_text
delegate :current_user, :link_to_signin, :link_to_signup, to: :helpers
use_helpers :current_user, :link_to_signin, :link_to_signup
def initialize(votable, cannot_vote_text:)
@votable = votable

View File

@@ -1,6 +1,6 @@
class Shared::TagListComponent < ApplicationComponent
attr_reader :taggable, :limit
delegate :link_list, to: :helpers
use_helpers :link_list
def initialize(taggable, limit:)
@taggable = taggable

View File

@@ -1,6 +1,6 @@
class Shared::VoteButtonComponent < ApplicationComponent
attr_reader :votable, :value, :options
delegate :current_user, :can?, to: :helpers
use_helpers :current_user, :can?
def initialize(votable, value:, **options)
@votable = votable