class ComfortableMexicanSofa::Content::Tag::FileLink
This is how you link previously uploaded file to anywhere. Good example may be a header image you want to use on the layout level.
{{cms:file_link id, as: image}}
`as` - url (default) | link | image - how file gets rendered out `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”]
identifier[R]
@return [String] A {Comfy::Cms::Site#files} ID.
variant_attrs[R]
@type [{String => String}]
Public Class Methods
new(context:, params: [], source: nil)
click to toggle source
Calls superclass method
ComfortableMexicanSofa::Content::Tag::new
# File lib/comfortable_mexican_sofa/content/tags/file_link.rb, line 29 def initialize(context:, params: [], source: nil) super options = params.extract_options! @identifier = params[0] @as = options["as"] || "url" @class = options["class"] @variant_attrs = options.slice("resize", "gravity", "crop") unless @identifier.present? raise Error, "Missing identifier for file link tag" end end
Public Instance Methods
file()
click to toggle source
@return [ActiveStorage::Blob]
# File lib/comfortable_mexican_sofa/content/tags/file_link.rb, line 49 def file file_record&.attachment end
file_record()
click to toggle source
@return [Comfy::Cms::File]
# File lib/comfortable_mexican_sofa/content/tags/file_link.rb, line 44 def file_record @file_record ||= context.site.files.detect { |f| f.id == identifier.to_i } end
label()
click to toggle source
@return [String]
# File lib/comfortable_mexican_sofa/content/tags/file_link.rb, line 54 def label return "" if file_record.nil? file_record.label.presence || file.filename.to_s end