auto_html 1.6.1 → 1.6.2

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.
data/README.md CHANGED
@@ -36,7 +36,7 @@ You'll probably have user input stored in model, so it's a good place to automat
36
36
  ... and you'll have this behavior:
37
37
 
38
38
  Comment.create(:body => 'Hey check out this cool video: http://www.youtube.com/watch?v=WdsGihou8J4')
39
- => #<Comment id: 123, body: '<p>Hey check out this cool video: <iframe class="youtube-player" type="text/html" width="587" height="350" src="http://www.youtube.com/embed/WdsGihou8J4" frameborder="0"> <br /></iframe></p>'>
39
+ => #<Comment id: 123, body: '<p>Hey check out this cool video: <div class="video youtube"><iframe class="youtube-player" type="text/html" width="587" height="350" src="http://www.youtube.com/embed/WdsGihou8J4" frameborder="0"> <br /></iframe></div></p>'>
40
40
 
41
41
  Note that order of invoking filters is important, i.e. you want html_escape as first and link amongst last, so that it doesn't transform youtube URL to plain link.
42
42
 
@@ -1,8 +1,8 @@
1
- require 'uri'
2
- require 'net/http'
3
- require 'rexml/document'
4
-
5
1
  AutoHtml.add_filter(:flickr).with(:maxwidth => nil, :maxheight => nil, :link_options => {}) do |text, options|
2
+ require 'uri'
3
+ require 'net/http'
4
+ require 'rexml/document'
5
+
6
6
  regex = %r{http://(www\.)?flickr\.com/photos/[^\s<]*}
7
7
 
8
8
  text.gsub(regex) do |match|
@@ -3,6 +3,6 @@ AutoHtml.add_filter(:gist).with({}) do |text, options|
3
3
  regex = %r{https?://gist\.github\.com/(\w+/)?(\d+)}
4
4
  text.gsub(regex) do
5
5
  gist_id = $2
6
- %{<script src="https://gist.github.com/#{gist_id}.js"></script>}
6
+ %{<script type="text/javascript" src="https://gist.github.com/#{gist_id}.js"></script>}
7
7
  end
8
8
  end
@@ -1,7 +1,7 @@
1
1
  AutoHtml.add_filter(:hashtag).with(:source => :twitter) do |text, options|
2
2
  if options[:source] == :twitter
3
- text.gsub(/#([^ ]+)/, '<a href="http://twitter.com/search?q=%23\1&f=realtime" class="hashtag" target="_blank">#\1</a>')
3
+ text.gsub(/#([^\s]+)/, '<a href="http://twitter.com/search?q=%23\1&f=realtime" class="hashtag" target="_blank">#\1</a>')
4
4
  elsif options[:source] == :facebook
5
- text.gsub(/#([^ ]+)/, '<a href="https://www.facebook.com/hashtag/\1" class="hashtag" target="_blank">#\1</a>')
5
+ text.gsub(/#([^\s]+)/, '<a href="https://www.facebook.com/hashtag/\1" class="hashtag" target="_blank">#\1</a>')
6
6
  end
7
7
  end
@@ -0,0 +1,10 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+
4
+ AutoHtml.add_filter(:instagram) do |text|
5
+ text << '/' unless text.end_with?('/')
6
+ regex = %r{https?:\/\/(www.)?instagr(am\.com|\.am)/p/.+}
7
+ text.gsub(regex) do
8
+ %{<iframe src="#{text}embed" height="714" width="616" frameborder="0" scrolling="no"></iframe>}
9
+ end
10
+ end
@@ -1,8 +1,7 @@
1
- require 'uri'
2
- require 'rinku'
3
- require 'rexml/document'
4
-
5
1
  AutoHtml.add_filter(:link).with({}) do |text, options|
2
+ require 'uri'
3
+ require 'rinku'
4
+ require 'rexml/document'
6
5
  option_short_link_name = options.delete(:short_link_name)
7
6
  attributes = Array(options).reject { |k,v| v.nil? }.map { |k, v| %{#{k}="#{REXML::Text::normalize(v)}"} }.join(' ')
8
7
  Rinku.auto_link(text, :all, attributes) do |url|
@@ -1,5 +1,4 @@
1
1
  require 'redcarpet'
2
-
3
2
  AutoHtml.add_filter(:redcarpet).with(:renderer => Redcarpet::Render::HTML, :markdown_options => {}) do |text, options|
4
3
  Redcarpet::Markdown.new(options[:renderer], options[:markdown_options]).render(text)
5
- end
4
+ end
@@ -1,6 +1,5 @@
1
- require 'action_controller'
2
- require 'cgi'
3
-
4
1
  AutoHtml.add_filter(:sanitize).with({}) do |text, options|
2
+ require 'action_controller'
3
+ require 'cgi'
5
4
  HTML::WhiteListSanitizer.new.sanitize(text, options)
6
- end
5
+ end
@@ -1,6 +1,6 @@
1
- require 'action_view'
2
-
3
1
  AutoHtml.add_filter(:simple_format).with({}) do |text, html_options|
2
+ require 'action_view'
3
+
4
4
  args = [text, {}, {:sanitize => false}]
5
5
  begin
6
6
  ActionView::Base.new.simple_format(*args)
@@ -1,9 +1,10 @@
1
1
  # encoding: UTF-8
2
- require 'uri'
3
2
 
4
3
  # set these options and default values
5
4
  # :width => '100%', :height => 166, :auto_play => false, :theme_color => '00FF00', :color => '915f33', :show_comments => false
6
5
  AutoHtml.add_filter(:soundcloud).with(:width => '100%', :height => 166, :auto_play => false, :theme_color => '00FF00', :color => '915f33', :show_comments => false, :show_artwork => false) do |text, options|
6
+ require 'uri'
7
+ require 'net/http'
7
8
  text.gsub(/(https?:\/\/)?(www.)?soundcloud\.com\/\S*/) do |match|
8
9
  new_uri = match.to_s
9
10
  new_uri = (new_uri =~ /^https?\:\/\/.*/) ? URI(new_uri) : URI("http://#{new_uri}")
@@ -0,0 +1,13 @@
1
+ # TED talks (http://www.ted.com)
2
+ AutoHtml.add_filter(:ted).with(:width => 640, :height => 360, :scrolling => "no", :frameborder => 0, :allow_full_screen => false) do |text, options|
3
+ text.gsub(/https?:\/\/(www.|embed.)?ted\.com\/talks\/([A-Za-z0-9._%-]*)\.html((\?|#)\S+)?/) do
4
+ ted_page = $2
5
+ width = options[:width]
6
+ height = options[:height]
7
+ scrolling = options[:scrolling]
8
+ frameborder = options[:frameborder]
9
+ allow_full_screen = options[:allow_full_screen]
10
+
11
+ %{<iframe width="#{width}" height="#{height}" frameborder="#{frameborder}" scrolling="#{scrolling}" src="http://embed.ted.com/talks/#{ted_page}.html"#{allow_full_screen ? ' webkitAllowFullScreen mozallowfullscreen allowFullScreen' : ''}></iframe>}
12
+ end
13
+ end
@@ -1,7 +1,7 @@
1
- require 'uri'
2
- require 'net/http'
3
-
4
1
  AutoHtml.add_filter(:twitter).with({}) do |text, options|
2
+ require 'uri'
3
+ require 'net/http'
4
+
5
5
  regex = %r{(?<!href=")https://twitter\.com(/#!)?/[A-Za-z0-9_]{1,15}/status(es)?/\d+}
6
6
 
7
7
  text.gsub(regex) do |match|
@@ -1,7 +1,7 @@
1
1
  AutoHtml.add_filter(:youtube).with(:width => 420, :height => 315, :frameborder => 0, :wmode => nil, :autoplay => false, :hide_related => false) do |text, options|
2
- regex = /https?:\/\/(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/
2
+ regex = /(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/
3
3
  text.gsub(regex) do
4
- youtube_id = $3
4
+ youtube_id = $4
5
5
  width = options[:width]
6
6
  height = options[:height]
7
7
  frameborder = options[:frameborder]
@@ -14,6 +14,6 @@ AutoHtml.add_filter(:youtube).with(:width => 420, :height => 315, :frameborder =
14
14
  params << "autoplay=1" if autoplay
15
15
  params << "rel=0" if hide_related
16
16
  src += "?#{params.join '&'}" unless params.empty?
17
- %{<iframe width="#{width}" height="#{height}" src="#{src}" frameborder="#{frameborder}" allowfullscreen></iframe>}
17
+ %{<div class="video youtube"><iframe width="#{width}" height="#{height}" src="#{src}" frameborder="#{frameborder}" allowfullscreen></iframe></div>}
18
18
  end
19
19
  end
@@ -2,6 +2,7 @@ require 'rubygems'
2
2
 
3
3
  require 'test/unit'
4
4
  require 'active_record'
5
+ require 'action_view'
5
6
  require 'active_support/core_ext/class'
6
7
 
7
8
  require File.dirname(__FILE__) + '/../init'
@@ -4,12 +4,12 @@ class GistTest < Test::Unit::TestCase
4
4
 
5
5
  def test_transform
6
6
  result = auto_html('https://gist.github.com/1710276') { gist }
7
- assert_equal '<script src="https://gist.github.com/1710276.js"></script>', result
7
+ assert_equal '<script type="text/javascript" src="https://gist.github.com/1710276.js"></script>', result
8
8
  end
9
9
 
10
10
  def test_transform_with_username
11
11
  result = auto_html('https://gist.github.com/toctan/6547840') { gist }
12
- assert_equal '<script src="https://gist.github.com/6547840.js"></script>', result
12
+ assert_equal '<script type="text/javascript" src="https://gist.github.com/6547840.js"></script>', result
13
13
  end
14
14
 
15
15
  end
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class InstagramTest < Test::Unit::TestCase
4
+ def test_instagram_embed
5
+ result = auto_html('http://instagram.com/p/WsQTLAGvx7/') { instagram }
6
+ assert_equal '<iframe src="http://instagram.com/p/WsQTLAGvx7/embed" height="714" width="616" frameborder="0" scrolling="no"></iframe>', result
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class TedTest < Test::Unit::TestCase
4
+ def test_transform_url_with_www
5
+ output = auto_html('http://www.ted.com/talks/amy_cuddy_your_body_language_shapes_who_you_are.html') { ted }
6
+ assert_equal '<iframe width="640" height="360" frameborder="0" scrolling="no" src="http://embed.ted.com/talks/amy_cuddy_your_body_language_shapes_who_you_are.html"></iframe>', output
7
+ end
8
+
9
+ def test_transform_url_without_www
10
+ output = auto_html('http://ted.com/talks/amy_cuddy_your_body_language_shapes_who_you_are.html') { ted }
11
+ assert_equal '<iframe width="640" height="360" frameborder="0" scrolling="no" src="http://embed.ted.com/talks/amy_cuddy_your_body_language_shapes_who_you_are.html"></iframe>', output
12
+ end
13
+
14
+ def test_transform_url_with_options
15
+ result = auto_html('http://www.ted.com/talks/amy_cuddy_your_body_language_shapes_who_you_are.html') { ted(:width => '50%', :height => '100', :scrolling => 'yes', :frameborder => 1, :allow_full_screen => true) }
16
+ assert_equal '<iframe width="50%" height="100" frameborder="1" scrolling="yes" src="http://embed.ted.com/talks/amy_cuddy_your_body_language_shapes_who_you_are.html" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>', result
17
+ end
18
+ end
@@ -4,51 +4,56 @@ class YouTubeTest < Test::Unit::TestCase
4
4
 
5
5
  def test_transform
6
6
  result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o') { youtube }
7
- assert_equal '<iframe width="420" height="315" src="//www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen></iframe>', result
7
+ assert_equal '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen></iframe></div>', result
8
8
  end
9
9
 
10
10
  def test_transform2
11
11
  result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o&eurl=http%3A%2F%2Fvukajlija.com%2Fvideo%2Fklipovi%3Fstrana%3D6&feature=player_embedded') { youtube }
12
- assert_equal '<iframe width="420" height="315" src="//www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen></iframe>', result
12
+ assert_equal '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen></iframe></div>', result
13
13
  end
14
14
 
15
15
  def test_transform3
16
16
  result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o&feature=related') { youtube }
17
- assert_equal '<iframe width="420" height="315" src="//www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen></iframe>', result
17
+ assert_equal '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen></iframe></div>', result
18
18
  end
19
19
 
20
20
  def test_transform3
21
21
  result = auto_html('foo http://www.youtube.com/watch?v=fT1ahr81HLw bar') { youtube }
22
- assert_equal 'foo <iframe width="420" height="315" src="//www.youtube.com/embed/fT1ahr81HLw" frameborder="0" allowfullscreen></iframe> bar', result
22
+ assert_equal 'foo <div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/fT1ahr81HLw" frameborder="0" allowfullscreen></iframe></div> bar', result
23
23
  end
24
24
 
25
25
  def test_transform4
26
26
  result = auto_html('foo http://www.youtube.com/watch?v=fT1ahr81HLw<br>bar') { youtube }
27
- assert_equal 'foo <iframe width="420" height="315" src="//www.youtube.com/embed/fT1ahr81HLw" frameborder="0" allowfullscreen></iframe><br>bar', result
27
+ assert_equal 'foo <div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/fT1ahr81HLw" frameborder="0" allowfullscreen></iframe></div><br>bar', result
28
28
  end
29
29
 
30
30
  def test_transform_url_without_www
31
31
  result = auto_html('http://youtube.com/watch?v=BwNrmYRiX_o') { youtube }
32
- assert_equal '<iframe width="420" height="315" src="//www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen></iframe>', result
32
+ assert_equal '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen></iframe></div>', result
33
33
  end
34
34
 
35
35
  def test_transform_with_options
36
36
  result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o') { youtube(:width => 300, :height => 255, :frameborder => 1, :wmode => 'window') }
37
- assert_equal '<iframe width="300" height="255" src="//www.youtube.com/embed/BwNrmYRiX_o?wmode=window" frameborder="1" allowfullscreen></iframe>', result
37
+ assert_equal '<div class="video youtube"><iframe width="300" height="255" src="//www.youtube.com/embed/BwNrmYRiX_o?wmode=window" frameborder="1" allowfullscreen></iframe></div>', result
38
38
  end
39
39
 
40
40
  def test_transform_with_short_url
41
41
  result = auto_html('http://www.youtu.be/BwNrmYRiX_o') { youtube }
42
- assert_equal '<iframe width="420" height="315" src="//www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen></iframe>', result
42
+ assert_equal '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen></iframe></div>', result
43
43
  end
44
44
 
45
45
  def test_transform_https
46
46
  result = auto_html("https://www.youtube.com/watch?v=t7NdBIA4zJg") { youtube }
47
- assert_equal '<iframe width="420" height="315" src="//www.youtube.com/embed/t7NdBIA4zJg" frameborder="0" allowfullscreen></iframe>', result
47
+ assert_equal '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/t7NdBIA4zJg" frameborder="0" allowfullscreen></iframe></div>', result
48
48
  end
49
49
 
50
50
  def test_short_with_params
51
51
  result = auto_html("http://youtu.be/t7NdBIA4zJg?t=1s&hd=1") { youtube }
52
- assert_equal '<iframe width="420" height="315" src="//www.youtube.com/embed/t7NdBIA4zJg" frameborder="0" allowfullscreen></iframe>', result
52
+ assert_equal '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/t7NdBIA4zJg" frameborder="0" allowfullscreen></iframe></div>', result
53
+ end
54
+
55
+ def test_transform_without_protocol
56
+ result = auto_html("www.youtube.com/watch?v=t7NdBIA4zJg") { youtube }
57
+ assert_equal '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/t7NdBIA4zJg" frameborder="0" allowfullscreen></iframe></div>', result
53
58
  end
54
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-05 00:00:00.000000000 Z
12
+ date: 2014-03-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rinku
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: '2.0'
37
+ version: '3.1'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: '2.0'
45
+ version: '3.1'
46
46
  description: Automatically transforms URIs (via domain) and includes the destination
47
47
  resource (Vimeo, YouTube movie, image, ...) in your document
48
48
  email: desimic@gmail.com
@@ -64,12 +64,14 @@ files:
64
64
  - lib/auto_html/filters/hashtag.rb
65
65
  - lib/auto_html/filters/html_escape.rb
66
66
  - lib/auto_html/filters/image.rb
67
+ - lib/auto_html/filters/instagram.rb
67
68
  - lib/auto_html/filters/link.rb
68
69
  - lib/auto_html/filters/metacafe.rb
69
70
  - lib/auto_html/filters/redcarpet.rb
70
71
  - lib/auto_html/filters/sanitize.rb
71
72
  - lib/auto_html/filters/simple_format.rb
72
73
  - lib/auto_html/filters/soundcloud.rb
74
+ - lib/auto_html/filters/ted.rb
73
75
  - lib/auto_html/filters/twitter.rb
74
76
  - lib/auto_html/filters/vimeo.rb
75
77
  - lib/auto_html/filters/worldstar.rb
@@ -93,12 +95,14 @@ files:
93
95
  - test/unit/filters/hashtag_test.rb
94
96
  - test/unit/filters/html_escape_test.rb
95
97
  - test/unit/filters/image_test.rb
98
+ - test/unit/filters/instagram_test.rb
96
99
  - test/unit/filters/link_test.rb
97
100
  - test/unit/filters/metacafe_test.rb
98
101
  - test/unit/filters/redcarpet_test.rb
99
102
  - test/unit/filters/sanitize_test.rb
100
103
  - test/unit/filters/simple_format_test.rb
101
104
  - test/unit/filters/soundcloud_test.rb
105
+ - test/unit/filters/ted_test.rb
102
106
  - test/unit/filters/twitter_test.rb
103
107
  - test/unit/filters/vimeo_test.rb
104
108
  - test/unit/filters/worldstar_test.rb