class ComfortableMexicanSofa::Content::Tag::File
File
tag allows attaching of file to the page. This controls how files are uploaded and then displayed on the page. Example tag:
{{ cms:file identifier, as: link, label: "My File" }}
`as` - url (default) | link | image - render out link or image tag `label` - attach label attribute to link or image tag `resize` - imagemagic option. For example: “100x50>” `gravity` - imagemagic option. For example: “center” `crop` - imagemagic option. For example: “100x50+0+0” `class` - any html classes that you want on the result link or image tag. For example “class1 class2”
Attributes
as[R]
@type [“url”, “link”, “image”]
variant_attrs[R]
@type [{String => String}]
Public Class Methods
new(context:, params: [], source: nil)
click to toggle source
@param (see ComfortableMexicanSofa::Content::Tag#initialize)
Calls superclass method
ComfortableMexicanSofa::Content::Tag::Fragment::new
# File lib/comfortable_mexican_sofa/content/tags/file.rb, line 27 def initialize(context:, params: [], source: nil) super @as = options["as"] || "url" @label = options["label"] @class = options["class"] @variant_attrs = options.slice("resize", "gravity", "crop") end
Public Instance Methods
form_field(object_name, view, index) { |safe_join([input, attachments_partial], "")| ... }
click to toggle source
# File lib/comfortable_mexican_sofa/content/tags/file.rb, line 35 def form_field(object_name, view, index) name = "#{object_name}[fragments_attributes][#{index}][files]" input = view.send(:file_field_tag, name, id: form_field_id, class: "form-control") attachments_partial = if fragment.attachments view.render( partial: "comfy/admin/cms/fragments/form_fragment_attachments", locals: { object_name: object_name, index: index, attachments: fragment.attachments, fragment_id: identifier, multiple: false } ) end yield view.safe_join([input, attachments_partial], "") end
Protected Instance Methods
file()
click to toggle source
@return [ActiveStorage::Blob]
# File lib/comfortable_mexican_sofa/content/tags/file.rb, line 59 def file fragment.attachments.first end
label()
click to toggle source
@return [String]
# File lib/comfortable_mexican_sofa/content/tags/file.rb, line 64 def label @label || file&.filename end