Class: Archangel::Liquid::Tags::YoutubeTag
- Inherits:
-
ApplicationTag
- Object
- Liquid::Tag
- ApplicationTag
- Archangel::Liquid::Tags::YoutubeTag
- 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=NOGEyBeoBGM
{% youtube "NOGEyBeoBGM" %}
{% youtube "NOGEyBeoBGM" width:800 height:600 %}
{% youtube "NOGEyBeoBGM" id:"my_video" class:"my-video" %}
{% youtube "NOGEyBeoBGM" autoplay:1 %}
{% youtube "NOGEyBeoBGM" captions: %}
{% youtube "NOGEyBeoBGM" loop:1 %}
{% youtube "NOGEyBeoBGM" annotations:1 %}
{% youtube "NOGEyBeoBGM" start:10 %}
{% youtube "NOGEyBeoBGM" end:60 %}
{% youtube "NOGEyBeoBGM" showinfo:0 %}
{% youtube "NOGEyBeoBGM" allowfullscreen: %}
{% youtube "NOGEyBeoBGM" allowtransparency:0 %}
{% youtube "NOGEyBeoBGM" 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
-
#initialize(tag_name, markup, options) ⇒ YoutubeTag
constructor
YouTube video embed for Liquid.
-
#render(_context) ⇒ String
Render the YouTube video.
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, ) 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], ).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? content_tag(:iframe, "", video_attributes) end |