Skip to content

Commit

Permalink
Add undent.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Nov 16, 2016
1 parent e9d8830 commit 3b5988c
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 52 deletions.
13 changes: 9 additions & 4 deletions config/initializers/05-string.rb
Expand Up @@ -24,6 +24,11 @@ def ustrip
self.gsub(/[\u00a0\u3000]/,"").strip
end

def undent
# from https://github.com/Homebrew/brew/blob/c9c7f462d37500549127efba96c7a25e5c70de4a/Library/Homebrew/extend/string.rb#L2-L4
gsub(/^[ \t]{#{(slice(/^[ \t]+/) || '').length}}/, "")
end

def numeric?
/^\d+$/ === self
end
Expand Down Expand Up @@ -144,10 +149,10 @@ def linkify

def embed_html(request)
if %r{^https?://www\.facebook\.com/.*/videos/(?<id>\d+)} =~ self
<<-EOF
<iframe src="https://www.facebook.com/video/embed?video_id=#{id}" width="1280" height="720" frameborder="0" scrolling="no" allowfullscreen></iframe>
<p><a href="https://www.facebook.com/video/embed?video_id=#{id}">Open embed</a></p>
<p><a href="#{request.root_url}/facebook/download?url=#{id}">Download video</a></p>
<<-EOF.undent
<iframe src="https://www.facebook.com/video/embed?video_id=#{id}" width="1280" height="720" frameborder="0" scrolling="no" allowfullscreen></iframe>
<p><a href="https://www.facebook.com/video/embed?video_id=#{id}">Open embed</a></p>
<p><a href="#{request.root_url}/facebook/download?url=#{id}">Download video</a></p>
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 Down
6 changes: 3 additions & 3 deletions views/dailymotion_feed.erb
Expand Up @@ -15,10 +15,10 @@
<updated><%= Time.at(video["created_time"]) %></updated>
<author><name><%= @screenname %></name></author>
<content type="html">
<%= <<-EOF.esc
<iframe width="480" height="270" scrolling="no" frameborder="no" src="https://www.dailymotion.com/embed/video/#{video["id"]}" allowfullscreen></iframe>
<%= <<-EOF.undent.esc
<iframe width="480" height="270" scrolling="no" frameborder="no" src="https://www.dailymotion.com/embed/video/#{video["id"]}" allowfullscreen></iframe>
#{video["description"].to_paragraphs}
#{video["description"].to_paragraphs}
EOF
-%>
</content>
Expand Down
12 changes: 6 additions & 6 deletions views/facebook_feed.erb
Expand Up @@ -62,14 +62,14 @@ end
if @type == "photos" and post["source"]
"<p><img src='#{post["source"]}'></p>".esc
elsif @edge == "videos" and post["id"]
<<-EOF.esc
<p><a href="https://www.facebook.com/video/embed?video_id=#{post["id"]}">Open embed</a></p>
<p><a href="#{request.root_url}/facebook/download?url=#{post["id"]}">Download video</a></p>
<<-EOF.undent.esc
<p><a href="https://www.facebook.com/video/embed?video_id=#{post["id"]}">Open embed</a></p>
<p><a href="#{request.root_url}/facebook/download?url=#{post["id"]}">Download video</a></p>
EOF
elsif post["type"] == "photo"
<<-EOF.esc
<p><a href="#{post["full_picture"]}"><img src="#{post["picture"]}"></a></p>
<p><a href="#{request.root_url}/facebook/download?url=#{post["parent_id"] || post["id"]}">Full size</a></p>
<<-EOF.undent.esc
<p><a href="#{post["full_picture"]}"><img src="#{post["picture"]}"></a></p>
<p><a href="#{request.root_url}/facebook/download?url=#{post["parent_id"] || post["id"]}">Full size</a></p>
EOF
end
%>
Expand Down
22 changes: 11 additions & 11 deletions views/imgur_feed.erb
Expand Up @@ -12,24 +12,24 @@
id = "imgur:album:#{image["id"]}"
title = "Album: #{image["title"]} (#{image["images_count"]} images)"
link = "https://imgur.com/a/#{image["id"]}"
body = <<-EOF.esc
<a href="#{link}"><img src="https://i.imgur.com/#{image["cover"]}h.jpg"></a>
body = <<-EOF.undent.esc
<a href="#{link}"><img src="https://i.imgur.com/#{image["cover"]}h.jpg"></a>
#{image["description"].to_paragraphs}
<p><a href="http://s.imgur.com/a/#{image["id"]}/zip">Download album</a></p>
EOF
#{image["description"].to_paragraphs}
<p><a href="http://s.imgur.com/a/#{image["id"]}/zip">Download album</a></p>
EOF
else
id = "imgur:image:#{image["id"]}"
title = "#{image["title"]} [#{image["width"]}x#{image["height"]}]"
link = "https://imgur.com/#{image["id"]}"
ext = image["type"].split("/")[1]
body = <<-EOF.esc
<a href="#{link}.#{ext}"><img src="https://i.imgur.com/#{image["id"]}h.#{ext}"></a>
body = <<-EOF.undent.esc
<a href="#{link}.#{ext}"><img src="https://i.imgur.com/#{image["id"]}h.#{ext}"></a>
#{image["description"].to_paragraphs}
<p><a href="https://imgur.com/download/#{image["id"]}/#{CGI.escape(image["title"])}">Download</a></p>
<p>Size: #{image["size"].to_filesize} (#{image["width"]}x#{image["height"]})</p>
EOF
#{image["description"].to_paragraphs}
<p><a href="https://imgur.com/download/#{image["id"]}/#{CGI.escape(image["title"])}">Download</a></p>
<p>Size: #{image["size"].to_filesize} (#{image["width"]}x#{image["height"]})</p>
EOF
end
-%>

Expand Down
14 changes: 7 additions & 7 deletions views/instagram_feed.erb
Expand Up @@ -28,15 +28,15 @@
<content type="html">
<%=
if post["is_video"]
<<-EOF.esc
<iframe src="https://www.instagram.com/p/#{post["code"]}/embed/" width="612" height="710" frameborder="0" scrolling="no" allowfullscreen></iframe>
#{post["caption"].to_paragraphs}
<p><a href="#{request.root_url}/instagram/download?url=#{post["code"]}">Download video</a></p>
<<-EOF.undent.esc
<iframe src="https://www.instagram.com/p/#{post["code"]}/embed/" width="612" height="710" frameborder="0" scrolling="no" allowfullscreen></iframe>
#{post["caption"].to_paragraphs}
<p><a href="#{request.root_url}/instagram/download?url=#{post["code"]}">Download video</a></p>
EOF
else
<<-EOF.esc
<img src="#{post["display_src"]}">
#{post["caption"].to_paragraphs}
<<-EOF.undent.esc
<img src="#{post["display_src"]}">
#{post["caption"].to_paragraphs}
EOF
end
-%>
Expand Down
8 changes: 4 additions & 4 deletions views/mixcloud_feed.erb
Expand Up @@ -16,12 +16,12 @@
<author><name><%= track["user"]["username"] %></name></author>
<content type="html">
<%=
<<-EOF.esc
<iframe width="100%" height="120" src="https://www.mixcloud.com/widget/iframe/?feed=#{track["url"]}&hide_cover=1&light=1" frameborder="0"></iframe>
<<-EOF.undent.esc
<iframe width="100%" height="120" src="https://www.mixcloud.com/widget/iframe/?feed=#{track["url"]}&hide_cover=1&light=1" frameborder="0"></iframe>
<a href="#{track["pictures"]["extra_large"]}"><img src="#{track["pictures"]["medium"]}"></a>
<a href="#{track["pictures"]["extra_large"]}"><img src="#{track["pictures"]["medium"]}"></a>
#{track["name"].to_paragraphs}
#{track["name"].to_paragraphs}
EOF
-%>
</content>
Expand Down
6 changes: 3 additions & 3 deletions views/periscope_feed.erb
Expand Up @@ -15,10 +15,10 @@
<updated><%= Time.parse(post["created_at"]) %></updated>
<author><name><%= post["user_display_name"] %></name></author>
<content type="html">
<%= <<-EOF.esc
<p><em>Live in #{post["city"]}.</em></p>
<%= <<-EOF.undent.esc
<p><em>Live in #{post["city"]}.</em></p>
<a href="https://www.periscope.tv/#{post["username"]}/#{post["id"]}"><img src="#{post["image_url"]}"></a>
<a href="https://www.periscope.tv/#{post["username"]}/#{post["id"]}"><img src="#{post["image_url"]}"></a>
EOF
-%>
</content>
Expand Down
12 changes: 6 additions & 6 deletions views/twitch_feed.erb
Expand Up @@ -15,15 +15,15 @@
<updated><%= Time.parse(video["created_at"]) %></updated>
<author><name><%= video["channel"]["display_name"] %></name></author>
<content type="html">
<%= <<-EOF.esc
<p><em>#{video["channel"]["display_name"]} was #{video["game"] ? "playing #{video["game"]}" : "live"}.</em></p>
<%= <<-EOF.undent.esc
<p><em>#{video["channel"]["display_name"]} was #{video["game"] ? "playing #{video["game"]}" : "live"}.</em></p>
<iframe width="620" height="378" src="https://player.twitch.tv/?video=#{video["_id"]}" frameborder="0" scrolling="no" allowfullscreen></iframe>
<iframe width="620" height="378" src="https://player.twitch.tv/?video=#{video["_id"]}" frameborder="0" scrolling="no" allowfullscreen></iframe>
#{video["description"].to_paragraphs}
#{video["description"].to_paragraphs}
<p><a href="https://player.twitch.tv/?video=#{video["_id"]}">Open embed</a></p>
<p><a href="#{request.root_url}/twitch/download?url=#{video["_id"]}">Download video</a></p>
<p><a href="https://player.twitch.tv/?video=#{video["_id"]}">Open embed</a></p>
<p><a href="#{request.root_url}/twitch/download?url=#{video["_id"]}">Download video</a></p>
EOF
-%>
</content>
Expand Down
8 changes: 4 additions & 4 deletions views/vine_feed.erb
Expand Up @@ -22,12 +22,12 @@
<updated><%= Time.parse(post["created"]) %></updated>
<author><name><%= post["username"] %></name></author>
<content type="html">
<%= <<-EOF.esc
<iframe width="600" height="600" scrolling="no" frameborder="no" src="#{post["permalinkUrl"]}/embed/simple" allowfullscreen></iframe>
<%= <<-EOF.undent.esc
<iframe width="600" height="600" scrolling="no" frameborder="no" src="#{post["permalinkUrl"]}/embed/simple" allowfullscreen></iframe>
<p>#{post["description"]}</p>
<p>#{post["description"]}</p>
<a href="#{request.root_url}/vine/download?url=#{post["shareUrl"]}">Download video</a>
<a href="#{request.root_url}/vine/download?url=#{post["shareUrl"]}">Download video</a>
EOF
-%>
</content>
Expand Down
8 changes: 4 additions & 4 deletions views/youtube_feed.erb
Expand Up @@ -33,10 +33,10 @@
<updated><%= updated %></updated>
<author><name><%= @username %></name></author>
<content type="html">
<%= <<-EOF.esc
<iframe width="640" height="360" src="https://www.youtube.com/embed/#{video["id"]["videoId"]}?rel=0" frameborder="0" scrolling="no" allowfullscreen></iframe>
#{content_extra}
#{video["snippet"]["description"].to_paragraphs}
<%= <<-EOF.undent.esc
<iframe width="640" height="360" src="https://www.youtube.com/embed/#{video["id"]["videoId"]}?rel=0" frameborder="0" scrolling="no" allowfullscreen></iframe>
#{content_extra}
#{video["snippet"]["description"].to_paragraphs}
EOF
-%>
</content>
Expand Down

0 comments on commit 3b5988c

Please sign in to comment.