auto_html 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +38 -0
- data/README.md +84 -0
- data/Rakefile +22 -0
- data/VERSION.yml +2 -2
- data/auto_html.gemspec +13 -9
- data/lib/auto_html.rb +0 -1
- data/lib/auto_html/auto_html_for.rb +8 -3
- data/lib/auto_html/base.rb +1 -1
- data/lib/auto_html/builder.rb +0 -1
- data/lib/auto_html/filter.rb +0 -2
- data/lib/auto_html/filters/simple_format.rb +3 -6
- data/lib/auto_html/filters/vimeo.rb +0 -2
- data/lib/auto_html/filters/youtube.rb +10 -4
- data/lib/auto_html/filters/youtube_js_api.rb +6 -0
- data/test/fixtures/schema.rb +0 -1
- data/test/functional/auto_html_for_options_test.rb +1 -0
- data/test/functional/auto_html_for_test.rb +5 -0
- data/test/test_helper.rb +7 -0
- data/test/unit/auto_html_test.rb +10 -0
- data/test/unit/filters/youtube_js_api_test.rb +30 -0
- data/test/unit/filters/youtube_test.rb +14 -9
- metadata +23 -8
- data/CHANGELOG.rdoc +0 -29
- data/README.rdoc +0 -92
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
## edge (planned for 1.3)
|
2
|
+
* no need for explicit call to auto_html_prepare
|
3
|
+
* no need for DB column for cache (ie. _html)
|
4
|
+
* Rails 3 support
|
5
|
+
* correctly handle blank and nil values when applying auto_html
|
6
|
+
* more filters: youtube_js_api
|
7
|
+
* youtube filter supports html5
|
8
|
+
|
9
|
+
|
10
|
+
## 1.2.1, released 2009-10-28
|
11
|
+
|
12
|
+
* more options for vimeo filter
|
13
|
+
* switch to gemcutter
|
14
|
+
|
15
|
+
## 1.2.0, released 2009-09-26
|
16
|
+
|
17
|
+
* link filter now uses Rails' link discovery engine. Closes: <http://github.com/dejan/auto_html/issues#issue/2> and <http://github.com/dejan/auto_html/issues#issue/3> if Rails 2.3+ is in use.
|
18
|
+
* added dailymotion filter
|
19
|
+
* added sanitize filter
|
20
|
+
|
21
|
+
## 1.1.2, released 2009-09-24
|
22
|
+
|
23
|
+
* link filter fix. Closes: <http://github.com/dejan/auto_html/issues#issue/2>
|
24
|
+
|
25
|
+
## 1.1.1, released 2009-09-06
|
26
|
+
|
27
|
+
* test_helper fix
|
28
|
+
|
29
|
+
## 1.1.0, released 2009-09-05
|
30
|
+
|
31
|
+
* Plugin gemified
|
32
|
+
* AutoHtmlFor.options[:htmlized_attribute_suffix] is now AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]. Closes gh-1
|
33
|
+
* Removed deezer filter since deezer.com no longer provides sharing of this kind
|
34
|
+
|
35
|
+
## 1.0.0
|
36
|
+
|
37
|
+
* Stuff described here: <http://www.elctech.com/projects/auto_html-plugin>
|
38
|
+
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
auto_html
|
2
|
+
=========
|
3
|
+
|
4
|
+
auto_html is a Rails extension for transforming URLs to appropriate resource (image, link, YouTube, Vimeo video,...). It's the perfect choice if you don't want to bother visitors with rich HTML editor or markup code, but you still want to allow them to embed video, images, links and more on your site, purely by pasting URL. Check out the [live demo](http://auto-html.rors.org).
|
5
|
+
|
6
|
+
|
7
|
+
## Example usage
|
8
|
+
|
9
|
+
Let's say you have model Comment with attribute body. Create another column in table Comments called body_html (this is optional, but recommended for performance reasons). Now have something like this:
|
10
|
+
|
11
|
+
class Comment < ActiveRecord::Base
|
12
|
+
auto_html_for :body do
|
13
|
+
html_escape
|
14
|
+
image
|
15
|
+
youtube(:width => 400, :height => 250)
|
16
|
+
link :target => "_blank", :rel => "nofollow"
|
17
|
+
simple_format
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
... and you'll have this behaviour:
|
22
|
+
|
23
|
+
Comment.create(:body => 'Hey check out this cool video: http://www.youtube.com/watch?v=WdsGihou8J4')
|
24
|
+
=> #<Comment id: 123, body: 'Hey check out this cool video: http://www.youtube.com/watch?v=WdsGihou8J4', body_html: '<p>Hey check out this cool video: <object height="250" width="400"><param name="movie" value="http://www.youtube.com/v/WdsGihou8J4" /><param name="wmode" value="transparent" /><embed src="http://www.youtube.com/v/WdsGihou8J4" type="application/x-shockwave-flash" height="250" wmode="transparent" width="400"></embed></object></p>'>
|
25
|
+
|
26
|
+
Note that order of invoking filters is important, ie. you want html_escape as first and link amongst last, so that it doesn't transform youtube URL to plain link.
|
27
|
+
|
28
|
+
|
29
|
+
Now all you have to do is to display it in template without escaping, since plugin took care of that:
|
30
|
+
|
31
|
+
<% for comment in @comments %>
|
32
|
+
<li><%= comment.body_html %></li>
|
33
|
+
<% end %>
|
34
|
+
|
35
|
+
|
36
|
+
If you need to display preview, no problem. Have something like this as action in your controller:
|
37
|
+
|
38
|
+
def preview
|
39
|
+
comment = Comment.new(params[:comment])
|
40
|
+
render :text => comment.body_html
|
41
|
+
end
|
42
|
+
|
43
|
+
Plugin is highly customizable, and you can easily create new filters that will transform user input any way you like. For instance, this is the image filter that comes bundled with plugin:
|
44
|
+
|
45
|
+
AutoHtml.add_filter(:image) do |text|
|
46
|
+
text.gsub(/http:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
|
47
|
+
%|<img src="#{match}" alt=""/>|
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
## Bundled filters
|
53
|
+
|
54
|
+
For filter list and options they support check: <http://github.com/dejan/auto_html/tree/master/lib/auto_html/filters>
|
55
|
+
|
56
|
+
|
57
|
+
## Install
|
58
|
+
|
59
|
+
### Important note on versions
|
60
|
+
|
61
|
+
As from version 1.2.0 auto_html uses Rails' engine for discovering links. There are some bugs with that engine in versions under Rails 2.3.2. so it's recommended you use auto_html 1.1.2 in that case, since internal engine is used in that version.
|
62
|
+
|
63
|
+
> for Rails <= 2.3.1 use auto_html 1.1.2<br/>
|
64
|
+
> for Rails >= 2.3.2 use auto_html 1.2.1
|
65
|
+
|
66
|
+
auto_html has been tested to work with Rails 3 and Ruby 1.9.
|
67
|
+
|
68
|
+
### As a gem
|
69
|
+
|
70
|
+
To enable the library in your Rails 2.1 (or greater) project, use the gem configuration method in "config/environment.rb"
|
71
|
+
|
72
|
+
Rails::Initializer.run do |config|
|
73
|
+
config.gem 'auto_html', :version => '~> 1.2.1'
|
74
|
+
end
|
75
|
+
|
76
|
+
### As a Rails plugin
|
77
|
+
|
78
|
+
script/plugin install git://github.com/dejan/auto_html.git
|
79
|
+
|
80
|
+
|
81
|
+
## Credits
|
82
|
+
|
83
|
+
Author: [Dejan Simic](http://github.com/dejan)<br/>
|
84
|
+
Contributors: [Claudio Perez Gamayo](http://github.com/crossblaim), [Matt Polito](http://github.com/mattpolito), [Ryan Heneise](http://github.com/mysmallidea), [Caleb Wright](http://github.com/fabrikagency)
|
data/Rakefile
CHANGED
@@ -8,6 +8,28 @@ Rake::TestTask.new(:test) do |t|
|
|
8
8
|
t.pattern = 'test/**/*_test.rb'
|
9
9
|
end
|
10
10
|
|
11
|
+
desc 'Test with recent versions of Rails'
|
12
|
+
task :test_with_recent do
|
13
|
+
versions = ['2.3.6', '3.0.0.beta4']
|
14
|
+
versions.each do |v|
|
15
|
+
puts "\n###### TESTING WITH RAILS #{v}"
|
16
|
+
ENV['RAILS_VERSION'] = v
|
17
|
+
Rake::Task['test'].execute
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Test with versions of Rails available on the system'
|
22
|
+
task :test_with_installed do
|
23
|
+
versions = `gem list rails | grep rails`.gsub("rails (", "").chop.split(', ')
|
24
|
+
exclude = []
|
25
|
+
(versions-exclude).each do |v|
|
26
|
+
puts "\n###### TESTING WITH RAILS #{v}"
|
27
|
+
ENV['RAILS_VERSION'] = v
|
28
|
+
Rake::Task['test'].execute
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
11
33
|
begin
|
12
34
|
require 'jeweler'
|
13
35
|
Jeweler::Tasks.new do |gem|
|
data/VERSION.yml
CHANGED
data/auto_html.gemspec
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{auto_html}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dejan Simic"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-08-14}
|
13
13
|
s.description = %q{Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document}
|
14
14
|
s.email = %q{desimic@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
|
-
"README.
|
16
|
+
"README.md"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
19
|
".gitignore",
|
20
|
-
"CHANGELOG.
|
20
|
+
"CHANGELOG.md",
|
21
21
|
"MIT-LICENCE",
|
22
|
-
"README.
|
22
|
+
"README.md",
|
23
23
|
"Rakefile",
|
24
24
|
"VERSION.yml",
|
25
25
|
"auto_html.gemspec",
|
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
"lib/auto_html/filters/simple_format.rb",
|
38
38
|
"lib/auto_html/filters/vimeo.rb",
|
39
39
|
"lib/auto_html/filters/youtube.rb",
|
40
|
+
"lib/auto_html/filters/youtube_js_api.rb",
|
40
41
|
"rails/init.rb",
|
41
42
|
"test/fixture_setup.rb",
|
42
43
|
"test/fixtures/database.yml",
|
@@ -53,13 +54,14 @@ Gem::Specification.new do |s|
|
|
53
54
|
"test/unit/filters/sanitize_test.rb",
|
54
55
|
"test/unit/filters/simple_format_test.rb",
|
55
56
|
"test/unit/filters/vimeo_test.rb",
|
57
|
+
"test/unit/filters/youtube_js_api_test.rb",
|
56
58
|
"test/unit/filters/youtube_test.rb",
|
57
59
|
"test/unit/unit_test_helper.rb"
|
58
60
|
]
|
59
61
|
s.homepage = %q{http://github.com/dejan/auto_html}
|
60
62
|
s.rdoc_options = ["--charset=UTF-8"]
|
61
63
|
s.require_paths = ["lib"]
|
62
|
-
s.rubygems_version = %q{1.3.
|
64
|
+
s.rubygems_version = %q{1.3.7}
|
63
65
|
s.summary = %q{Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document}
|
64
66
|
s.test_files = [
|
65
67
|
"test/fixture_setup.rb",
|
@@ -76,6 +78,7 @@ Gem::Specification.new do |s|
|
|
76
78
|
"test/unit/filters/sanitize_test.rb",
|
77
79
|
"test/unit/filters/simple_format_test.rb",
|
78
80
|
"test/unit/filters/vimeo_test.rb",
|
81
|
+
"test/unit/filters/youtube_js_api_test.rb",
|
79
82
|
"test/unit/filters/youtube_test.rb",
|
80
83
|
"test/unit/unit_test_helper.rb"
|
81
84
|
]
|
@@ -84,9 +87,10 @@ Gem::Specification.new do |s|
|
|
84
87
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
85
88
|
s.specification_version = 3
|
86
89
|
|
87
|
-
if Gem::Version.new(Gem::
|
90
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
88
91
|
else
|
89
92
|
end
|
90
93
|
else
|
91
94
|
end
|
92
95
|
end
|
96
|
+
|
data/lib/auto_html.rb
CHANGED
@@ -22,11 +22,16 @@ module AutoHtmlFor
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
suffix = AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
|
26
|
+
|
25
27
|
[raw_attrs].flatten.each do |raw_attr|
|
28
|
+
define_method("#{raw_attr}#{suffix}=") do |val|
|
29
|
+
write_attribute("#{raw_attr}#{suffix}", val)
|
30
|
+
end
|
31
|
+
define_method("#{raw_attr}#{suffix}") do
|
32
|
+
read_attribute("#{raw_attr}#{suffix}") || send("auto_html_prepare_#{raw_attr}")
|
33
|
+
end
|
26
34
|
define_method("auto_html_prepare_#{raw_attr}") do
|
27
|
-
suffix =
|
28
|
-
AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix] ||
|
29
|
-
AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
|
30
35
|
self.send(raw_attr.to_s + suffix + "=",
|
31
36
|
auto_html(self.send(raw_attr), &proc))
|
32
37
|
end
|
data/lib/auto_html/base.rb
CHANGED
data/lib/auto_html/builder.rb
CHANGED
data/lib/auto_html/filter.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
|
1
3
|
AutoHtml.add_filter(:simple_format) do |text|
|
2
|
-
|
3
|
-
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
|
4
|
-
text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph
|
5
|
-
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
|
6
|
-
text.insert 0, start_tag
|
7
|
-
text << "</p>"
|
4
|
+
ActionView::Base.new.simple_format(text)
|
8
5
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
AutoHtml.add_filter(:vimeo).with(:width => 440, :height => 248, :show_title => false, :fullscreen => true, :show_byline => false, :show_portrait => false) do |text, options|
|
2
2
|
text.gsub(/http:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/) do
|
3
3
|
vimeo_id = $2
|
4
|
-
|
5
4
|
width = options[:width]
|
6
5
|
height = options[:height]
|
7
|
-
|
8
6
|
allowfullscreen = options[:fullscreen]
|
9
7
|
fullscreen = options[:fullscreen] ? 1 : 0
|
10
8
|
show_title = options[:show_title] ? 1 : 0
|
@@ -1,6 +1,12 @@
|
|
1
|
-
AutoHtml.add_filter(:youtube).with(:width => 390, :height => 250) do |text, options|
|
2
|
-
|
1
|
+
AutoHtml.add_filter(:youtube).with(:width => 390, :height => 250, :frameborder => 0) do |text, options|
|
2
|
+
regex = /http:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?/
|
3
|
+
text.gsub(regex) do
|
3
4
|
youtube_id = $2
|
4
|
-
|
5
|
+
width = options[:width]
|
6
|
+
height = options[:height]
|
7
|
+
frameborder = options[:frameborder]
|
8
|
+
%{<iframe class="youtube-player" type="text/html" width="#{width}" height="#{height}" src="http://www.youtube.com/embed/#{youtube_id}" frameborder="#{frameborder}">
|
9
|
+
</iframe>}
|
5
10
|
end
|
6
|
-
end
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,6 @@
|
|
1
|
+
AutoHtml.add_filter(:youtube_js_api).with(:width => 390, :height => 250) do |text, options|
|
2
|
+
text.gsub(/http:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?/) do
|
3
|
+
youtube_id = $2
|
4
|
+
%{<object width="#{options[:width]}" height="#{options[:height]}"><param name="movie" value="http://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="http://www.youtube.com/v/#{youtube_id}?enablejsapi=1&playerapiid=ytplayer" type="application/x-shockwave-flash" wmode="transparent" width="#{options[:width]}" height="#{options[:height]}" allowscriptaccess="always"></embed></object>}
|
5
|
+
end
|
6
|
+
end
|
data/test/fixtures/schema.rb
CHANGED
@@ -14,6 +14,11 @@ end
|
|
14
14
|
class AutoHtmlForTest < Test::Unit::TestCase
|
15
15
|
include FixtureSetup
|
16
16
|
|
17
|
+
def test_transform_on_initialization
|
18
|
+
@article = Article.new(:body => 'Yo!')
|
19
|
+
assert_equal '<p>Yo!</p>', @article.body_html
|
20
|
+
end
|
21
|
+
|
17
22
|
def test_transform_after_save
|
18
23
|
@article = Article.new(:body => 'Yo!')
|
19
24
|
@article.save!
|
data/test/test_helper.rb
CHANGED
data/test/unit/auto_html_test.rb
CHANGED
@@ -21,5 +21,15 @@ class AutoHtmlTest < Test::Unit::TestCase
|
|
21
21
|
result = auto_html("Check the logo: http://rors.org/images/rails.png. Visit: http://rubyonrails.org") { simple_format; image; link }
|
22
22
|
assert_equal '<p>Check the logo: <img src="http://rors.org/images/rails.png" alt=""/>. Visit: <a href="http://rubyonrails.org">http://rubyonrails.org</a></p>', result
|
23
23
|
end
|
24
|
+
|
25
|
+
def test_should_return_blank_if_input_is_blank
|
26
|
+
result = auto_html("") { simple_format; image; link }
|
27
|
+
assert_equal "", result
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_not_apply_simple_format_if_input_is_nil
|
31
|
+
result = auto_html(nil) { simple_format; image; link }
|
32
|
+
assert_equal "", result
|
33
|
+
end
|
24
34
|
|
25
35
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../unit_test_helper'
|
2
|
+
|
3
|
+
class YouTubeJsApiTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_transform
|
6
|
+
result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o') { youtube_js_api }
|
7
|
+
assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/BwNrmYRiX_o?enablejsapi=1&playerapiid=ytplayer"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/BwNrmYRiX_o?enablejsapi=1&playerapiid=ytplayer" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250" allowscriptaccess="always"></embed></object>', result
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_transform2
|
11
|
+
result = auto_html('http://www.youtube.com/watch?v=3-ewi9saKg8&eurl=http%3A%2F%2Fvukajlija.com%2Fvideo%2Fklipovi%3Fstrana%3D6&feature=player_embedded') { youtube_js_api }
|
12
|
+
assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/3-ewi9saKg8?enablejsapi=1&playerapiid=ytplayer"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/3-ewi9saKg8?enablejsapi=1&playerapiid=ytplayer" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250" allowscriptaccess="always"></embed></object>', result
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_transform3
|
16
|
+
result = auto_html('http://www.youtube.com/watch?v=Mw8KJ29qph0&feature=related') { youtube_js_api }
|
17
|
+
assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/Mw8KJ29qph0?enablejsapi=1&playerapiid=ytplayer"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Mw8KJ29qph0?enablejsapi=1&playerapiid=ytplayer" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250" allowscriptaccess="always"></embed></object>', result
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_transform_url_without_www
|
21
|
+
result = auto_html('http://youtube.com/watch?v=BwNrmYRiX_o') { youtube_js_api }
|
22
|
+
assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/BwNrmYRiX_o?enablejsapi=1&playerapiid=ytplayer"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/BwNrmYRiX_o?enablejsapi=1&playerapiid=ytplayer" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250" allowscriptaccess="always"></embed></object>', result
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_transform_with_options
|
26
|
+
result = auto_html('http://www.youtube.com/watch?v=ZA1NoOOoaNw') { youtube_js_api(:width => 300, :height => 250) }
|
27
|
+
assert_equal '<object width="300" height="250"><param name="movie" value="http://www.youtube.com/v/ZA1NoOOoaNw?enablejsapi=1&playerapiid=ytplayer"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ZA1NoOOoaNw?enablejsapi=1&playerapiid=ytplayer" type="application/x-shockwave-flash" wmode="transparent" width="300" height="250" allowscriptaccess="always"></embed></object>', result
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -4,27 +4,32 @@ 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 '<
|
7
|
+
assert_equal '<iframe class="youtube-player" type="text/html" width="390" height="250" src="http://www.youtube.com/embed/BwNrmYRiX_o" frameborder="0">
|
8
|
+
</iframe>', result
|
8
9
|
end
|
9
10
|
|
10
11
|
def test_transform2
|
11
|
-
result = auto_html('http://www.youtube.com/watch?v=
|
12
|
-
assert_equal '<
|
12
|
+
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 }
|
13
|
+
assert_equal '<iframe class="youtube-player" type="text/html" width="390" height="250" src="http://www.youtube.com/embed/BwNrmYRiX_o" frameborder="0">
|
14
|
+
</iframe>', result
|
13
15
|
end
|
14
16
|
|
15
17
|
def test_transform3
|
16
|
-
result = auto_html('http://www.youtube.com/watch?v=
|
17
|
-
assert_equal '<
|
18
|
+
result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o&feature=related') { youtube }
|
19
|
+
assert_equal '<iframe class="youtube-player" type="text/html" width="390" height="250" src="http://www.youtube.com/embed/BwNrmYRiX_o" frameborder="0">
|
20
|
+
</iframe>', result
|
18
21
|
end
|
19
22
|
|
20
23
|
def test_transform_url_without_www
|
21
24
|
result = auto_html('http://youtube.com/watch?v=BwNrmYRiX_o') { youtube }
|
22
|
-
assert_equal '<
|
25
|
+
assert_equal '<iframe class="youtube-player" type="text/html" width="390" height="250" src="http://www.youtube.com/embed/BwNrmYRiX_o" frameborder="0">
|
26
|
+
</iframe>', result
|
23
27
|
end
|
24
28
|
|
25
29
|
def test_transform_with_options
|
26
|
-
result = auto_html('http://www.youtube.com/watch?v=
|
27
|
-
assert_equal '<
|
30
|
+
result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o') { youtube(:width => 300, :height => 255, :frameborder => 1) }
|
31
|
+
assert_equal '<iframe class="youtube-player" type="text/html" width="300" height="255" src="http://www.youtube.com/embed/BwNrmYRiX_o" frameborder="1">
|
32
|
+
</iframe>', result
|
28
33
|
end
|
29
34
|
|
30
|
-
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 1.3.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Dejan Simic
|
@@ -9,7 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-08-14 00:00:00 +02:00
|
13
19
|
default_executable:
|
14
20
|
dependencies: []
|
15
21
|
|
@@ -20,12 +26,12 @@ executables: []
|
|
20
26
|
extensions: []
|
21
27
|
|
22
28
|
extra_rdoc_files:
|
23
|
-
- README.
|
29
|
+
- README.md
|
24
30
|
files:
|
25
31
|
- .gitignore
|
26
|
-
- CHANGELOG.
|
32
|
+
- CHANGELOG.md
|
27
33
|
- MIT-LICENCE
|
28
|
-
- README.
|
34
|
+
- README.md
|
29
35
|
- Rakefile
|
30
36
|
- VERSION.yml
|
31
37
|
- auto_html.gemspec
|
@@ -43,6 +49,7 @@ files:
|
|
43
49
|
- lib/auto_html/filters/simple_format.rb
|
44
50
|
- lib/auto_html/filters/vimeo.rb
|
45
51
|
- lib/auto_html/filters/youtube.rb
|
52
|
+
- lib/auto_html/filters/youtube_js_api.rb
|
46
53
|
- rails/init.rb
|
47
54
|
- test/fixture_setup.rb
|
48
55
|
- test/fixtures/database.yml
|
@@ -59,6 +66,7 @@ files:
|
|
59
66
|
- test/unit/filters/sanitize_test.rb
|
60
67
|
- test/unit/filters/simple_format_test.rb
|
61
68
|
- test/unit/filters/vimeo_test.rb
|
69
|
+
- test/unit/filters/youtube_js_api_test.rb
|
62
70
|
- test/unit/filters/youtube_test.rb
|
63
71
|
- test/unit/unit_test_helper.rb
|
64
72
|
has_rdoc: true
|
@@ -71,21 +79,27 @@ rdoc_options:
|
|
71
79
|
require_paths:
|
72
80
|
- lib
|
73
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
74
83
|
requirements:
|
75
84
|
- - ">="
|
76
85
|
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
77
89
|
version: "0"
|
78
|
-
version:
|
79
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
80
92
|
requirements:
|
81
93
|
- - ">="
|
82
94
|
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
83
98
|
version: "0"
|
84
|
-
version:
|
85
99
|
requirements: []
|
86
100
|
|
87
101
|
rubyforge_project:
|
88
|
-
rubygems_version: 1.3.
|
102
|
+
rubygems_version: 1.3.7
|
89
103
|
signing_key:
|
90
104
|
specification_version: 3
|
91
105
|
summary: Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document
|
@@ -104,5 +118,6 @@ test_files:
|
|
104
118
|
- test/unit/filters/sanitize_test.rb
|
105
119
|
- test/unit/filters/simple_format_test.rb
|
106
120
|
- test/unit/filters/vimeo_test.rb
|
121
|
+
- test/unit/filters/youtube_js_api_test.rb
|
107
122
|
- test/unit/filters/youtube_test.rb
|
108
123
|
- test/unit/unit_test_helper.rb
|
data/CHANGELOG.rdoc
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
== 1.2.1, released 2009-10-28
|
2
|
-
|
3
|
-
* more options for vimeo filter
|
4
|
-
* switch to gemcutter
|
5
|
-
|
6
|
-
== 1.2.0, released 2009-09-26
|
7
|
-
|
8
|
-
* link filter now uses Rails' link discovery engine. Closes: http://github.com/dejan/auto_html/issues#issue/2 and http://github.com/dejan/auto_html/issues#issue/3 if Rails 2.3+ is in use.
|
9
|
-
* added dailymotion filter
|
10
|
-
* added sanitize filter
|
11
|
-
|
12
|
-
== 1.1.2, released 2009-09-24
|
13
|
-
|
14
|
-
* link filter fix. Closes: http://github.com/dejan/auto_html/issues#issue/2
|
15
|
-
|
16
|
-
== 1.1.1, released 2009-09-06
|
17
|
-
|
18
|
-
* test_helper fix
|
19
|
-
|
20
|
-
== 1.1.0, released 2009-09-05
|
21
|
-
|
22
|
-
* Plugin gemified
|
23
|
-
* AutoHtmlFor.options[:htmlized_attribute_suffix] is now AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]. Closes gh-1
|
24
|
-
* Removed deezer filter since deezer.com no longer provides sharing of this kind
|
25
|
-
|
26
|
-
== 1.0.0
|
27
|
-
|
28
|
-
* Stuff described here: http://www.elctech.com/projects/auto_html-plugin
|
29
|
-
|
data/README.rdoc
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
= auto_html
|
2
|
-
|
3
|
-
Rails plugin for transforming urls to appropriate resource (image, link, YouTube, Vimeo video,...). Check out the {live demo}[http://auto_html.rors.org].
|
4
|
-
|
5
|
-
|
6
|
-
== Synopsis
|
7
|
-
|
8
|
-
auto_html plugin is the perfect choice if you don't want to bother visitors with rich HTML editor or markup code, but you still want to allow them to embed video, images, links and more on your site, purely by pasting URL.
|
9
|
-
|
10
|
-
Let's say you have model Comment with attribute body. Create another column in table Comments called body_html. Now have something like this:
|
11
|
-
|
12
|
-
class Comment < ActiveRecord::Base
|
13
|
-
auto_html_for :body do
|
14
|
-
html_escape
|
15
|
-
image
|
16
|
-
youtube :width => 400, :height => 250
|
17
|
-
link :target => "_blank", :rel => "nofollow"
|
18
|
-
simple_format
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
... and you'll have this behaviour:
|
23
|
-
|
24
|
-
Comment.create(:body => 'Hey check out this cool video: http://www.youtube.com/watch?v=WdsGihou8J4')
|
25
|
-
=> #<Comment id: 123, body: 'Hey check out this cool video: http://www.youtube.com/watch?v=WdsGihou8J4', body_html: '<p>Hey check out this cool video: <object height="250" width="400"><param name="movie" value="http://www.youtube.com/v/WdsGihou8J4" /><param name="wmode" value="transparent" /><embed src="http://www.youtube.com/v/WdsGihou8J4" type="application/x-shockwave-flash" height="250" wmode="transparent" width="400"></embed></object></p>'>
|
26
|
-
|
27
|
-
Note that order of invoking filters is important, ie. you want html_escape as first and link amongst last, so that it doesn't transform youtube URL to plain link.
|
28
|
-
|
29
|
-
|
30
|
-
Now all you have to do is to display it in template without escaping, since plugin took care of that:
|
31
|
-
|
32
|
-
<% for comment in @comments %>
|
33
|
-
<li><%= comment.body_html %></li>
|
34
|
-
<% end %>
|
35
|
-
|
36
|
-
|
37
|
-
If you need to display preview, no problem. Have something like this as action in your controller:
|
38
|
-
|
39
|
-
def preview
|
40
|
-
comment = Comment.new(params[:comment])
|
41
|
-
comment.auto_html_prepare
|
42
|
-
render :text => comment.body_html
|
43
|
-
end
|
44
|
-
|
45
|
-
Plugin is highly customizable, and you can easily create new filters that will transform user input any way you like. For instance, this is the image filter that comes bundled with plugin:
|
46
|
-
|
47
|
-
AutoHtml.add_filter(:image) do |text|
|
48
|
-
text.gsub(/http:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
|
49
|
-
%|<img src="#{match}" alt=""/>|
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
== Bundled filters
|
55
|
-
|
56
|
-
For filter list and options they support check: http://github.com/dejan/auto_html/tree/master/lib/auto_html/filters
|
57
|
-
|
58
|
-
|
59
|
-
== Install
|
60
|
-
|
61
|
-
=== Important note on versions
|
62
|
-
|
63
|
-
As from version 1.2.0 auto_html uses Rails' engine for discovering links. There are some bugs with that engine in versions under Rails 2.3.2. so it's recommended you use auto_html 1.1.2 in that case, since internal engine is used in that version.
|
64
|
-
|
65
|
-
Rails:: auto_html
|
66
|
-
<= 2.3.1:: 1.1.2
|
67
|
-
>= 2.3.2:: 1.2.1
|
68
|
-
|
69
|
-
|
70
|
-
=== As a gem
|
71
|
-
|
72
|
-
To enable the library in your Rails 2.1 (or greater) project, use the gem configuration method in "config/environment.rb"
|
73
|
-
|
74
|
-
Rails::Initializer.run do |config|
|
75
|
-
config.gem 'dejan-auto_html', :version => '~> 1.2.1', :lib => 'auto_html', :source => 'http://gemcutter.org'
|
76
|
-
end
|
77
|
-
|
78
|
-
=== As a Rails plugin
|
79
|
-
|
80
|
-
script/plugin install git://github.com/dejan/auto_html.git
|
81
|
-
|
82
|
-
|
83
|
-
== Links:
|
84
|
-
|
85
|
-
* http://auto_html.rors.org
|
86
|
-
* http://www.elctech.com/projects/auto_html-plugin
|
87
|
-
|
88
|
-
|
89
|
-
== Credits
|
90
|
-
|
91
|
-
Author:: {Dejan Simic}[http://github.com/dejan]
|
92
|
-
Contributor:: {Claudio Perez Gamayo}[http://github.com/crossblaim]
|