auto_html 1.6.2 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
|
|
1
|
+
AutoHtml.add_filter(:liveleak).with(:width => 420, :height => 315, :frameborder => 0, :wmode => nil, :autoplay => false, :hide_related => false) do |text, options|
|
2
|
+
regex = %r{http://www\.liveleak\.com/(?:ll_embed|view)\?.=(\w+)}
|
3
|
+
text.gsub(regex) do
|
4
|
+
liveleak_id = $1
|
5
|
+
width = options[:width]
|
6
|
+
height = options[:height]
|
7
|
+
frameborder = options[:frameborder]
|
8
|
+
wmode = options[:wmode]
|
9
|
+
autoplay = options[:autoplay]
|
10
|
+
hide_related = options[:hide_related]
|
11
|
+
src = "http://www.liveleak.com/ll_embed?f=#{liveleak_id}"
|
12
|
+
params = []
|
13
|
+
params << "wmode=#{wmode}" if wmode
|
14
|
+
params << "autoplay=1" if autoplay
|
15
|
+
params << "rel=0" if hide_related
|
16
|
+
src += "?#{params.join '&'}" unless params.empty?
|
17
|
+
%{<iframe width="#{width}" height="#{height}" src="#{src}" frameborder="#{frameborder}" allowfullscreen></iframe>}
|
18
|
+
end
|
19
|
+
end
|
@@ -2,15 +2,18 @@ AutoHtml.add_filter(:twitter).with({}) do |text, options|
|
|
2
2
|
require 'uri'
|
3
3
|
require 'net/http'
|
4
4
|
|
5
|
-
regex = %r{(?<!href=")https://twitter\.com(/#!)?/[A-Za-z0-9_]{1,15}/status(es)?/\d+}
|
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|
|
8
8
|
params = { :url => match }.merge(options)
|
9
9
|
|
10
|
-
uri = URI("
|
10
|
+
uri = URI("https://api.twitter.com/1/statuses/oembed.json")
|
11
11
|
uri.query = URI.encode_www_form(params)
|
12
12
|
|
13
|
-
|
13
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
14
|
+
http.use_ssl = true
|
15
|
+
|
16
|
+
response = JSON.parse(http.get(uri.request_uri).body)
|
14
17
|
response["html"]
|
15
18
|
end
|
16
19
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('../../unit_test_helper', __FILE__)
|
2
|
+
|
3
|
+
class LiveLeakTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_transform
|
6
|
+
result = auto_html('http://www.liveleak.com/view?i=BwNrmYRiX_o') { liveleak }
|
7
|
+
assert_equal '<iframe width="420" height="315" src="http://www.liveleak.com/ll_embed?f=BwNrmYRiX_o" frameborder="0" allowfullscreen></iframe>', result
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_transform2
|
11
|
+
result = auto_html('http://www.liveleak.com/ll_embed?f=ef8304ab85e5') { liveleak }
|
12
|
+
assert_equal '<iframe width="420" height="315" src="http://www.liveleak.com/ll_embed?f=ef8304ab85e5" frameborder="0" allowfullscreen></iframe>', result
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -6,35 +6,40 @@ class TwitterTest < Test::Unit::TestCase
|
|
6
6
|
def setup
|
7
7
|
response = %Q(
|
8
8
|
{
|
9
|
-
"
|
10
|
-
"
|
11
|
-
"cache_age": "
|
9
|
+
"author_name": "Dan Martell",
|
10
|
+
"author_url": "https://twitter.com/danmartell",
|
11
|
+
"cache_age": "3153600000",
|
12
12
|
"height": null,
|
13
13
|
"html": "things",
|
14
|
-
"version": "1.0",
|
15
14
|
"provider_name": "Twitter",
|
16
|
-
"
|
17
|
-
"
|
18
|
-
"
|
19
|
-
"
|
15
|
+
"provider_url": "https://twitter.com",
|
16
|
+
"type": "rich",
|
17
|
+
"url": "https://twitter.com/danmartell/statuses/279651488517738496",
|
18
|
+
"version": "1.0",
|
19
|
+
"width": 550
|
20
20
|
})
|
21
|
-
|
22
|
-
FakeWeb.register_uri(:get, %r|
|
21
|
+
|
22
|
+
FakeWeb.register_uri(:get, %r|https://api\.twitter\.com/1/statuses/oembed\.json|, :body => response)
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_transform
|
26
|
-
|
26
|
+
transformed_html = "things"
|
27
27
|
result = auto_html('https://twitter.com/danmartell/statuses/279651488517738496') { twitter }
|
28
|
-
assert_equal
|
28
|
+
assert_equal transformed_html, result
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_transform_with_dangling_slash
|
32
|
+
transformed_html = "things"
|
33
|
+
result = auto_html('https://twitter.com/danmartell/statuses/279651488517738496/') { twitter }
|
34
|
+
assert_equal transformed_html, result
|
29
35
|
end
|
30
36
|
|
31
37
|
def test_dont_transform_a_regular_link_to_twitter
|
32
|
-
|
38
|
+
transformed_html = %Q(<blockquote class="twitter-tweet"><p>Stop saying you can't! Start asking "What would need to be true for me to accomplish this" - it'll change your life. <a href="https://twitter.com/search?q=%23focus&src=hash">#focus</a> <a href="https://twitter.com/search?q=%23solutions&src=hash">#solutions</a></p>— Dan Martell (@danmartell) <a href="https://twitter.com/danmartell/statuses/279651488517738496">December 14, 2012</a></blockquote>
|
33
39
|
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>)
|
40
|
+
result = auto_html(transformed_html) { twitter }
|
34
41
|
|
35
|
-
|
36
|
-
|
37
|
-
assert_equal transormed_html, result
|
42
|
+
assert_equal transformed_html, result
|
38
43
|
end
|
39
44
|
|
40
45
|
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.
|
4
|
+
version: 1.6.3
|
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-
|
12
|
+
date: 2014-04-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rinku
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/auto_html/filters/image.rb
|
67
67
|
- lib/auto_html/filters/instagram.rb
|
68
68
|
- lib/auto_html/filters/link.rb
|
69
|
+
- lib/auto_html/filters/liveleak.rb
|
69
70
|
- lib/auto_html/filters/metacafe.rb
|
70
71
|
- lib/auto_html/filters/redcarpet.rb
|
71
72
|
- lib/auto_html/filters/sanitize.rb
|
@@ -97,6 +98,7 @@ files:
|
|
97
98
|
- test/unit/filters/image_test.rb
|
98
99
|
- test/unit/filters/instagram_test.rb
|
99
100
|
- test/unit/filters/link_test.rb
|
101
|
+
- test/unit/filters/liveleak_test.rb
|
100
102
|
- test/unit/filters/metacafe_test.rb
|
101
103
|
- test/unit/filters/redcarpet_test.rb
|
102
104
|
- test/unit/filters/sanitize_test.rb
|