Class: AssetTag
- Inherits:
-
LiquidumTag
- Object
- LiquidumTag
- AssetTag
- Defined in:
- lib/scribo/liquid/tags/asset_tag.rb
Overview
Add assets (by name) from the current Liquidum site
Basic usage:
{%asset 'test.png'%}
Advanced usage:
{%asset 'test.png' height="72px"%}
{%asset 'test.png' style="height: 72px;"%}
Note: It will only look at published assets
Instance Method Summary collapse
Instance Method Details
#render(context) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/scribo/liquid/tags/asset_tag.rb', line 16 def render(context) super current_content = context.registers['content'] content = current_content.site.contents.published.located(argv1, restricted: false).first return "<!-- asset '#{argv1}' not found -->" unless content full_path = content.full_path if File.basename(full_path).include?('/_') full_path = context.registers['controller'].helpers.scribo.content_path(content) end case content&.media_type when 'image' %[<img] + attr_str(:src, arg(:src), full_path) + attr_str(:alt, content.properties['title'], content.properties['title']) + attr_str(:title, content.properties['caption'], content.properties['caption']) + attr_str(:width, arg(:width)) + attr_str(:height, arg(:height)) + attr_str(:style, arg(:style)) + %[/>] else if content&.content_type == 'text/css' %[<link rel="stylesheet" type="text/css"] + attr_str(:href, arg(:href), full_path) + %[/>] elsif content&.content_type == 'application/javascript' %[<script] + attr_str(:src, arg(:src), full_path) + %[/></script>] else "<!-- unknown asset: #{argv1} -->" end end end |