Class: Practical::Views::TiptapDocumentComponent::Attachment
- Inherits:
-
Node
- Object
- ViewComponent::Base
- BaseComponent
- Node
- Practical::Views::TiptapDocumentComponent::Attachment
show all
- Defined in:
- app/components/practical/views/tiptap_document_component.rb
Instance Attribute Summary
Attributes inherited from Node
#node_content
Instance Method Summary
collapse
Methods inherited from Node
#initialize, #render_node_contents
#render_node
#grab, #mix
Instance Method Details
#attachment ⇒ Object
249
250
251
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 249
def attachment
@attachment ||= GlobalID::Locator.locate_signed(sgid.to_s, for: :document)&.attachment
end
|
#attachment_details_and_download ⇒ Object
239
240
241
242
243
244
245
246
247
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 239
def attachment_details_and_download
tag.section(class: 'attachment-details') {
tag.p {
tag.a(href: url, target: "_blank") {
"#{filename} – #{human_file_size}"
}
}
}
end
|
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 215
def attachment_figure
if previewable?
image = tag.div {
tag.img(src: url, width: width, height: height)
}
else
image = tag.div {
render Practical::Views::IconForFileExtensionComponent.new(extension: extension)
}
end
safe_join([
image,
attachment_details_and_download,
figure_caption
])
end
|
#attrs ⇒ Object
257
258
259
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 257
def attrs
node_content[:attrs]
end
|
#call ⇒ Object
191
192
193
194
195
196
197
198
199
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 191
def call
tag.figure(class: 'wa-stack wa-gap-s') {
if missing_attachment?
missing_attachment_figure
else
attachment_figure
end
}
end
|
307
308
309
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 307
def default_figure_size
100
end
|
#extension ⇒ Object
281
282
283
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 281
def extension
attachment.extension
end
|
233
234
235
236
237
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 233
def figure_caption
if node_content[:content].present?
tag.figcaption { render_node_contents }
end
end
|
#filename ⇒ Object
269
270
271
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 269
def filename
attachment.original_filename
end
|
#has_dimensions? ⇒ Boolean
293
294
295
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 293
def has_dimensions?
!stored_width.blank? && !stored_height.blank?
end
|
#height ⇒ Object
302
303
304
305
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 302
def height
return stored_height if has_dimensions?
default_figure_size
end
|
#human_file_size ⇒ Object
273
274
275
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 273
def human_file_size
helpers.number_to_human_size(attachment.size)
end
|
#missing_attachment? ⇒ Boolean
253
254
255
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 253
def missing_attachment?
attachment.nil?
end
|
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 201
def missing_attachment_figure
safe_join([
tag.div {
render Practical::Views::IconForFileExtensionComponent.new(extension: "missing")
},
tag.section(class: 'attachment-details') {
tag.p(t("tiptap_document.attachment_missing.text"))
},
figure_caption
])
end
|
#previewable? ⇒ Boolean
261
262
263
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 261
def previewable?
attrs.dig(:previewable)
end
|
#sgid ⇒ Object
265
266
267
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 265
def sgid
attrs.dig(:sgid)
end
|
#stored_height ⇒ Object
289
290
291
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 289
def stored_height
attrs.dig(:height)
end
|
#stored_width ⇒ Object
285
286
287
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 285
def stored_width
attrs.dig(:width)
end
|
#url ⇒ Object
277
278
279
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 277
def url
attachment.url
end
|
#width ⇒ Object
297
298
299
300
|
# File 'app/components/practical/views/tiptap_document_component.rb', line 297
def width
return stored_width if has_dimensions?
default_figure_size
end
|