Class: Landable::Liquid::AssetTag

Inherits:
Liquid::Tag
  • Object
show all
Includes:
ActionView::Helpers::AssetTagHelper, Sprockets::Rails::Helper
Defined in:
lib/landable/liquid/asset_tags.rb

Direct Known Subclasses

AssetAttributeTag

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, param, tokens) ⇒ AssetTag

Returns a new instance of AssetTag.



14
15
16
17
18
# File 'lib/landable/liquid/asset_tags.rb', line 14

def initialize(tag_name, param, tokens)
  @tag_name = tag_name
  @asset_name = param.strip
  @tokens = tokens
end

Instance Attribute Details

#asset_nameObject

Returns the value of attribute asset_name.



6
7
8
# File 'lib/landable/liquid/asset_tags.rb', line 6

def asset_name
  @asset_name
end

#tag_nameObject

Returns the value of attribute tag_name.



6
7
8
# File 'lib/landable/liquid/asset_tags.rb', line 6

def tag_name
  @tag_name
end

Instance Method Details

#render(context) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/landable/liquid/asset_tags.rb', line 20

def render(context)
  tag_method = tag_name.to_sym
  tag_method = :image_tag if tag_method == :img_tag

  # if this matches an application asset, use that
  if assets_environment[asset_name]
    send tag_method, asset_name

  # otherwise, find an asset of our own
  else
    asset = lookup_asset context, asset_name

    options = {}
    options[:alt] = asset.description if tag_method == :image_tag

    send tag_method, asset.public_url, options
  end
end