-
-
Notifications
You must be signed in to change notification settings - Fork 392
/
card_l_cell.rb
137 lines (102 loc) · 2.77 KB
/
card_l_cell.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# frozen_string_literal: true
module Decidim
# This cell is used a base for all List cards. It holds the basic layout
# so other cells only have to customize a few methods or overwrite views.
class CardLCell < Decidim::ViewModel
include Cell::ViewModel::Partial
include Decidim::TooltipHelper
include Decidim::CardHelper
include Decidim::LayoutHelper
include Decidim::SearchesHelper
alias resource model
def show
render
end
private
def resource_id
"#{class_base_name}_#{resource.id}"
end
def item_list_class
return "card__list" if extra_class.blank?
"card__list #{extra_class}"
end
def extra_class
""
end
def wrapper_class
options[:wrapper_class] || ""
end
def html_options
@html_options ||= options[:html_options] || {}
end
def presented_resource
present(resource)
end
def render_extra_data?
options[:render_extra_data]
end
def resource_path
resource_locator(resource).path(url_extra_params)
end
def url_extra_params
options[:url_extra_params] || {}
end
def class_base_name
@class_base_name ||= resource.class.name.gsub(/\ADecidim::/, "").underscore.split("/").join("__")
end
def prefix_class(class_name = nil)
return class_base_name if class_name.blank?
"#{class_base_name}__#{class_name}"
end
def resource_image_path
nil
end
def has_image?
resource_image_path.present?
end
def has_link_to_resource?
true
end
def link_whole_card?
return true unless options.has_key?(:link_whole_card)
options[:link_whole_card]
end
def has_description?
false
end
def metadata_cell
"decidim/card_metadata"
end
def has_author?
false
end
def details_template
return :metadata if metadata_cell.present?
return :author if has_author?
end
def title
decidim_escape_translated(resource.title)
end
def title_tag
options[:title_tag] || :div
end
def description_length
100
end
def description
attribute = resource.try(:short_description) || resource.try(:body) || resource.description
text = translated_attribute(attribute)
decidim_sanitize_editor(html_truncate(text, length: description_length), strip_tags: true)
end
def has_authors?
resource.is_a?(Decidim::Authorable) || resource.is_a?(Decidim::Coauthorable)
end
def render_space?
context[:show_space].presence && resource.respond_to?(:participatory_space) && resource.participatory_space.present?
end
def participatory_space
return unless render_space?
@participatory_space ||= resource.participatory_space
end
end
end