Class: Smithy::Liquid::Tags::Asset::AssetFilePath

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/smithy/liquid/tags/asset.rb

Constant Summary collapse

Syntax =
/(#{::Liquid::Expression}+)?/

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ AssetFilePath

Returns a new instance of AssetFilePath.



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/smithy/liquid/tags/asset.rb', line 31

def initialize(tag_name, markup, tokens)
  if markup =~ Syntax
    @asset_id = $1.gsub('\'', '')
    if @asset = ::Smithy::Asset.find_by_id(@asset_id)
      @url = @asset.url
    else
      @url = controller.smithy_asset_path(@asset_id)
    end
  else
    raise ::Liquid::SyntaxError.new("Syntax Error in '#{@tag_name}' - Valid syntax: asset_file_path <asset_id|path>")
  end
  super
end

Instance Method Details

#render(context) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/smithy/liquid/tags/asset.rb', line 45

def render(context)
  @asset_id = context[@variable]
  if @asset = ::Smithy::Asset.find_by_id(@asset_id)
    @url = @asset.url
  else
    @url = @asset_id
  end
  @url
end