Class: VoteFu::VoteWidgetComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/vote_fu/vote_widget_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(voteable:, voter: nil, scope: nil, variant: :default, upvote_label: "▲", downvote_label: "▼", show_count: true, count_format: :plusminus) ⇒ VoteWidgetComponent

Returns a new instance of VoteWidgetComponent.

Parameters:

  • voteable (ActiveRecord::Base)

    The voteable record

  • voter (ActiveRecord::Base, nil) (defaults to: nil)

    The current voter

  • scope (String, Symbol, nil) (defaults to: nil)

    Vote scope for scoped voting

  • variant (Symbol) (defaults to: :default)

    Widget style (:default, :compact, :vertical, :large)

  • upvote_label (String) (defaults to: "▲")

    Upvote button label

  • downvote_label (String) (defaults to: "▼")

    Downvote button label

  • show_count (Boolean) (defaults to: true)

    Whether to show vote count

  • count_format (Symbol) (defaults to: :plusminus)

    Count format (:plusminus, :total, :split)



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/components/vote_fu/vote_widget_component.rb', line 16

def initialize(
  voteable:,
  voter: nil,
  scope: nil,
  variant: :default,
  upvote_label: "",
  downvote_label: "",
  show_count: true,
  count_format: :plusminus
)
  @voteable = voteable
  @voter = voter
  @scope = scope
  @variant = variant
  @upvote_label = upvote_label
  @downvote_label = downvote_label
  @show_count = show_count
  @count_format = count_format
end

Instance Attribute Details

#voteableObject (readonly)

The voteable record



6
7
8
# File 'app/components/vote_fu/vote_widget_component.rb', line 6

def voteable
  @voteable
end

Instance Method Details

#callObject



36
37
38
39
40
41
42
43
44
# File 'app/components/vote_fu/vote_widget_component.rb', line 36

def call
  tag.div(**wrapper_attributes) do
    safe_join([
      upvote_button,
      (count_display if @show_count),
      downvote_button
    ].compact)
  end
end