class Archangel::Liquid::Tags::VimeoTag
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 %}
Attributes
attributes[R]
key[R]
Public Class Methods
new(tag_name, markup, options)
click to toggle source
Vimeo video embed for Liquid
@param tag_name [String] the Liquid
tag name @param markup [String] the passed options @param options [Object] options
Calls superclass method
# 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
Public Instance Methods
render(_context)
click to toggle source
Render the Vimeo video
@param _context [Object] the Liquid
context @return [String] the rendered video
# File lib/archangel/liquid/tags/vimeo_tag.rb, line 51 def render(_context) return if key.blank? content_tag(:iframe, "", video_attributes) end
Protected Instance Methods
video_attributes()
click to toggle source
# File lib/archangel/liquid/tags/vimeo_tag.rb, line 61 def video_attributes { src: video_url, width: video_width, height: video_height }.merge(video_fetch_attributes) end
video_fetch_attributes()
click to toggle source
# File lib/archangel/liquid/tags/vimeo_tag.rb, line 69 def video_fetch_attributes { id: nil, class: nil, style: nil, frameborder: 0, allowtransparency: "true", allowFullScreen: "allowFullScreen" }.each_with_object({}) do |(key, value), hash| hash[key] = attributes.fetch(key.to_s.downcase.to_sym, value) end end
video_height()
click to toggle source
# File lib/archangel/liquid/tags/vimeo_tag.rb, line 102 def video_height attributes.fetch(:height, 360) end
video_url()
click to toggle source
# File lib/archangel/liquid/tags/vimeo_tag.rb, line 82 def video_url [ "https://player.vimeo.com/video/#{key}", video_url_params ].join("?") end
video_url_params()
click to toggle source
# File lib/archangel/liquid/tags/vimeo_tag.rb, line 89 def video_url_params { autoplay: attributes.fetch(:autoplay, 0), loop: attributes.fetch(:loop, 0), width: video_width, height: video_height }.compact.reject { |_, value| value.blank? }.to_query end
video_width()
click to toggle source
# File lib/archangel/liquid/tags/vimeo_tag.rb, line 98 def video_width attributes.fetch(:width, 640) end