Skip to content

Commit

Permalink
Make embed_html work without the request object.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Jan 14, 2017
1 parent 4bf78db commit 2450215
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions config/initializers/05-nil.rb
Expand Up @@ -19,11 +19,11 @@ def linkify
nil
end

def linkify_and_embed(request, embed_only="")
def linkify_and_embed(request=nil, embed_only="")
nil
end

def embed_html(request)
def embed_html(request=nil)
nil
end

Expand Down
9 changes: 5 additions & 4 deletions config/initializers/05-string.rb
Expand Up @@ -169,7 +169,7 @@ def linkify
end
end

def linkify_and_embed(request, embed_only="")
def linkify_and_embed(request=nil, embed_only="")
embeds = []
result = self.gsub(SPOTIFY_REGEXP) do |uri|
"https://play.spotify.com/#{uri.gsub(":","/")}"
Expand All @@ -188,11 +188,12 @@ def linkify_and_embed(request, embed_only="")
return result + embeds.map { |html| "\n" + html }.join
end

def embed_html(request)
def embed_html(request=nil)
root_url = request ? request.root_url : ""
if %r{^https?://www\.facebook\.com/.*/videos/(?<id>\d+)} =~ self or %r{^https?://www\.facebook\.com/video/embed\?video_id=(?<id>\d+)} =~ self
<<-EOF.undent
<iframe src="https://www.facebook.com/video/embed?video_id=#{id}" width="1280" height="720" frameborder="0" scrolling="no" allowfullscreen></iframe>
<a href="https://www.facebook.com/video/embed?video_id=#{id}">Open embed</a> | <a href="#{request.root_url}/facebook/download?url=#{id}">Download video</a>
<a href="https://www.facebook.com/video/embed?video_id=#{id}">Open embed</a> | <a href="#{root_url}/facebook/download?url=#{id}">Download video</a>
EOF
elsif %r{^https?://(?:www\.|m\.)youtube\.com/(?:.*?[?&#](v=(?<id>[^&#]+)|list=(?<list>[^&#]+)|t=(?<t>[^&#]+)))+} =~ self or %r{^https?://youtu\.be/(?<id>[^?&#]+)(?:.*?[?&#](list=(?<list>[^&#]+)|t=(?<t>[^&#]+)))*} =~ self
# https://www.youtube.com/watch?v=z5OGD5_9cA0&list=PL0QrZvg7QIgpoLdNFnEePRrU-YJfr9Be7&index=3&t=30s
Expand All @@ -216,7 +217,7 @@ def embed_html(request)
url += "&time=#{t}" if t
<<-EOF.undent
<iframe width="853" height="480" src="#{url}" frameborder="0" scrolling="no" allowfullscreen></iframe>
<a href="#{url}">Open embed</a> | <a href="#{request.root_url}/twitch/watch?url=#{vod_id || channel_name}&open">Open in VLC</a> | <a href="#{request.root_url}/twitch/download?url=#{vod_id || channel_name}">Download video</a>
<a href="#{url}">Open embed</a> | <a href="#{root_url}/twitch/watch?url=#{vod_id || channel_name}&open">Open in VLC</a> | <a href="#{root_url}/twitch/download?url=#{vod_id || channel_name}">Download video</a>
EOF
elsif %r{^https?://(?:www\.)?soundcloud\.com/(?<artist>[^/]+)/(?<set>sets/)?(?<track>[^/?#]+)} =~ self
# https://soundcloud.com/infectedmushroom/liquid-smoke
Expand Down

0 comments on commit 2450215

Please sign in to comment.