Class: Archangel::Liquid::Tags::VimeoTag

Inherits:
ApplicationTag show all
Defined in:
lib/archangel/liquid/tags/vimeo_tag.rb

Overview

Vimeo custom tag for Liquid

Example

Given the Vimeo URL https://vimeo.com/183344978
{% vimeo "183344978" %}
{% vimeo "183344978" width:800 height:60 %}
{% vimeo "183344978" id:"my_video" class:"my-video" %}
{% vimeo "183344978" autoplay:1 %}
{% vimeo "183344978" loop:1 %}
{% vimeo "183344978" allowfullscreen:0 %}
{% vimeo "183344978" allowtransparency:0 %}
{% vimeo "183344978" frameborder:4 %}

Constant Summary

Constants inherited from ApplicationTag

ApplicationTag::ASSET_ATTRIBUTES_SYNTAX, ApplicationTag::ASSET_SYNTAX, ApplicationTag::KEY_VALUE_ATTRIBUTES_SYNTAX, ApplicationTag::SLUG_ATTRIBUTES_SYNTAX, ApplicationTag::SLUG_SYNTAX, ApplicationTag::URL_ATTRIBUTES_SYNTAX

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, options) ⇒ VimeoTag

Vimeo video embed for Liquid

Parameters:

  • tag_name (String)

    the Liquid tag name

  • markup (String)

    the passed options

  • options (Object)

    options


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/archangel/liquid/tags/vimeo_tag.rb', line 28

def initialize(tag_name, markup, options)
  super

  match = SLUG_ATTRIBUTES_SYNTAX.match(markup)

  if match.blank?
    raise ::Liquid::SyntaxError, Archangel.t("errors.syntax.vimeo")
  end

  @key = ::Liquid::Variable.new(match[:slug], options).name
  @attributes = {}

  match[:attributes].scan(KEY_VALUE_ATTRIBUTES_SYNTAX) do |key, value|
    @attributes[key.to_sym] = ::Liquid::Expression.parse(value)
  end
end

Instance Method Details

#render(_context) ⇒ String

Render the Vimeo video

Parameters:

  • _context (Object)

    the Liquid context

Returns:

  • (String)

    the rendered video


51
52
53
54
55
# File 'lib/archangel/liquid/tags/vimeo_tag.rb', line 51

def render(_context)
  return if key.blank?

  (:iframe, "", video_attributes)
end