Class: Occams::Content::Tags::Image
- Inherits:
-
Occams::Content::Tag
- Object
- Occams::Content::Tag
- Occams::Content::Tags::Image
- Includes:
- Mixins::FileContent
- Defined in:
- lib/occams/content/tags/image.rb
Overview
This is like the the file_link tag, but specifically for images Identify the image by its label cms:image label }
‘class` - any html classes that you want on the image tag. For example “class1 class2”
-
variant_attrs are not functional, perhaps due to some change in ImageMagick
-
Simply use a class in your CSS / SASS to style your image display
‘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”
Instance Attribute Summary collapse
-
#as ⇒ Object
readonly
Returns the value of attribute as.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#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) ⇒ Image
constructor
A new instance of Image.
- #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) ⇒ Image
Returns a new instance of Image.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/occams/content/tags/image.rb', line 22 def initialize(context:, params: [], source: nil) super = params. @identifier = params[0] @as = 'image' @class = ['class'] @variant_attrs = .slice('resize', 'gravity', 'crop') # broken for ImageMagick return if @identifier.present? raise Error, 'Missing identifier label for image tag' end |
Instance Attribute Details
#as ⇒ Object (readonly)
Returns the value of attribute as.
20 21 22 |
# File 'lib/occams/content/tags/image.rb', line 20 def as @as end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
20 21 22 |
# File 'lib/occams/content/tags/image.rb', line 20 def identifier @identifier end |
#variant_attrs ⇒ Object (readonly)
Returns the value of attribute variant_attrs.
20 21 22 |
# File 'lib/occams/content/tags/image.rb', line 20 def variant_attrs @variant_attrs end |
Instance Method Details
#file ⇒ ActiveStorage::Blob
42 43 44 |
# File 'lib/occams/content/tags/image.rb', line 42 def file file_record&. end |
#file_record ⇒ Occams::Cms::File
37 38 39 |
# File 'lib/occams/content/tags/image.rb', line 37 def file_record @file_record ||= context.site.files.detect { |f| f.label == identifier } end |
#label ⇒ String
47 48 49 50 51 |
# File 'lib/occams/content/tags/image.rb', line 47 def label return '' if file_record.nil? file_record.label.presence || file.filename.to_s end |