class Jekyll::TwitchTag
This is a liquid tag that embed Twitch
Clips input is a url
Public Class Methods
channel_url(url)
click to toggle source
Class Methods
# File lib/jekyll-twitch/twitch_tag.rb, line 26 def self.channel_url(url) slug = url.match %r{(?<no>twitch.tv/)(?<channel>.+)/?\??} "https://player.twitch.tv/?channel=#{slug[:channel]}&autoplay=false" end
clip_url(url)
click to toggle source
# File lib/jekyll-twitch/twitch_tag.rb, line 31 def self.clip_url(url) slug = url.match %r{(?<no>/clip/)(?<clip>.+)/?\??} "https://clips.twitch.tv/embed?autoplay=false&clip=#{slug[:clip]}" end
collection_url(url)
click to toggle source
# File lib/jekyll-twitch/twitch_tag.rb, line 36 def self.collection_url(url) slug = url.match %r{(?<no>/collections/)(?<collection>.+)/?\??} "https://player.twitch.tv/?collection=#{slug[:collection]}&autoplay=false" end
hostname(url)
click to toggle source
# File lib/jekyll-twitch/twitch_tag.rb, line 41 def self.hostname(url) matches = url.match %r{\A(?<safe>https?://)?(?<host>[A-z.]+)(?<port>:\d+)?} matches[:host] end
new(_tag_name, content, _tokens)
click to toggle source
Calls superclass method
# File lib/jekyll-twitch/twitch_tag.rb, line 10 def initialize(_tag_name, content, _tokens) super @parsed_url = Jekyll::TwitchTag.parse_twitch_url content.strip end
parse_twitch_url(url)
click to toggle source
# File lib/jekyll-twitch/twitch_tag.rb, line 46 def self.parse_twitch_url(url) case url when %r{/clip/} clip_url url when %r{/videos/} video_url url when %r{/collections/} collection_url url else channel_url url end end
site_url(context)
click to toggle source
# File lib/jekyll-twitch/twitch_tag.rb, line 59 def self.site_url(context) hostname(context.registers[:site].config['url']) end
video_url(url)
click to toggle source
# File lib/jekyll-twitch/twitch_tag.rb, line 63 def self.video_url(url) slug = url.match %r{(?<no>/videos/)(?<vod>\d+)} "https://player.twitch.tv/?video=#{slug[:vod]}&autoplay=false" end
Public Instance Methods
render(context)
click to toggle source
# File lib/jekyll-twitch/twitch_tag.rb, line 15 def render(context) host = Jekyll::TwitchTag.site_url context %(<iframe src="#{@parsed_url}&parent=#{host}" height="100%" width="100%" allowfullscreen="true"> </iframe>) end