Class: Archangel::Liquid::Tags::YoutubeTag

Inherits:
ApplicationTag
  • Object
show all
Defined in:
lib/archangel/liquid/tags/youtube_tag.rb

Overview

YouTube custom tag for Liquid

Example

Given the YouTube URL https://www.youtube.com/watch?v=-X2atEH7nCg
{% youtube "-X2atEH7nCg" %}
{% youtube "-X2atEH7nCg" width:800 height:600 %}
{% youtube "-X2atEH7nCg" id:"my_video" class:"my-video" %}
{% youtube "-X2atEH7nCg" autoplay:1 %}
{% youtube "-X2atEH7nCg" captions: %}
{% youtube "-X2atEH7nCg" loop:1 %}
{% youtube "-X2atEH7nCg" annotations:1 %}
{% youtube "-X2atEH7nCg" start:10 %}
{% youtube "-X2atEH7nCg" end:60 %}
{% youtube "-X2atEH7nCg" showinfo:0 %}
{% youtube "-X2atEH7nCg" allowfullscreen: %}
{% youtube "-X2atEH7nCg" allowtransparency:0 %}
{% youtube "-X2atEH7nCg" 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) ⇒ YoutubeTag

YouTube video embed for Liquid


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/archangel/liquid/tags/youtube_tag.rb', line 33

def initialize(tag_name, markup, options)
  super

  match = SLUG_ATTRIBUTES_SYNTAX.match(markup)

  if match.blank?
    raise ::Liquid::SyntaxError, Archangel.t("errors.syntax.youtube")
  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 YouTube video


56
57
58
59
60
# File 'lib/archangel/liquid/tags/youtube_tag.rb', line 56

def render(_context)
  return if key.blank?

  (:iframe, "", video_attributes)
end