convert 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,11 +1,13 @@
1
- module Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- def unescape_html(string, options = {})
4
- @regex = /(<.*?[a-z]{0,12}?>)+/i
4
+ def unescape_html(string, options = {})
5
+ @regex = /(<.*?[a-z]{0,12}?>)+/i
5
6
 
6
- string.gsub(@regex) do |tag|
7
- tag.gsub("&lt;", "<").gsub("&gt;", ">")
7
+ string.gsub(@regex) do |tag|
8
+ tag.gsub("&lt;", "<").gsub("&gt;", ">")
9
+ end
8
10
  end
9
- end
10
11
 
12
+ end
11
13
  end
@@ -1,24 +1,26 @@
1
- module Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- # Vimeo and Youtube embed markdown extension
4
- def video_embed(string, options = {})
5
- @regex = /\?\[(youtube|vimeo)\]\(https?:\/\/(www\.)?(vimeo\.com\/|youtu\.be\/|youtube\.com\/watch\?v=)(\S+)\)/
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
- string.scan(@regex).each do |type, prefix, url, id|
8
- r = if('vimeo' == type)
9
- vimeo_embed(options)
10
- elsif('youtube' == type)
11
- youtube_embed(options)
12
- else
13
- nil
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
- # Substitute the original text with the embedded version
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
@@ -1,33 +1,35 @@
1
- module Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- # Convert vimeo movie URL to embedded iframe
4
- def vimeo(string, options = {})
5
- # Original: 440 248
6
- options = {
7
- :width => 590,
8
- :height => 335,
9
- :show_title => false,
10
- :show_byline => false,
11
- :show_portrait => false,
12
- :allow_fullscreen => true
13
- }.merge(options)
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
- @regex = /https?:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/
16
+ @regex = /https?:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/
16
17
 
17
- string.gsub(@regex) do
18
- vimeo_id = $2
19
- width = options[:width]
20
- height = options[:height]
21
- show_title = "title=0" unless options[:show_title]
22
- show_byline = "byline=0" unless options[:show_byline]
23
- show_portrait = "portrait=0" unless options[:show_portrait]
24
- allow_fullscreen = " allowfullscreen" if options[:allow_fullscreen]
25
- frameborder = options[:frameborder] || 0
26
- query_string_variables = [show_title, show_byline, show_portrait].compact.join("&")
27
- query_string = "?" + query_string_variables unless query_string_variables.empty?
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
- %{<iframe src="//player.vimeo.com/video/#{vimeo_id}#{query_string}" width="#{width}" height="#{height}" frameborder="#{frameborder}"#{allow_fullscreen}></iframe>}
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 Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- # Embed vimeo by id
4
- def vimeo_embed(string, options = {})
5
- {:width => 590, :height => 335}.merge(options)
4
+ # Embed vimeo by id
5
+ def vimeo_embed(string, options = {})
6
+ {:width => 590, :height => 335}.merge(options)
6
7
 
7
- %{<iframe src="https://player.vimeo.com/video/#{string}?title=0&byline=0&portrait=0" width="#{options[:width]}" height="#{options[:height]}"></iframe>}
8
- end
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
@@ -1,18 +1,20 @@
1
- module Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- # Convert worldstar movie URL to embedded html
4
- def worldstar(string, options = {})
5
- # Original: 448 374
6
- options = {:width => 590, :height => 335}.merge(options)
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
- @regex = /http:\/\/www\.worldstarhiphop\.com\/videos\/video\.php\?v\=(wshh[A-Za-z0-9]+)/
9
+ @regex = /http:\/\/www\.worldstarhiphop\.com\/videos\/video\.php\?v\=(wshh[A-Za-z0-9]+)/
9
10
 
10
- string.gsub(@regex) do
11
- video_id = $1
12
- width = options[:width]
13
- height = options[:height]
14
- %{<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>}
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
@@ -1,42 +1,44 @@
1
- module Converters
2
-
3
- # Convert youtube movie URL to embedded iframe
4
- def youtube(string, options = {})
5
- # Original: 420 315
6
- options = {
7
- :width => 590,
8
- :height => 335,
9
- :frameborder => 0,
10
- :wmode => 'transparent',
11
- :autoplay => false,
12
- :hide_related => true,
13
- :fs => true,
14
- :modestbranding => true,
15
- :allow_fullscreen => true
16
- }.merge(options)
17
-
18
- @regex = /(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/
19
-
20
- string.gsub(@regex) do
21
- youtube_id = $4
22
- src = "https://www.youtube.com/embed/#{youtube_id}"
23
- width = options[:width]
24
- height = options[:height]
25
- allow_fullscreen = " allowfullscreen" if options[:allow_fullscreen]
26
- frameborder = options[:frameborder]
27
-
28
- a = []
29
- a << "wmode=#{options[:wmode]}" if options[:wmode]
30
- a << "autoplay=1" if options[:autoplay]
31
- a << "rel=0" if options[:hide_related]
32
- a << "modestbranding=1" if options[:modestbranding]
33
- a << "fs=1" if options[:fs]
34
-
35
- src += "?#{a.join '&'}" unless a.empty?
36
-
37
- %{<iframe width="#{width}" height="#{height}" src="#{src}" frameborder="#{frameborder}"#{allow_fullscreen}></iframe>}
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 Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- # Embed youtube by id
4
- def youtube_embed(string, options = {})
5
- options = {:width => 590, :height => 335}.merge(options)
4
+ # Embed youtube by id
5
+ def youtube_embed(string, options = {})
6
+ options = {:width => 590, :height => 335}.merge(options)
6
7
 
7
- %{<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>}
8
- end
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 Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- def youtube_image(string, options = {})
4
- options = {
5
- :width => 320,
6
- :height => 315,
7
- :style => 'medium',
8
- :target => 'blank',
9
- :border => '0'
10
- }.merge(options)
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
- styles = {
13
- 'default' => 'default',
14
- 'high' => 'hqdefault',
15
- 'medium' => 'mqdefault',
16
- 'normal' => 'sddefault',
17
- 'max' => 'maxresdefault'
18
- }
13
+ styles = {
14
+ 'default' => 'default',
15
+ 'high' => 'hqdefault',
16
+ 'medium' => 'mqdefault',
17
+ 'normal' => 'sddefault',
18
+ 'max' => 'maxresdefault'
19
+ }
19
20
 
20
- @regex = /(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/
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
- string.gsub(@regex) do
23
- youtube_id = $4
24
- video_url = "https://www.youtube.com/watch?v=#{youtube_id}"
25
- target = options[:target]
26
- width = options[:width]
27
- height = options[:height]
28
- border = options[:border]
29
- style = styles[options[:style]] rescue styles['default']
30
- src = "//img.youtube.com/vi/#{youtube_id}/#{style}.jpg"
31
- %{<div class="thumbnail youtube"><a href="#{video_url}" target="_#{target}"><img src="#{src}" width="#{width}" height="#{height}" border="#{border}"></a></div>}
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 Converters
1
+ module Convert
2
+ module Converters
2
3
 
3
- def youtube_js_api(string, options = {})
4
- # Original: 390 250
5
- options = {:width => 590, :height => 335}.merge(options)
4
+ def youtube_js_api(string, options = {})
5
+ # Original: 390 250
6
+ options = {:width => 590, :height => 335}.merge(options)
6
7
 
7
- @regex = /https?:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?/
8
+ @regex = /https?:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?/
8
9
 
9
- string.gsub(@regex) do
10
- youtube_id = $2
11
- width = options[:width]
12
- height = options[:height]
10
+ string.gsub(@regex) do
11
+ youtube_id = $2
12
+ width = options[:width]
13
+ height = options[:height]
13
14
 
14
- %{<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>}
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
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Dir['./lib/converters/*.rb'].each do |c|
4
+
5
+ tmp = ['module Convert']
6
+ f = File.readlines(c)
7
+ f.each do |line|
8
+ tmp << " #{line}"
9
+ end
10
+ tmp << 'end'
11
+
12
+ File.open(c, 'w'){|f| f.write(tmp.join)}
13
+ end
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.2
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-05 00:00:00.000000000 Z
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
- - test.rb
164
+ - mod.rb
165
165
  homepage: https://github.com/fugroup/convert
166
166
  licenses:
167
167
  - MIT
data/test.rb DELETED
@@ -1,16 +0,0 @@
1
- class Flat
2
- def initialize
3
- self.class.t
4
- end
5
-
6
- def self.t
7
- puts "TEEEE"
8
- end
9
- end
10
-
11
- f = Flat.new
12
-
13
-
14
-
15
-
16
-