Class: ComfortableMexicanSofa::Content::Tag::FileLink
- Inherits:
-
ComfortableMexicanSofa::Content::Tag
- Object
- ComfortableMexicanSofa::Content::Tag
- ComfortableMexicanSofa::Content::Tag::FileLink
- Includes:
- Mixins::FileContent
- Defined in:
- lib/comfortable_mexican_sofa/content/tags/file_link.rb
Overview
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”
Instance Attribute Summary collapse
-
#as ⇒ Object
readonly
Returns the value of attribute as.
-
#identifier ⇒ String
readonly
A Comfy::Cms::Site#files ID.
-
#variant_attrs ⇒ Object
readonly
Returns the value of attribute variant_attrs.
Attributes inherited from ComfortableMexicanSofa::Content::Tag
Instance Method Summary collapse
- #file ⇒ ActiveStorage::Blob
- #file_record ⇒ Comfy::Cms::File
-
#initialize(context:, params: [], source: nil) ⇒ FileLink
constructor
A new instance of FileLink.
- #label ⇒ String
Methods included from Mixins::FileContent
Methods inherited from ComfortableMexicanSofa::Content::Tag
#allow_erb?, #content, #nodes, #render
Constructor Details
#initialize(context:, params: [], source: nil) ⇒ FileLink
Returns a new instance of FileLink.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/comfortable_mexican_sofa/content/tags/file_link.rb', line 29 def initialize(context:, params: [], source: nil) super = params. @identifier = params[0] @as = ["as"] || "url" @class = ["class"] @variant_attrs = .slice("resize", "gravity", "crop") unless @identifier.present? raise Error, "Missing identifier for file link tag" end end |
Instance Attribute Details
#as ⇒ Object (readonly)
Returns the value of attribute as.
24 25 26 |
# File 'lib/comfortable_mexican_sofa/content/tags/file_link.rb', line 24 def as @as end |
#identifier ⇒ String (readonly)
Returns A Comfy::Cms::Site#files ID.
21 22 23 |
# File 'lib/comfortable_mexican_sofa/content/tags/file_link.rb', line 21 def identifier @identifier end |
#variant_attrs ⇒ Object (readonly)
Returns the value of attribute variant_attrs.
27 28 29 |
# File 'lib/comfortable_mexican_sofa/content/tags/file_link.rb', line 27 def variant_attrs @variant_attrs end |
Instance Method Details
#file ⇒ ActiveStorage::Blob
49 50 51 |
# File 'lib/comfortable_mexican_sofa/content/tags/file_link.rb', line 49 def file file_record&. end |
#file_record ⇒ Comfy::Cms::File
44 45 46 |
# 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 ⇒ String
54 55 56 57 |
# 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 |