Class: ComfortableMexicanSofa::Content::Tag::PageFileLink
- Inherits:
-
ComfortableMexicanSofa::Content::Tag
- Object
- ComfortableMexicanSofa::Content::Tag
- ComfortableMexicanSofa::Content::Tag::PageFileLink
- Includes:
- Mixins::FileContent
- Defined in:
- lib/comfortable_mexican_sofa/content/tags/page_file_link.rb
Overview
This tag allows you to link page-level files from within the page content.
E.g. if your layout has:
{{ cms:file graphic, render: false }}
{{ cms:files , redner: false }}
You can link to the files from an individual page (or snippet rendered in the context of the page) like so:
{{ cms:page_file_link graphic }}
{{ cms:page_file_link , filename: "cat.jpg" }}
‘as` - url (default) | link | image - how file gets rendered out `label` - attach label attribute to link or image tag `resize` - imagemagick option. For example: “100x50>” `gravity` - imagemagick option. For example: “center” `crop` - imagemagick 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.
-
#filename ⇒ String
readonly
Used to refer to a file in a cms:files } tag.
-
#identifier ⇒ String
readonly
A ‘cms:file(s)` identifier.
-
#variant_attrs ⇒ Object
readonly
Returns the value of attribute variant_attrs.
Attributes inherited from ComfortableMexicanSofa::Content::Tag
Instance Method Summary collapse
- #file ⇒ ActiveStorage::Blob
- #fragment ⇒ Comfy::Cms::Fragment
-
#initialize(context:, params: [], source: nil) ⇒ PageFileLink
constructor
A new instance of PageFileLink.
- #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) ⇒ PageFileLink
Returns a new instance of PageFileLink.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/comfortable_mexican_sofa/content/tags/page_file_link.rb', line 42 def initialize(context:, params: [], source: nil) super = params. @identifier = params[0] @as = ["as"] || "url" @class = ["class"] @variant_attrs = .slice("resize", "gravity", "crop") @filename = ["filename"] unless @identifier.present? raise Error, "Missing identifier for page file link tag" end end |
Instance Attribute Details
#as ⇒ Object (readonly)
Returns the value of attribute as.
33 34 35 |
# File 'lib/comfortable_mexican_sofa/content/tags/page_file_link.rb', line 33 def as @as end |
#filename ⇒ String (readonly)
Returns Used to refer to a file in a cms:files } tag.
39 40 41 |
# File 'lib/comfortable_mexican_sofa/content/tags/page_file_link.rb', line 39 def filename @filename end |
#identifier ⇒ String (readonly)
Returns A ‘cms:file(s)` identifier.
30 31 32 |
# File 'lib/comfortable_mexican_sofa/content/tags/page_file_link.rb', line 30 def identifier @identifier end |
#variant_attrs ⇒ Object (readonly)
Returns the value of attribute variant_attrs.
36 37 38 |
# File 'lib/comfortable_mexican_sofa/content/tags/page_file_link.rb', line 36 def variant_attrs @variant_attrs end |
Instance Method Details
#file ⇒ ActiveStorage::Blob
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/comfortable_mexican_sofa/content/tags/page_file_link.rb', line 63 def file @file ||= if fragment.nil? nil elsif filename.nil? fragment..first else fragment..detect { |a| a.filename.to_s == filename } end end |
#fragment ⇒ Comfy::Cms::Fragment
58 59 60 |
# File 'lib/comfortable_mexican_sofa/content/tags/page_file_link.rb', line 58 def fragment @fragment ||= context.fragments.detect { |f| f.identifier == identifier } end |
#label ⇒ String
75 76 77 78 |
# File 'lib/comfortable_mexican_sofa/content/tags/page_file_link.rb', line 75 def label return if file.nil? file.filename.to_s end |