class TwitchEmbed

Public Class Methods

new(tag_name, markup, tokens) click to toggle source
Calls superclass method
# File lib/jekyll-embeds.rb, line 30
def initialize(tag_name, markup, tokens)
  super
  params = Shellwords.shellwords markup
  @items = { :url => params[0], :type => params[1] || "channel", :aplay => params[2] || false }
end

Public Instance Methods

render(context) click to toggle source
# File lib/jekyll-embeds.rb, line 36
def render(context)
  tstr = "#{@items[:url].strip}"

  case @items[:type]
    when "channel" || "0"
      if tstr[/twitch\.tv\/([^\?]*)/]
        @twitch_url = $1
      else
        @twitch_url = "#{@items[:url]}"
      end
      %Q{<div class='embed-container'><iframe src="https://player.twitch.tv/?channel=#{@twitch_url}" frameborder="0" allowfullscreen="true" scrolling="no" autoplay="#{@items[:aplay]}" height="390" width="640"></iframe></div>}

    when "video" || "1"
      if tstr[/twitch\.tv\/videos\/([^\?]*)/]
        @twitch_url = $1
      else
        @twitch_url = "#{@items[:url]}"
      end
      %Q{<div class='embed-container'><iframe src="https://player.twitch.tv/?video=#{@twitch_url}&autoplay=#{@items[:aplay]}" frameborder="0" allowfullscreen="true" scrolling="no" autoplay="#{@items[:aplay]}" height="390" width="640"></iframe></div>}

    when "clip" || "2"
      if tstr[/clips\.twitch\.tv\/([^\?]*)/]
        @twitch_url = $1
      elsif tstr[/twitch\.tv\/([^\?]*)\/clip\/([^\?]*)\?/]
        @twitch_url = $2
      else
        @twitch_url = "#{@items[:url]}"
      end
      %Q{<div class='embed-container'><iframe src="https://clips.twitch.tv/embed?clip=#{@twitch_url}&autoplay=#{@items[:aplay]}" frameborder="0" allowfullscreen="true" scrolling="no" autoplay="#{@items[:aplay]}" height="390" width="640"></iframe></div>}

    else
      ""
    end
end