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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a22241a31ca94ae8d3a66c4ade462391d65be420
|
4
|
+
data.tar.gz: e0f125711a785f1a5b85247c8fe5dde78ff84487
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 074a8650dd8e2e300f471eca8cbeb29c35b0964ba4e5c0305b8d3b3a8d7be2fd07f7bb0687fd326eb467568b3a7f044e1bea662db8485f804569bb3a2042de9e
|
7
|
+
data.tar.gz: 9e20b6614dc40bb7e7e851b828d6f60c3a6330f47308d6392a245c5ec27914cac0f42b007ae909979e32fd570a9ba15de54396661abcf44305debafd4a74a943
|
data/CHANGELOG.md
CHANGED
data/convert.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'convert'
|
3
|
-
s.version = '0.1.
|
4
|
-
s.date = '2017-01-
|
3
|
+
s.version = '0.1.3'
|
4
|
+
s.date = '2017-01-12'
|
5
5
|
s.summary = "Convert strings and HTML to links and embedded content"
|
6
6
|
s.description = "Easily convert any string and replace with links and embedded content from a long list of providers and libraries."
|
7
7
|
s.authors = ["Fugroup Limited"]
|
data/lib/convert.rb
CHANGED
@@ -6,27 +6,21 @@ Dir["#{root}/lib/converters/*.rb"].each{|f| require f}
|
|
6
6
|
# Require the sanitizers
|
7
7
|
Dir["#{root}/lib/sanitizers/*.rb"].each{|f| require f}
|
8
8
|
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
autoload :
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
# # # # # #
|
25
|
-
# Convert strings and HTML from a long list of converters
|
26
|
-
# @homepage: https://github.com/fugroup/convert
|
27
|
-
# @author: Vidar <vidar@fugroup.net>, Fugroup Ltd.
|
28
|
-
# @license: MIT, contributions are welcome.
|
29
|
-
# # # # # #
|
9
|
+
# Convert strings and HTML from a long list of converters
|
10
|
+
# @homepage: https://github.com/fugroup/convert
|
11
|
+
# @author: Vidar <vidar@fugroup.net>, Fugroup Ltd.
|
12
|
+
# @license: MIT, contributions are welcome.
|
13
|
+
module Convert
|
14
|
+
|
15
|
+
# Autoload for faster loading
|
16
|
+
module Converters
|
17
|
+
autoload :Redcarpet, 'redcarpet'
|
18
|
+
autoload :Kramdown, 'kramdown'
|
19
|
+
autoload :Rinku, 'rinku'
|
20
|
+
autoload :Sanitize, 'sanitize'
|
21
|
+
autoload :HTMLEntities, 'htmlentities'
|
22
|
+
end
|
23
|
+
autoload :Nokogiri, 'nokogiri'
|
30
24
|
|
31
25
|
# Some of the matchers are taken from https://github.com/dejan/auto_html
|
32
26
|
|
data/lib/converters/auto_link.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
# Convert URL to html link
|
5
|
+
def auto_link(string, options = {})
|
6
|
+
options = {
|
7
|
+
:mode => :all,
|
8
|
+
:link_attr => nil,
|
9
|
+
:skip_tags => nil,
|
10
|
+
:strip => false
|
11
|
+
}.merge(options)
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Rinku.auto_link(string, options[:mode], options[:link_attr], options[:skip_tags]) do |url|
|
14
|
+
# Remove query options (default false)
|
15
|
+
url = strip_params(url) if options[:strip]
|
16
|
+
url
|
17
|
+
end
|
16
18
|
end
|
17
|
-
end
|
18
19
|
|
20
|
+
end
|
19
21
|
end
|
@@ -1,17 +1,19 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
def dailymotion(string, options = {})
|
5
|
+
# http://www.dailymotion.com/video/x3gpxwp_first-person-view-of-a-downhill-ice-cross-course-red-bull-crashed-ice-2015_sport
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
# Original 480 360
|
8
|
+
options = {:width => 590, :height => 335}.merge(options)
|
8
9
|
|
9
|
-
|
10
|
+
@regex = /http:\/\/www\.dailymotion\.com.*\/video\/(.+)_*/
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
string.gsub(@regex) do
|
13
|
+
video_id = $1
|
14
|
+
%{<object type="application/x-shockwave-flash" data="http://www.dailymotion.com/swf/#{video_id}&related=0" width="#{options[:width]}" height="#{options[:height]}"><param name="movie" value="http://www.dailymotion.com/swf/#{video_id}&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><a href="http://www.dailymotion.com/video/#{video_id}?embed=1"><img src="http://www.dailymotion.com/thumbnail/video/#{video_id}" width="#{options[:width]}" height="#{options[:height]}"/></a></object>}
|
15
|
+
end
|
14
16
|
end
|
15
|
-
end
|
16
17
|
|
18
|
+
end
|
17
19
|
end
|
data/lib/converters/decode.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
# Remove stuff from email body that is going to be stripped anyway.
|
5
|
+
def email_escape(string, options = {})
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
# No options at the moment
|
8
|
+
options = {}.merge(options)
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
# Youtube videos
|
11
|
+
@regex = /<iframe.+src=['"].+\/embed\/(.+)[?].+['"].+iframe>/
|
12
|
+
string = string.gsub(@regex, "https://youtu.be/#{'\1'}")
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
# Vimeo videos
|
15
|
+
# Example: https://vimeo.com/59437462
|
16
|
+
@regex = /<iframe.+src=['"]\/\/player\.vimeo.com\/video\/(.+)[?]{1}.+['"].+iframe>/
|
17
|
+
string = string.gsub(@regex, "https://vimeo.com/#{'\1'}")
|
18
|
+
string
|
19
|
+
end
|
19
20
|
|
21
|
+
end
|
20
22
|
end
|
data/lib/converters/encode.rb
CHANGED
data/lib/converters/flickr.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
def flickr(string, options = {})
|
5
|
+
# https://www.flickr.com/photos/fotokunstsusanne/23160248869
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
{:maxwidth => nil, :maxheight => nil, :link_options => {}}.merge(options)
|
8
|
+
@regex = %r{https?://(www\.)?flickr\.com/photos/[^\s<]*}
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
string.gsub(@regex) do |match|
|
11
|
+
params = { :url => match, :format => "json" }
|
12
|
+
[:maxwidth, :maxheight].each{|p| params[p] = options[p] unless options[p].nil? or !options[p] > 0}
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
uri = URI("http://www.flickr.com/services/oembed")
|
15
|
+
uri.query = URI.encode_www_form(params)
|
15
16
|
|
16
|
-
|
17
|
+
response = JSON.parse(Net::HTTP.get(uri))
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
link_options = Array(options[:link_options]).reject { |k,v| v.nil? }.map { |k, v| %{#{k}="#{REXML::Text::normalize(v)}"} }.join(' ')
|
20
|
+
%{<a href="#{match}"#{ ' ' + link_options unless link_options.empty? }><img src="#{response["url"]}" alt="#{response["title"]}" title="#{response["title"]}" /></a>}
|
21
|
+
end
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
24
|
+
end
|
23
25
|
end
|
data/lib/converters/gist.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
def gist(string, options = {})
|
5
|
+
# https://gist.github.com/1710276
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
# No options at the moment
|
8
|
+
options = {}.merge(options)
|
8
9
|
|
9
|
-
|
10
|
+
@regex = %r{https?://gist\.github\.com/(\w+/)?(\d+)}
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
string.gsub(@regex) do
|
13
|
+
gist_id = $2
|
14
|
+
%{<script src="https://gist.github.com/#{gist_id}.js"></script>}
|
15
|
+
end
|
14
16
|
end
|
15
|
-
end
|
16
17
|
|
18
|
+
end
|
17
19
|
end
|
@@ -1,35 +1,37 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
def google_maps(string, options = {})
|
5
|
+
options = {
|
6
|
+
:width => 420,
|
7
|
+
:height => 315,
|
8
|
+
:style => "color:#000;text-align:left",
|
9
|
+
:link_text => "View Larger Map",
|
10
|
+
:show_info => true,
|
11
|
+
:type => :normal,
|
12
|
+
:zoom => 18,
|
13
|
+
:more => ''
|
14
|
+
}.merge(options)
|
14
15
|
|
15
|
-
|
16
|
+
map_type = {:normal => '&t=m', :satellite => '&t=k', :terrain => '&t=p', :hybrid => '&t=h'}
|
16
17
|
|
17
|
-
|
18
|
+
@regex = /(https?):\/\/maps\.google\.([a-z\.]+)\/maps\?(.*)/
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
20
|
+
string.gsub(@regex) do
|
21
|
+
domain_country = $2
|
22
|
+
map_query = $3
|
23
|
+
width = options[:width]
|
24
|
+
height = options[:height]
|
25
|
+
style = options[:style]
|
26
|
+
link_text = options[:link_text]
|
27
|
+
type = options[:type].to_sym
|
28
|
+
map_options = (options[:show_info] ? '' : '&iwloc=near')
|
29
|
+
map_options << map_type[type] if map_type.has_key?(type)
|
30
|
+
map_options << "&z=#{options[:zoom]}"
|
31
|
+
map_options << options[:more]
|
32
|
+
%{<iframe width="#{width}" height="#{height}" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="//maps.google.#{domain_country}/maps?f=q&source=s_q&#{map_query}&output=embed#{map_options}"></iframe><br><small><a href="//maps.google.#{domain_country}/maps?f=q&source=embed&#{map_query}" style="#{style}">#{link_text}</a></small>}
|
33
|
+
end
|
32
34
|
end
|
33
|
-
end
|
34
35
|
|
36
|
+
end
|
35
37
|
end
|
data/lib/converters/hashtag.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
def hashtag(string, options = {})
|
5
|
+
options = {:source => :twitter}.merge(options)
|
6
|
+
@regex = /#([^\s]+)/
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
if options[:source] == :twitter
|
9
|
+
string.gsub(@regex, '<a href="http://twitter.com/search?q=%23\1&f=realtime" class="hashtag" target="_blank">#\1</a>')
|
10
|
+
elsif options[:source] == :facebook
|
11
|
+
string.gsub(@regex, '<a href="https://www.facebook.com/hashtag/\1" class="hashtag" target="_blank">#\1</a>')
|
12
|
+
end
|
11
13
|
end
|
12
|
-
end
|
13
14
|
|
15
|
+
end
|
14
16
|
end
|
@@ -1,11 +1,13 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
# Escape html
|
5
|
+
def escape_html(string, options = {})
|
6
|
+
options = {:map => {'&' => '&', '>' => '>', '<' => '<', '"' => '"' }}.merge(options)
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
@regex = /[&"><]/
|
9
|
+
string.gsub(@regex){|m| options[:map][m]}
|
10
|
+
end
|
10
11
|
|
12
|
+
end
|
11
13
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
# Iframe embed code
|
5
|
+
def iframe_embed(url, options = {})
|
6
|
+
options = {:width => 231, :height => 436, :scrolling => 'no', :frameborder => 0}.merge(options)
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
%{<iframe frameborder="#{options[:frameborder]}" scrolling="#{options[:scrolling]}" height="#{options[:height]}" width="#{options[:width]}" src="#{url}"></iframe>}
|
9
|
+
end
|
9
10
|
|
11
|
+
end
|
10
12
|
end
|
data/lib/converters/image_tag.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
# Convert image to img html tag
|
5
|
+
def image_tag(src, options = {})
|
6
|
+
options = {:alt => ''}.merge(options)
|
7
|
+
%{<img src="#{src}" alt="#{options[:alt]}">}
|
8
|
+
end
|
8
9
|
|
10
|
+
end
|
9
11
|
end
|
data/lib/converters/instagram.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
def instagram(string, options = {})
|
5
|
+
options = {:height => 714, :width => 616}.merge(options)
|
6
|
+
@regex = %r{https?:\/\/(www.)?instagr(am\.com|\.am)/p/.+}
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
string.gsub(@regex) do
|
9
|
+
string += '/' unless string.end_with?('/')
|
10
|
+
%{<iframe src="#{string}embed" height="#{options[:height]}" width="#{options[:width]}" frameborder="0" scrolling="no"></iframe>}
|
11
|
+
end
|
10
12
|
end
|
11
|
-
end
|
12
13
|
|
14
|
+
end
|
13
15
|
end
|