convert 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/convert.gemspec +2 -2
  4. data/lib/convert.rb +15 -21
  5. data/lib/converters/auto_link.rb +16 -14
  6. data/lib/converters/dailymotion.rb +12 -10
  7. data/lib/converters/decode.rb +6 -4
  8. data/lib/converters/email_escape.rb +16 -14
  9. data/lib/converters/encode.rb +6 -4
  10. data/lib/converters/flickr.rb +16 -14
  11. data/lib/converters/gist.rb +12 -10
  12. data/lib/converters/google_maps.rb +30 -28
  13. data/lib/converters/hashtag.rb +11 -9
  14. data/lib/converters/html_escape.rb +9 -7
  15. data/lib/converters/iframe_embed.rb +8 -6
  16. data/lib/converters/image_tag.rb +8 -6
  17. data/lib/converters/instagram.rb +10 -8
  18. data/lib/converters/kramdown.rb +14 -12
  19. data/lib/converters/liveleak.rb +22 -20
  20. data/lib/converters/markdown.rb +16 -14
  21. data/lib/converters/metacafe.rb +23 -21
  22. data/lib/converters/nokogiri.rb +27 -25
  23. data/lib/converters/redcarpet.rb +8 -6
  24. data/lib/converters/sanitize.rb +10 -8
  25. data/lib/converters/simple_format.rb +8 -6
  26. data/lib/converters/soundcloud.rb +31 -29
  27. data/lib/converters/strip_params.rb +9 -7
  28. data/lib/converters/ted.rb +23 -21
  29. data/lib/converters/twitter.rb +15 -13
  30. data/lib/converters/unescape_html.rb +8 -6
  31. data/lib/converters/video_embed.rb +20 -18
  32. data/lib/converters/vimeo.rb +28 -26
  33. data/lib/converters/vimeo_embed.rb +8 -6
  34. data/lib/converters/worldstar.rb +14 -12
  35. data/lib/converters/youtube.rb +40 -38
  36. data/lib/converters/youtube_embed.rb +8 -6
  37. data/lib/converters/youtube_image.rb +30 -28
  38. data/lib/converters/youtube_js_api.rb +13 -11
  39. data/mod.rb +13 -0
  40. metadata +3 -3
  41. data/test.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 801baa051b323492f08661c4974bdcbcb7d74cc8
4
- data.tar.gz: 4ed88e46bdb61689d748b3ec710515311627c90b
3
+ metadata.gz: a22241a31ca94ae8d3a66c4ade462391d65be420
4
+ data.tar.gz: e0f125711a785f1a5b85247c8fe5dde78ff84487
5
5
  SHA512:
6
- metadata.gz: 87f7bb5c719508441109fcb41deddd9a061308099a47dc10d5a38adaf0209f449d7339ae8789fa80838c22f57886c56e5dc92bbcc029eb9de2dfd7a4497647b7
7
- data.tar.gz: 3d552b2eed413435ef9df66ec6e04bfb19f2d2733da2a4fb47c2ecc55a851b9a760451c6678df9f3bfe88e99c5b0e4e788d076571b8310f73d4b2c031177d766
6
+ metadata.gz: 074a8650dd8e2e300f471eca8cbeb29c35b0964ba4e5c0305b8d3b3a8d7be2fd07f7bb0687fd326eb467568b3a7f044e1bea662db8485f804569bb3a2042de9e
7
+ data.tar.gz: 9e20b6614dc40bb7e7e851b828d6f60c3a6330f47308d6392a245c5ec27914cac0f42b007ae909979e32fd570a9ba15de54396661abcf44305debafd4a74a943
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ **Version 0.1.2** - *2016-05-01*
2
+
3
+ - Fixed gem files not being included
4
+
1
5
  **Version 0.1.1** - *2016-05-01*
2
6
 
3
7
  - Fixed gemspec issues
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.2'
4
- s.date = '2017-01-05'
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
- # Autoload for faster loading
10
- module Converters
11
- autoload :Redcarpet, 'redcarpet'
12
- autoload :Kramdown, 'kramdown'
13
- autoload :Rinku, 'rinku'
14
- autoload :Sanitize, 'sanitize'
15
- autoload :HTMLEntities, 'htmlentities'
16
- end
17
- autoload :Nokogiri, 'nokogiri'
18
-
19
- # # # # # #
20
- # The Convert module is responsible for converting strings
21
- #
22
- class Convert
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
 
@@ -1,19 +1,21 @@
1
- module Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- # Convert URL to html link
4
- def auto_link(string, options = {})
5
- options = {
6
- :mode => :all,
7
- :link_attr => nil,
8
- :skip_tags => nil,
9
- :strip => false
10
- }.merge(options)
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
- Rinku.auto_link(string, options[:mode], options[:link_attr], options[:skip_tags]) do |url|
13
- # Remove query options (default false)
14
- url = strip_params(url) if options[:strip]
15
- url
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 Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- def dailymotion(string, options = {})
4
- # http://www.dailymotion.com/video/x3gpxwp_first-person-view-of-a-downhill-ice-cross-course-red-bull-crashed-ice-2015_sport
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
- # Original 480 360
7
- options = {:width => 590, :height => 335}.merge(options)
7
+ # Original 480 360
8
+ options = {:width => 590, :height => 335}.merge(options)
8
9
 
9
- @regex = /http:\/\/www\.dailymotion\.com.*\/video\/(.+)_*/
10
+ @regex = /http:\/\/www\.dailymotion\.com.*\/video\/(.+)_*/
10
11
 
11
- string.gsub(@regex) do
12
- video_id = $1
13
- %{<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>}
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
@@ -1,7 +1,9 @@
1
- module Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- def decode(string, options = {})
4
- HTMLEntities.new.decode(string)
5
- end
4
+ def decode(string, options = {})
5
+ HTMLEntities.new.decode(string)
6
+ end
6
7
 
8
+ end
7
9
  end
@@ -1,20 +1,22 @@
1
- module Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- # Remove stuff from email body that is going to be stripped anyway.
4
- def email_escape(string, options = {})
4
+ # Remove stuff from email body that is going to be stripped anyway.
5
+ def email_escape(string, options = {})
5
6
 
6
- # No options at the moment
7
- options = {}.merge(options)
7
+ # No options at the moment
8
+ options = {}.merge(options)
8
9
 
9
- # Youtube videos
10
- @regex = /<iframe.+src=['"].+\/embed\/(.+)[?].+['"].+iframe>/
11
- string = string.gsub(@regex, "https://youtu.be/#{'\1'}")
10
+ # Youtube videos
11
+ @regex = /<iframe.+src=['"].+\/embed\/(.+)[?].+['"].+iframe>/
12
+ string = string.gsub(@regex, "https://youtu.be/#{'\1'}")
12
13
 
13
- # Vimeo videos
14
- # Example: https://vimeo.com/59437462
15
- @regex = /<iframe.+src=['"]\/\/player\.vimeo.com\/video\/(.+)[?]{1}.+['"].+iframe>/
16
- string = string.gsub(@regex, "https://vimeo.com/#{'\1'}")
17
- string
18
- end
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
@@ -1,7 +1,9 @@
1
- module Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- def encode(string, options = {})
4
- HTMLEntities.new.encode(string)
5
- end
4
+ def encode(string, options = {})
5
+ HTMLEntities.new.encode(string)
6
+ end
6
7
 
8
+ end
7
9
  end
@@ -1,23 +1,25 @@
1
- module Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- def flickr(string, options = {})
4
- # https://www.flickr.com/photos/fotokunstsusanne/23160248869
4
+ def flickr(string, options = {})
5
+ # https://www.flickr.com/photos/fotokunstsusanne/23160248869
5
6
 
6
- {:maxwidth => nil, :maxheight => nil, :link_options => {}}.merge(options)
7
- @regex = %r{https?://(www\.)?flickr\.com/photos/[^\s<]*}
7
+ {:maxwidth => nil, :maxheight => nil, :link_options => {}}.merge(options)
8
+ @regex = %r{https?://(www\.)?flickr\.com/photos/[^\s<]*}
8
9
 
9
- string.gsub(@regex) do |match|
10
- params = { :url => match, :format => "json" }
11
- [:maxwidth, :maxheight].each{|p| params[p] = options[p] unless options[p].nil? or !options[p] > 0}
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
- uri = URI("http://www.flickr.com/services/oembed")
14
- uri.query = URI.encode_www_form(params)
14
+ uri = URI("http://www.flickr.com/services/oembed")
15
+ uri.query = URI.encode_www_form(params)
15
16
 
16
- response = JSON.parse(Net::HTTP.get(uri))
17
+ response = JSON.parse(Net::HTTP.get(uri))
17
18
 
18
- link_options = Array(options[:link_options]).reject { |k,v| v.nil? }.map { |k, v| %{#{k}="#{REXML::Text::normalize(v)}"} }.join(' ')
19
- %{<a href="#{match}"#{ ' ' + link_options unless link_options.empty? }><img src="#{response["url"]}" alt="#{response["title"]}" title="#{response["title"]}" /></a>}
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
@@ -1,17 +1,19 @@
1
- module Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- def gist(string, options = {})
4
- # https://gist.github.com/1710276
4
+ def gist(string, options = {})
5
+ # https://gist.github.com/1710276
5
6
 
6
- # No options at the moment
7
- options = {}.merge(options)
7
+ # No options at the moment
8
+ options = {}.merge(options)
8
9
 
9
- @regex = %r{https?://gist\.github\.com/(\w+/)?(\d+)}
10
+ @regex = %r{https?://gist\.github\.com/(\w+/)?(\d+)}
10
11
 
11
- string.gsub(@regex) do
12
- gist_id = $2
13
- %{<script src="https://gist.github.com/#{gist_id}.js"></script>}
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 Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- def google_maps(string, options = {})
4
- options = {
5
- :width => 420,
6
- :height => 315,
7
- :style => "color:#000;text-align:left",
8
- :link_text => "View Larger Map",
9
- :show_info => true,
10
- :type => :normal,
11
- :zoom => 18,
12
- :more => ''
13
- }.merge(options)
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
- map_type = {:normal => '&t=m', :satellite => '&t=k', :terrain => '&t=p', :hybrid => '&t=h'}
16
+ map_type = {:normal => '&t=m', :satellite => '&t=k', :terrain => '&t=p', :hybrid => '&t=h'}
16
17
 
17
- @regex = /(https?):\/\/maps\.google\.([a-z\.]+)\/maps\?(.*)/
18
+ @regex = /(https?):\/\/maps\.google\.([a-z\.]+)\/maps\?(.*)/
18
19
 
19
- string.gsub(@regex) do
20
- domain_country = $2
21
- map_query = $3
22
- width = options[:width]
23
- height = options[:height]
24
- style = options[:style]
25
- link_text = options[:link_text]
26
- type = options[:type].to_sym
27
- map_options = (options[:show_info] ? '' : '&iwloc=near')
28
- map_options << map_type[type] if map_type.has_key?(type)
29
- map_options << "&z=#{options[:zoom]}"
30
- map_options << options[:more]
31
- %{<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>}
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
@@ -1,14 +1,16 @@
1
- module Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- def hashtag(string, options = {})
4
- options = {:source => :twitter}.merge(options)
5
- @regex = /#([^\s]+)/
4
+ def hashtag(string, options = {})
5
+ options = {:source => :twitter}.merge(options)
6
+ @regex = /#([^\s]+)/
6
7
 
7
- if options[:source] == :twitter
8
- string.gsub(@regex, '<a href="http://twitter.com/search?q=%23\1&f=realtime" class="hashtag" target="_blank">#\1</a>')
9
- elsif options[:source] == :facebook
10
- string.gsub(@regex, '<a href="https://www.facebook.com/hashtag/\1" class="hashtag" target="_blank">#\1</a>')
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 Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- # Escape html
4
- def escape_html(string, options = {})
5
- options = {:map => {'&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' }}.merge(options)
4
+ # Escape html
5
+ def escape_html(string, options = {})
6
+ options = {:map => {'&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' }}.merge(options)
6
7
 
7
- @regex = /[&"><]/
8
- string.gsub(@regex){|m| options[:map][m]}
9
- end
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 Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- # Iframe embed code
4
- def iframe_embed(url, options = {})
5
- options = {:width => 231, :height => 436, :scrolling => 'no', :frameborder => 0}.merge(options)
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
- %{<iframe frameborder="#{options[:frameborder]}" scrolling="#{options[:scrolling]}" height="#{options[:height]}" width="#{options[:width]}" src="#{url}"></iframe>}
8
- end
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
@@ -1,9 +1,11 @@
1
- module Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- # Convert image to img html tag
4
- def image_tag(src, options = {})
5
- options = {:alt => ''}.merge(options)
6
- %{<img src="#{src}" alt="#{options[:alt]}">}
7
- end
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
@@ -1,13 +1,15 @@
1
- module Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- def instagram(string, options = {})
4
- options = {:height => 714, :width => 616}.merge(options)
5
- @regex = %r{https?:\/\/(www.)?instagr(am\.com|\.am)/p/.+}
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
- string.gsub(@regex) do
8
- string += '/' unless string.end_with?('/')
9
- %{<iframe src="#{string}embed" height="#{options[:height]}" width="#{options[:width]}" frameborder="0" scrolling="no"></iframe>}
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