Class: Occams::Content::Tags::Image

Inherits:
Occams::Content::Tag show all
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

Attributes inherited from Occams::Content::Tag

#context, #params, #source

Instance Method Summary collapse

Methods included from Mixins::FileContent

#content

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.

Raises:



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

  options = params.extract_options!
  @identifier     = params[0]
  @as             = 'image'
  @class          = options['class']
  @variant_attrs  = options.slice('resize', 'gravity', 'crop') # broken for ImageMagick

  return if @identifier.present?

  raise Error, 'Missing identifier label for image tag'
end

Instance Attribute Details

#asObject (readonly)

Returns the value of attribute as.



20
21
22
# File 'lib/occams/content/tags/image.rb', line 20

def as
  @as
end

#identifierObject (readonly)

Returns the value of attribute identifier.



20
21
22
# File 'lib/occams/content/tags/image.rb', line 20

def identifier
  @identifier
end

#variant_attrsObject (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

#fileActiveStorage::Blob

Returns:

  • (ActiveStorage::Blob)


42
43
44
# File 'lib/occams/content/tags/image.rb', line 42

def file
  file_record&.attachment
end

#file_recordOccams::Cms::File

Returns:



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

#labelString

Returns:

  • (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