class CS50::VideoTag
Public Class Methods
new(tag_name, text, tokens)
click to toggle source
gist.github.com/niquepa/4c59b7d52a15dde2367a
Calls superclass method
# File lib/jekyll-theme-cs50.rb, line 82 def initialize(tag_name, text, tokens) super if text =~ /^https?:\/\/(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/ @v = $1 components = { rel: "0", showinfo: "0" } params = CGI::parse(URI::parse(text.strip).query || "") ["autoplay", "end", "index", "list", "start", "t"].each do |param| if params.key?(param) components[param] = params[param].first end end @src = URI::HTTPS.build(:host => "www.youtube.com", :path => "/embed/#{@v}", :query => URI.encode_www_form(components)) end end
Public Instance Methods
render(context)
click to toggle source
# File lib/jekyll-theme-cs50.rb, line 100 def render(context) if @v and @src <<~EOT <div class="embed-responsive embed-responsive-16by9"> <iframe allowfullscreen class="border embed-responsive-item" src="#{@src}" style="background-image: url('https://img.youtube.com/vi/#{@v}/sddefault.jpg'); background-repeat: no-repeat; background-size: cover;"></iframe> </div> EOT else <<~EOT <p><img alt="static" class="border" data-video src="https://i.imgur.com/xnZ5A2u.gif"></p> EOT end end