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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Shared::ModerationActionsComponent < ApplicationComponent
|
||||
attr_reader :record
|
||||
delegate :can?, to: :helpers
|
||||
use_helpers :can?
|
||||
|
||||
def initialize(record)
|
||||
@record = record
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user