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