Class: Liquid::Image

Inherits:
DmCore::LiquidTag
  • Object
show all
Includes:
ActionView::Helpers::AssetTagHelper, ActionView::Helpers::TagHelper, DmCore::AccountHelper, DmCore::ParamsHelper, DmCore::UrlHelper
Defined in:
lib/dm_cms/liquid/tags/image.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.detailsObject




30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/dm_cms/liquid/tags/image.rb', line 30

def self.details
  { name: self.tag_name,
    summary: 'Displays an image',
    category: 'media',
    description: <<-END_OF_DESCRIPTION
Displays an image. Will pull image (with optional version) from the site's media directory unless a full path is given.
Any normal HTML img attributes can be passed, such `alt`, `title`, `width`, etc

Parameters:

src
: name of the image.  Can either reference a file in the 'media' directory (`2014/car.jpg`), a full path (`http://example.com/image/car.jpg`)
or reference an S3 file (`s3://bucket/car.jpg`)

version
: (optional) Use a specific image version (`thumb`, `lg`, etc)

protected
: (optional) File is in protected directory.  `version` will have no effect with this option

html img attributes
: you can specify any valid HTML img attributes, such as `width` or `title`

**Examples**

~~~
{% image src: '2014/placeholder_190x105.jpg', class: 'right', title: "Some title" %}
~~~
Image in the media directory, with a specified class and title

~~~
{% image src: '2014/placeholder_190x105.jpg', class: right, protected: true %}
~~~
Image is in the protected asset folder

~~~
{% image src: '2014/placeholder_190x105.jpg', version: 'thumb', alt: "Some title" %}
~~~
Use the `thumb` version of the image

END_OF_DESCRIPTION
  }
end

Instance Method Details

#render(context) ⇒ Object




15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dm_cms/liquid/tags/image.rb', line 15

def render(context)
  if @attributes['version']
    #--- pull from MediaFile object
    src = MediaFile.url_by_name(@attributes['src'], version: @attributes['version'])
    @attributes.delete('version')
  else
    #--- handle like regular url
    src = file_url(@attributes['src'], account_site_assets: (context), default_folder: 'media', protected: @attributes['protected'].as_boolean)
  end
  @attributes.delete('src')
  
  image_tag(src,  @attributes)
end