Class: Decidim::LikeButtonsCell

Inherits:
ViewModel
  • Object
show all
Includes:
CellsHelper, LikeableHelper, ResourceHelper
Defined in:
app/cells/decidim/like_buttons_cell.rb

Overview

This cell renders the like button and the likes count. It only supports one row of buttons per page due to current tag ids used by javascript.

Instance Method Summary collapse

Methods included from ResourceHelper

#linked_classes_filter_values_for, #linked_classes_for, #resource_locator

Methods included from LikeableHelper

#current_user_can_like?, #likes_enabled?, #path_to_create_like, #path_to_destroy_like, #show_likes_card?

Methods included from CellsHelper

#current_component, #flaggable?, #from_context, #index_action?, #show_action?, #user_flaggable?, #withdrawable?

Instance Method Details

#button_classesObject



28
29
30
# File 'app/cells/decidim/like_buttons_cell.rb', line 28

def button_classes
  "button button__sm button__transparent-secondary"
end

#button_contentObject



47
48
49
# File 'app/cells/decidim/like_buttons_cell.rb', line 47

def button_content
  render
end

#like_pathObject

produce the path to a like from the engine routes as the cell does not have access to routes



43
44
45
# File 'app/cells/decidim/like_buttons_cell.rb', line 43

def like_path(*)
  decidim.like_path(*)
end

#likes_pathObject

produce the path to likes from the engine routes as the cell does not have access to routes



38
39
40
# File 'app/cells/decidim/like_buttons_cell.rb', line 38

def likes_path(*)
  decidim.likes_path(*)
end

#resourceObject

The resource being un/liked is the Cell's model.



33
34
35
# File 'app/cells/decidim/like_buttons_cell.rb', line 33

def resource
  model
end

#showObject

Renders the "Like" button. Contains all the logic about how the button should be rendered and which actions the button must trigger.

It takes into account:

  • if likes are enabled
  • if users are logged in
  • if users require verification


19
20
21
22
23
24
25
26
# File 'app/cells/decidim/like_buttons_cell.rb', line 19

def show
  return render :disabled_likes if likes_blocked?
  return render unless current_user
  return render :disabled_likes if user_can_not_participate?
  return render :verification_modal unless like_allowed?

  render
end