convert 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/convert.gemspec +2 -2
- data/lib/convert.rb +15 -21
- data/lib/converters/auto_link.rb +16 -14
- data/lib/converters/dailymotion.rb +12 -10
- data/lib/converters/decode.rb +6 -4
- data/lib/converters/email_escape.rb +16 -14
- data/lib/converters/encode.rb +6 -4
- data/lib/converters/flickr.rb +16 -14
- data/lib/converters/gist.rb +12 -10
- data/lib/converters/google_maps.rb +30 -28
- data/lib/converters/hashtag.rb +11 -9
- data/lib/converters/html_escape.rb +9 -7
- data/lib/converters/iframe_embed.rb +8 -6
- data/lib/converters/image_tag.rb +8 -6
- data/lib/converters/instagram.rb +10 -8
- data/lib/converters/kramdown.rb +14 -12
- data/lib/converters/liveleak.rb +22 -20
- data/lib/converters/markdown.rb +16 -14
- data/lib/converters/metacafe.rb +23 -21
- data/lib/converters/nokogiri.rb +27 -25
- data/lib/converters/redcarpet.rb +8 -6
- data/lib/converters/sanitize.rb +10 -8
- data/lib/converters/simple_format.rb +8 -6
- data/lib/converters/soundcloud.rb +31 -29
- data/lib/converters/strip_params.rb +9 -7
- data/lib/converters/ted.rb +23 -21
- data/lib/converters/twitter.rb +15 -13
- data/lib/converters/unescape_html.rb +8 -6
- data/lib/converters/video_embed.rb +20 -18
- data/lib/converters/vimeo.rb +28 -26
- data/lib/converters/vimeo_embed.rb +8 -6
- data/lib/converters/worldstar.rb +14 -12
- data/lib/converters/youtube.rb +40 -38
- data/lib/converters/youtube_embed.rb +8 -6
- data/lib/converters/youtube_image.rb +30 -28
- data/lib/converters/youtube_js_api.rb +13 -11
- data/mod.rb +13 -0
- metadata +3 -3
- data/test.rb +0 -16
@@ -1,11 +1,13 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
def unescape_html(string, options = {})
|
5
|
+
@regex = /(<.*?[a-z]{0,12}?>)+/i
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
string.gsub(@regex) do |tag|
|
8
|
+
tag.gsub("<", "<").gsub(">", ">")
|
9
|
+
end
|
8
10
|
end
|
9
|
-
end
|
10
11
|
|
12
|
+
end
|
11
13
|
end
|
@@ -1,24 +1,26 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
# Vimeo and Youtube embed markdown extension
|
5
|
+
def video_embed(string, options = {})
|
6
|
+
@regex = /\?\[(youtube|vimeo)\]\(https?:\/\/(www\.)?(vimeo\.com\/|youtu\.be\/|youtube\.com\/watch\?v=)(\S+)\)/
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
string.scan(@regex).each do |type, prefix, url, id|
|
9
|
+
r = if('vimeo' == type)
|
10
|
+
vimeo_embed(options)
|
11
|
+
elsif('youtube' == type)
|
12
|
+
youtube_embed(options)
|
13
|
+
else
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
# Substitute the original text with the embedded version
|
17
|
+
# OLD, optional https not supported:
|
18
|
+
# @text.gsub!("?[#{type}](https://#{prefix}#{url}#{id})", r) if r
|
19
|
+
x = %r{\?\[#{type}\]\(https?:\/\/#{Regexp.escape(prefix)}#{Regexp.escape(url)}#{id}\)}i
|
20
|
+
string.gsub!(x, r) if r
|
14
21
|
end
|
15
|
-
|
16
|
-
# OLD, optional https not supported:
|
17
|
-
# @text.gsub!("?[#{type}](https://#{prefix}#{url}#{id})", r) if r
|
18
|
-
x = %r{\?\[#{type}\]\(https?:\/\/#{Regexp.escape(prefix)}#{Regexp.escape(url)}#{id}\)}i
|
19
|
-
string.gsub!(x, r) if r
|
22
|
+
string
|
20
23
|
end
|
21
|
-
string
|
22
|
-
end
|
23
24
|
|
25
|
+
end
|
24
26
|
end
|
data/lib/converters/vimeo.rb
CHANGED
@@ -1,33 +1,35 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
# Convert vimeo movie URL to embedded iframe
|
5
|
+
def vimeo(string, options = {})
|
6
|
+
# Original: 440 248
|
7
|
+
options = {
|
8
|
+
:width => 590,
|
9
|
+
:height => 335,
|
10
|
+
:show_title => false,
|
11
|
+
:show_byline => false,
|
12
|
+
:show_portrait => false,
|
13
|
+
:allow_fullscreen => true
|
14
|
+
}.merge(options)
|
14
15
|
|
15
|
-
|
16
|
+
@regex = /https?:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
string.gsub(@regex) do
|
19
|
+
vimeo_id = $2
|
20
|
+
width = options[:width]
|
21
|
+
height = options[:height]
|
22
|
+
show_title = "title=0" unless options[:show_title]
|
23
|
+
show_byline = "byline=0" unless options[:show_byline]
|
24
|
+
show_portrait = "portrait=0" unless options[:show_portrait]
|
25
|
+
allow_fullscreen = " allowfullscreen" if options[:allow_fullscreen]
|
26
|
+
frameborder = options[:frameborder] || 0
|
27
|
+
query_string_variables = [show_title, show_byline, show_portrait].compact.join("&")
|
28
|
+
query_string = "?" + query_string_variables unless query_string_variables.empty?
|
28
29
|
|
29
|
-
|
30
|
+
%{<iframe src="//player.vimeo.com/video/#{vimeo_id}#{query_string}" width="#{width}" height="#{height}" frameborder="#{frameborder}"#{allow_fullscreen}></iframe>}
|
31
|
+
end
|
30
32
|
end
|
31
|
-
end
|
32
33
|
|
34
|
+
end
|
33
35
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
# Embed vimeo by id
|
5
|
+
def vimeo_embed(string, options = {})
|
6
|
+
{:width => 590, :height => 335}.merge(options)
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
%{<iframe src="https://player.vimeo.com/video/#{string}?title=0&byline=0&portrait=0" width="#{options[:width]}" height="#{options[:height]}"></iframe>}
|
9
|
+
end
|
9
10
|
|
11
|
+
end
|
10
12
|
end
|
data/lib/converters/worldstar.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
# Convert worldstar movie URL to embedded html
|
5
|
+
def worldstar(string, options = {})
|
6
|
+
# Original: 448 374
|
7
|
+
options = {:width => 590, :height => 335}.merge(options)
|
7
8
|
|
8
|
-
|
9
|
+
@regex = /http:\/\/www\.worldstarhiphop\.com\/videos\/video\.php\?v\=(wshh[A-Za-z0-9]+)/
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
string.gsub(@regex) do
|
12
|
+
video_id = $1
|
13
|
+
width = options[:width]
|
14
|
+
height = options[:height]
|
15
|
+
%{<object width="#{width}" height="#{height}"><param name="movie" value="http://www.worldstarhiphop.com/videos/e/16711680/#{video_id}"><param name="allowFullScreen" value="true"></param><embed src="http://www.worldstarhiphop.com/videos/e/16711680/#{video_id}" type="application/x-shockwave-flash" allowFullscreen="true" width="#{width}" height="#{height}"></embed></object>}
|
16
|
+
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
19
|
+
end
|
18
20
|
end
|
data/lib/converters/youtube.rb
CHANGED
@@ -1,42 +1,44 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
1
|
+
module Convert
|
2
|
+
module Converters
|
3
|
+
|
4
|
+
# Convert youtube movie URL to embedded iframe
|
5
|
+
def youtube(string, options = {})
|
6
|
+
# Original: 420 315
|
7
|
+
options = {
|
8
|
+
:width => 590,
|
9
|
+
:height => 335,
|
10
|
+
:frameborder => 0,
|
11
|
+
:wmode => 'transparent',
|
12
|
+
:autoplay => false,
|
13
|
+
:hide_related => true,
|
14
|
+
:fs => true,
|
15
|
+
:modestbranding => true,
|
16
|
+
:allow_fullscreen => true
|
17
|
+
}.merge(options)
|
18
|
+
|
19
|
+
@regex = /(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/
|
20
|
+
|
21
|
+
string.gsub(@regex) do
|
22
|
+
youtube_id = $4
|
23
|
+
src = "https://www.youtube.com/embed/#{youtube_id}"
|
24
|
+
width = options[:width]
|
25
|
+
height = options[:height]
|
26
|
+
allow_fullscreen = " allowfullscreen" if options[:allow_fullscreen]
|
27
|
+
frameborder = options[:frameborder]
|
28
|
+
|
29
|
+
a = []
|
30
|
+
a << "wmode=#{options[:wmode]}" if options[:wmode]
|
31
|
+
a << "autoplay=1" if options[:autoplay]
|
32
|
+
a << "rel=0" if options[:hide_related]
|
33
|
+
a << "modestbranding=1" if options[:modestbranding]
|
34
|
+
a << "fs=1" if options[:fs]
|
35
|
+
|
36
|
+
src += "?#{a.join '&'}" unless a.empty?
|
37
|
+
|
38
|
+
%{<iframe width="#{width}" height="#{height}" src="#{src}" frameborder="#{frameborder}"#{allow_fullscreen}></iframe>}
|
39
|
+
end
|
38
40
|
end
|
41
|
+
|
39
42
|
end
|
40
43
|
|
41
44
|
end
|
42
|
-
|
@@ -1,10 +1,12 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
# Embed youtube by id
|
5
|
+
def youtube_embed(string, options = {})
|
6
|
+
options = {:width => 590, :height => 335}.merge(options)
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
%{<iframe src="https://www.youtube.com/embed/#{string}?wmode=transparent&modestbranding=1&fs=1&rel=0" allowfullscreen="1" webkitallowfullscreen="1" mozallowfullscreen="1" width="#{options[:width]}" height="#{options[:height]}" frameborder="0"></iframe>}
|
9
|
+
end
|
9
10
|
|
11
|
+
end
|
10
12
|
end
|
@@ -1,35 +1,37 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
def youtube_image(string, options = {})
|
5
|
+
options = {
|
6
|
+
:width => 320,
|
7
|
+
:height => 315,
|
8
|
+
:style => 'medium',
|
9
|
+
:target => 'blank',
|
10
|
+
:border => '0'
|
11
|
+
}.merge(options)
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
styles = {
|
14
|
+
'default' => 'default',
|
15
|
+
'high' => 'hqdefault',
|
16
|
+
'medium' => 'mqdefault',
|
17
|
+
'normal' => 'sddefault',
|
18
|
+
'max' => 'maxresdefault'
|
19
|
+
}
|
19
20
|
|
20
|
-
|
21
|
+
@regex = /(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
string.gsub(@regex) do
|
24
|
+
youtube_id = $4
|
25
|
+
video_url = "https://www.youtube.com/watch?v=#{youtube_id}"
|
26
|
+
target = options[:target]
|
27
|
+
width = options[:width]
|
28
|
+
height = options[:height]
|
29
|
+
border = options[:border]
|
30
|
+
style = styles[options[:style]] rescue styles['default']
|
31
|
+
src = "//img.youtube.com/vi/#{youtube_id}/#{style}.jpg"
|
32
|
+
%{<div class="thumbnail youtube"><a href="#{video_url}" target="_#{target}"><img src="#{src}" width="#{width}" height="#{height}" border="#{border}"></a></div>}
|
33
|
+
end
|
32
34
|
end
|
33
|
-
end
|
34
35
|
|
36
|
+
end
|
35
37
|
end
|
@@ -1,18 +1,20 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
def youtube_js_api(string, options = {})
|
5
|
+
# Original: 390 250
|
6
|
+
options = {:width => 590, :height => 335}.merge(options)
|
6
7
|
|
7
|
-
|
8
|
+
@regex = /https?:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?/
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
string.gsub(@regex) do
|
11
|
+
youtube_id = $2
|
12
|
+
width = options[:width]
|
13
|
+
height = options[:height]
|
13
14
|
|
14
|
-
|
15
|
+
%{<object width="#{width}" height="#{height}"><param name="movie" value="//www.youtube.com/v/#{youtube_id}?enablejsapi=1&playerapiid=ytplayer"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="//www.youtube.com/v/#{youtube_id}?enablejsapi=1&playerapiid=ytplayer" type="application/x-shockwave-flash" wmode="transparent" width="#{width}" height="#{height}" allowscriptaccess="always"></embed></object>}
|
16
|
+
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
19
|
+
end
|
18
20
|
end
|
data/mod.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: convert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fugroup Limited
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redcarpet
|
@@ -161,7 +161,7 @@ files:
|
|
161
161
|
- lib/sanitizers/full.rb
|
162
162
|
- lib/sanitizers/linebreaks.rb
|
163
163
|
- lib/sanitizers/simple.rb
|
164
|
-
-
|
164
|
+
- mod.rb
|
165
165
|
homepage: https://github.com/fugroup/convert
|
166
166
|
licenses:
|
167
167
|
- MIT
|