auto_html 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/Rakefile +7 -2
- data/lib/auto_html/auto_html_for.rb +5 -3
- data/lib/auto_html/filters/gist.rb +9 -0
- data/lib/auto_html/filters/google_map.rb +13 -0
- data/lib/auto_html/filters/youtube.rb +1 -1
- data/lib/auto_html/rake_tasks.rb +1 -1
- data/test/test_helper.rb +1 -0
- data/test/unit/filters/gist_test.rb +10 -0
- data/test/unit/filters/google_map_test.rb +14 -0
- data/test/unit/filters/youtube_test.rb +5 -0
- metadata +8 -4
data/README.md
CHANGED
@@ -99,4 +99,4 @@ Specify the gem in Gemfile of the project
|
|
99
99
|
## Credits
|
100
100
|
|
101
101
|
Author: [Dejan Simic](http://github.com/dejan)<br/>
|
102
|
-
Contributors:
|
102
|
+
Contributors: https://github.com/dejan/auto_html/contributors
|
data/Rakefile
CHANGED
@@ -9,8 +9,13 @@ Rake::TestTask.new(:test) do |t|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
desc 'Test with recent versions of Rails'
|
12
|
-
task :
|
13
|
-
versions = ['2.1.
|
12
|
+
task :test_wit_all_rails_versions do
|
13
|
+
versions = ['2.1.2',
|
14
|
+
'2.2.3',
|
15
|
+
# '2.3.14',
|
16
|
+
'3.0.11',
|
17
|
+
'3.1.3',
|
18
|
+
'3.2.1']
|
14
19
|
versions.each do |v|
|
15
20
|
puts "\n###### TESTING WITH RAILS #{v}"
|
16
21
|
ENV['RAILS_VERSION'] = v
|
@@ -26,7 +26,8 @@ module AutoHtmlFor
|
|
26
26
|
|
27
27
|
[raw_attrs].flatten.each do |raw_attr|
|
28
28
|
define_method("#{raw_attr}#{suffix}=") do |val|
|
29
|
-
|
29
|
+
a = "#{raw_attr}#{suffix}"
|
30
|
+
write_attribute(a, val) if attributes[a]
|
30
31
|
end
|
31
32
|
define_method("#{raw_attr}#{suffix}") do
|
32
33
|
result = read_attribute("#{raw_attr}#{suffix}") || send("auto_html_prepare_#{raw_attr}")
|
@@ -35,8 +36,9 @@ module AutoHtmlFor
|
|
35
36
|
result
|
36
37
|
end
|
37
38
|
define_method("auto_html_prepare_#{raw_attr}") do
|
38
|
-
self.send(raw_attr
|
39
|
-
|
39
|
+
result = auto_html(self.send(raw_attr), &proc)
|
40
|
+
self.send(raw_attr.to_s + suffix + "=", result)
|
41
|
+
result
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
AutoHtml.add_filter(:google_map).with(:width => 420, :height => 315, :style => "color:#000;text-align:left", :link_text => "View Larger Map") do |text, options|
|
3
|
+
regex = /(https?):\/\/maps\.google\.co(.*)\/maps\?(.*)/
|
4
|
+
text.gsub(regex) do
|
5
|
+
domain_country = $2
|
6
|
+
map_query = $3
|
7
|
+
width = options[:width]
|
8
|
+
height = options[:height]
|
9
|
+
style = options[:style]
|
10
|
+
link_text = options[:link_text]
|
11
|
+
%{<iframe width="#{width}" height="#{height}" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co#{domain_country}/maps?f=q&source=s_q&#{map_query}&output=embed"></iframe><br /><small><a href="http://maps.google.co#{domain_country}/maps?f=q&source=embed&#{map_query}" style="#{style}">#{link_text}</a></small>}
|
12
|
+
end
|
13
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
AutoHtml.add_filter(:youtube).with(:width => 420, :height => 315, :frameborder => 0, :wmode => nil) do |text, options|
|
2
|
-
regex = /(https?):\/\/(www.)?(youtube\.com\/watch\?v=|youtu\.be\/)([A-Za-z0-9_-]*)(\&\S+)
|
2
|
+
regex = /(https?):\/\/(www.)?(youtube\.com\/watch\?v=|youtu\.be\/)([A-Za-z0-9_-]*)(\&\S+)?(\S)*/
|
3
3
|
text.gsub(regex) do
|
4
4
|
protocol = $1
|
5
5
|
youtube_id = $4
|
data/lib/auto_html/rake_tasks.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path('../../unit_test_helper', __FILE__)
|
2
|
+
|
3
|
+
class GistTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_transform
|
6
|
+
result = auto_html('https://gist.github.com/1710276') { gist }
|
7
|
+
assert_equal '<script src="https://gist.github.com/1710276.js"></script>', result
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path('../../unit_test_helper', __FILE__)
|
2
|
+
|
3
|
+
class GoogleMapTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_transform
|
6
|
+
result = auto_html('http://maps.google.co.kr/maps?q=%ED%8C%8C%ED%8A%B8%EB%84%88%EC%8A%A4%ED%83%80%EC%9B%8C+1%EC%B0%A8&hl=ko&ie=UTF8&ll=37.472942,126.884762&spn=0.00774,0.010053&sll=37.473027,126.88451&sspn=0.003887,0.005026&vpsrc=6&gl=kr&hq=%ED%8C%8C%ED%8A%B8%EB%84%88%EC%8A%A4%ED%83%80%EC%9B%8C+1%EC%B0%A8&t=m&z=17&iwloc=A') { google_map }
|
7
|
+
assert_equal '<iframe width="420" height="315" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.kr/maps?f=q&source=s_q&q=%ED%8C%8C%ED%8A%B8%EB%84%88%EC%8A%A4%ED%83%80%EC%9B%8C+1%EC%B0%A8&hl=ko&ie=UTF8&ll=37.472942,126.884762&spn=0.00774,0.010053&sll=37.473027,126.88451&sspn=0.003887,0.005026&vpsrc=6&gl=kr&hq=%ED%8C%8C%ED%8A%B8%EB%84%88%EC%8A%A4%ED%83%80%EC%9B%8C+1%EC%B0%A8&t=m&z=17&iwloc=A&output=embed"></iframe><br /><small><a href="http://maps.google.co.kr/maps?f=q&source=embed&q=%ED%8C%8C%ED%8A%B8%EB%84%88%EC%8A%A4%ED%83%80%EC%9B%8C+1%EC%B0%A8&hl=ko&ie=UTF8&ll=37.472942,126.884762&spn=0.00774,0.010053&sll=37.473027,126.88451&sspn=0.003887,0.005026&vpsrc=6&gl=kr&hq=%ED%8C%8C%ED%8A%B8%EB%84%88%EC%8A%A4%ED%83%80%EC%9B%8C+1%EC%B0%A8&t=m&z=17&iwloc=A" style="color:#000;text-align:left">View Larger Map</a></small>', result
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_transform_2
|
11
|
+
result = auto_html('http://maps.google.com/maps?hl=en&q=newyork&gs_sm=e&gs_upl=917l917l0l1666l1l1l0l0l0l0l317l317l3-1l1l0&bav=on.2,or.r_gc.r_pw.,cf.osb&biw=1280&bih=679&um=1&ie=UTF-8&sa=N&tab=wl') { google_map }
|
12
|
+
assert_equal '<iframe width="420" height="315" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&source=s_q&hl=en&q=newyork&gs_sm=e&gs_upl=917l917l0l1666l1l1l0l0l0l0l317l317l3-1l1l0&bav=on.2,or.r_gc.r_pw.,cf.osb&biw=1280&bih=679&um=1&ie=UTF-8&sa=N&tab=wl&output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&source=embed&hl=en&q=newyork&gs_sm=e&gs_upl=917l917l0l1666l1l1l0l0l0l0l317l317l3-1l1l0&bav=on.2,or.r_gc.r_pw.,cf.osb&biw=1280&bih=679&um=1&ie=UTF-8&sa=N&tab=wl" style="color:#000;text-align:left">View Larger Map</a></small>', result
|
13
|
+
end
|
14
|
+
end
|
@@ -16,6 +16,11 @@ class YouTubeTest < Test::Unit::TestCase
|
|
16
16
|
result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o&feature=related') { youtube }
|
17
17
|
assert_equal '<iframe width="420" height="315" src="http://www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen></iframe>', result
|
18
18
|
end
|
19
|
+
|
20
|
+
def test_transform3
|
21
|
+
result = auto_html('foo http://www.youtube.com/watch?v=fT1ahr81HLw bar') { youtube }
|
22
|
+
assert_equal 'foo <iframe width="420" height="315" src="http://www.youtube.com/embed/fT1ahr81HLw" frameborder="0" allowfullscreen></iframe> bar', result
|
23
|
+
end
|
19
24
|
|
20
25
|
def test_transform_url_without_www
|
21
26
|
result = auto_html('http://youtube.com/watch?v=BwNrmYRiX_o') { youtube }
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 1.5.
|
9
|
+
- 1
|
10
|
+
version: 1.5.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dejan Simic
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-02-18 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -66,6 +66,8 @@ files:
|
|
66
66
|
- lib/auto_html/capistrano.rb
|
67
67
|
- lib/auto_html/filter.rb
|
68
68
|
- lib/auto_html/filters/dailymotion.rb
|
69
|
+
- lib/auto_html/filters/gist.rb
|
70
|
+
- lib/auto_html/filters/google_map.rb
|
69
71
|
- lib/auto_html/filters/google_video.rb
|
70
72
|
- lib/auto_html/filters/html_escape.rb
|
71
73
|
- lib/auto_html/filters/image.rb
|
@@ -90,6 +92,8 @@ files:
|
|
90
92
|
- test/test_helper.rb
|
91
93
|
- test/unit/auto_html_test.rb
|
92
94
|
- test/unit/filters/dailymotion_test.rb
|
95
|
+
- test/unit/filters/gist_test.rb
|
96
|
+
- test/unit/filters/google_map_test.rb
|
93
97
|
- test/unit/filters/google_video_test.rb
|
94
98
|
- test/unit/filters/html_escape_test.rb
|
95
99
|
- test/unit/filters/image_test.rb
|