auto_html 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.rdoc +24 -0
- data/MIT-LICENCE +20 -0
- data/README.rdoc +92 -0
- data/Rakefile +26 -0
- data/VERSION.yml +4 -0
- data/auto_html.gemspec +92 -0
- data/lib/auto_html.rb +9 -0
- data/lib/auto_html/auto_html_for.rb +40 -0
- data/lib/auto_html/base.rb +11 -0
- data/lib/auto_html/builder.rb +22 -0
- data/lib/auto_html/filter.rb +24 -0
- data/lib/auto_html/filters/dailymotion.rb +6 -0
- data/lib/auto_html/filters/google_video.rb +6 -0
- data/lib/auto_html/filters/html_escape.rb +9 -0
- data/lib/auto_html/filters/image.rb +5 -0
- data/lib/auto_html/filters/link.rb +5 -0
- data/lib/auto_html/filters/sanitize.rb +6 -0
- data/lib/auto_html/filters/simple_format.rb +8 -0
- data/lib/auto_html/filters/vimeo.rb +6 -0
- data/lib/auto_html/filters/youtube.rb +6 -0
- data/rails/init.rb +3 -0
- data/test/fixture_setup.rb +9 -0
- data/test/fixtures/database.yml +5 -0
- data/test/fixtures/schema.rb +10 -0
- data/test/functional/auto_html_for_options_test.rb +25 -0
- data/test/functional/auto_html_for_test.rb +29 -0
- data/test/test_helper.rb +6 -0
- data/test/unit/auto_html_test.rb +25 -0
- data/test/unit/filters/dailymotion_test.rb +20 -0
- data/test/unit/filters/google_video_test.rb +15 -0
- data/test/unit/filters/html_escape_test.rb +15 -0
- data/test/unit/filters/image_test.rb +45 -0
- data/test/unit/filters/link_test.rb +50 -0
- data/test/unit/filters/sanitize_test.rb +36 -0
- data/test/unit/filters/simple_format_test.rb +15 -0
- data/test/unit/filters/vimeo_test.rb +30 -0
- data/test/unit/filters/youtube_test.rb +30 -0
- data/test/unit/unit_test_helper.rb +3 -0
- metadata +108 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
test.sqlite3
|
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
== 1.2.0, released 2009-09-26
|
2
|
+
|
3
|
+
* 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.
|
4
|
+
* added dailymotion filter
|
5
|
+
* added sanitize filter
|
6
|
+
|
7
|
+
== 1.1.2, released 2009-09-24
|
8
|
+
|
9
|
+
* link filter fix. Closes: http://github.com/dejan/auto_html/issues#issue/2
|
10
|
+
|
11
|
+
== 1.1.1, released 2009-09-06
|
12
|
+
|
13
|
+
* test_helper fix
|
14
|
+
|
15
|
+
== 1.1.0, released 2009-09-05
|
16
|
+
|
17
|
+
* Plugin gemified
|
18
|
+
* AutoHtmlFor.options[:htmlized_attribute_suffix] is now AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]. Closes gh-1
|
19
|
+
* Removed deezer filter since deezer.com no longer provides sharing of this kind
|
20
|
+
|
21
|
+
== 1.0.0
|
22
|
+
|
23
|
+
* Stuff described here: http://www.elctech.com/projects/auto_html-plugin
|
24
|
+
|
data/MIT-LICENCE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Dejan Simic
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,92 @@
|
|
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.0
|
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.0', :lib => 'auto_html', :source => 'http://gems.github.com'
|
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]
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
desc 'Default: run tests'
|
4
|
+
task :default => :test
|
5
|
+
|
6
|
+
desc 'Test AutoHtml'
|
7
|
+
Rake::TestTask.new(:test) do |t|
|
8
|
+
t.pattern = 'test/**/*_test.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
gem.name = "auto_html"
|
15
|
+
gem.summary = %{Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document}
|
16
|
+
gem.email = "desimic@gmail.com"
|
17
|
+
gem.homepage = "http://github.com/dejan/auto_html"
|
18
|
+
gem.description = "Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document"
|
19
|
+
gem.authors = ["Dejan Simic"]
|
20
|
+
gem.files.exclude 'test.sqlite3'
|
21
|
+
gem.has_rdoc = false
|
22
|
+
end
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
25
|
+
end
|
26
|
+
|
data/VERSION.yml
ADDED
data/auto_html.gemspec
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{auto_html}
|
8
|
+
s.version = "1.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Dejan Simic"]
|
12
|
+
s.date = %q{2009-09-26}
|
13
|
+
s.description = %q{Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document}
|
14
|
+
s.email = %q{desimic@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"CHANGELOG.rdoc",
|
21
|
+
"MIT-LICENCE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION.yml",
|
25
|
+
"auto_html.gemspec",
|
26
|
+
"lib/auto_html.rb",
|
27
|
+
"lib/auto_html/auto_html_for.rb",
|
28
|
+
"lib/auto_html/base.rb",
|
29
|
+
"lib/auto_html/builder.rb",
|
30
|
+
"lib/auto_html/filter.rb",
|
31
|
+
"lib/auto_html/filters/dailymotion.rb",
|
32
|
+
"lib/auto_html/filters/google_video.rb",
|
33
|
+
"lib/auto_html/filters/html_escape.rb",
|
34
|
+
"lib/auto_html/filters/image.rb",
|
35
|
+
"lib/auto_html/filters/link.rb",
|
36
|
+
"lib/auto_html/filters/sanitize.rb",
|
37
|
+
"lib/auto_html/filters/simple_format.rb",
|
38
|
+
"lib/auto_html/filters/vimeo.rb",
|
39
|
+
"lib/auto_html/filters/youtube.rb",
|
40
|
+
"rails/init.rb",
|
41
|
+
"test/fixture_setup.rb",
|
42
|
+
"test/fixtures/database.yml",
|
43
|
+
"test/fixtures/schema.rb",
|
44
|
+
"test/functional/auto_html_for_options_test.rb",
|
45
|
+
"test/functional/auto_html_for_test.rb",
|
46
|
+
"test/test_helper.rb",
|
47
|
+
"test/unit/auto_html_test.rb",
|
48
|
+
"test/unit/filters/dailymotion_test.rb",
|
49
|
+
"test/unit/filters/google_video_test.rb",
|
50
|
+
"test/unit/filters/html_escape_test.rb",
|
51
|
+
"test/unit/filters/image_test.rb",
|
52
|
+
"test/unit/filters/link_test.rb",
|
53
|
+
"test/unit/filters/sanitize_test.rb",
|
54
|
+
"test/unit/filters/simple_format_test.rb",
|
55
|
+
"test/unit/filters/vimeo_test.rb",
|
56
|
+
"test/unit/filters/youtube_test.rb",
|
57
|
+
"test/unit/unit_test_helper.rb"
|
58
|
+
]
|
59
|
+
s.homepage = %q{http://github.com/dejan/auto_html}
|
60
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
61
|
+
s.require_paths = ["lib"]
|
62
|
+
s.rubygems_version = %q{1.3.5}
|
63
|
+
s.summary = %q{Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document}
|
64
|
+
s.test_files = [
|
65
|
+
"test/fixture_setup.rb",
|
66
|
+
"test/fixtures/schema.rb",
|
67
|
+
"test/functional/auto_html_for_options_test.rb",
|
68
|
+
"test/functional/auto_html_for_test.rb",
|
69
|
+
"test/test_helper.rb",
|
70
|
+
"test/unit/auto_html_test.rb",
|
71
|
+
"test/unit/filters/dailymotion_test.rb",
|
72
|
+
"test/unit/filters/google_video_test.rb",
|
73
|
+
"test/unit/filters/html_escape_test.rb",
|
74
|
+
"test/unit/filters/image_test.rb",
|
75
|
+
"test/unit/filters/link_test.rb",
|
76
|
+
"test/unit/filters/sanitize_test.rb",
|
77
|
+
"test/unit/filters/simple_format_test.rb",
|
78
|
+
"test/unit/filters/vimeo_test.rb",
|
79
|
+
"test/unit/filters/youtube_test.rb",
|
80
|
+
"test/unit/unit_test_helper.rb"
|
81
|
+
]
|
82
|
+
|
83
|
+
if s.respond_to? :specification_version then
|
84
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
85
|
+
s.specification_version = 3
|
86
|
+
|
87
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
88
|
+
else
|
89
|
+
end
|
90
|
+
else
|
91
|
+
end
|
92
|
+
end
|
data/lib/auto_html.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module AutoHtmlFor
|
2
|
+
|
3
|
+
# default options that can be overridden on the global level
|
4
|
+
@@auto_html_for_options = {
|
5
|
+
:htmlized_attribute_suffix => '_html'
|
6
|
+
}
|
7
|
+
mattr_reader :auto_html_for_options
|
8
|
+
|
9
|
+
def self.included(base)
|
10
|
+
base.extend(ClassMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def auto_html_for(raw_attrs, &proc)
|
15
|
+
include AutoHtmlFor::InstanceMethods
|
16
|
+
before_save :auto_html_prepare
|
17
|
+
|
18
|
+
define_method("auto_html_prepare") do
|
19
|
+
auto_html_methods = self.methods.select { |m| m=~/^auto_html_prepare_/ }
|
20
|
+
auto_html_methods.each do |method|
|
21
|
+
self.send(method)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
[raw_attrs].flatten.each do |raw_attr|
|
26
|
+
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
|
+
self.send(raw_attr.to_s + suffix + "=",
|
31
|
+
auto_html(self.send(raw_attr), &proc))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module InstanceMethods
|
38
|
+
include AutoHtml
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module AutoHtml
|
2
|
+
class Builder
|
3
|
+
|
4
|
+
@@filters = {}
|
5
|
+
|
6
|
+
def initialize(text)
|
7
|
+
@text = text.dup
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.add_filter(name, &block)
|
11
|
+
filter = Filter.new(block)
|
12
|
+
@@filters.merge!(name => filter)
|
13
|
+
src = %|
|
14
|
+
def #{name}(options = {})
|
15
|
+
@text = @@filters["#{name}".to_sym].apply(@text, options)
|
16
|
+
end
|
17
|
+
|
|
18
|
+
class_eval src, __FILE__, __LINE__
|
19
|
+
filter
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AutoHtml
|
2
|
+
|
3
|
+
class Filter
|
4
|
+
def initialize(block)
|
5
|
+
@block = block
|
6
|
+
@options = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def with(options, &block)
|
10
|
+
@options = options
|
11
|
+
@block = block
|
12
|
+
end
|
13
|
+
|
14
|
+
def apply(text, options = {})
|
15
|
+
_options = @options && @options.merge(options)
|
16
|
+
if _options
|
17
|
+
@block.call(text.dup, _options)
|
18
|
+
else
|
19
|
+
@block.call(text.dup)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
AutoHtml.add_filter(:dailymotion).with(:width => 480, :height => 360) do |text, options|
|
2
|
+
text.gsub(/http:\/\/www\.dailymotion\.com.*\/video\/(.+)_*/) do
|
3
|
+
video_id = $1
|
4
|
+
%{<object type="application/x-shockwave-flash" data="http://www.dailymotion.com/swf/#{video_id}&related=0" width="#{options[:width]}" height="#{options[:height]}"><param name="movie" value="http://www.dailymotion.com/swf/#{video_id}&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><a href="http://www.dailymotion.com/video/#{video_id}?embed=1"><img src="http://www.dailymotion.com/thumbnail/video/#{video_id}" width="#{options[:width]}" height="#{options[:height]}"/></a></object>}
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
AutoHtml.add_filter(:google_video).with(:width => 650, :height => 391) do |text, options|
|
2
|
+
text.gsub(/http:\/\/video\.google\.com\/videoplay\?docid\=(-?[0-9]*)[&\w;=\+_\-]*/) do
|
3
|
+
docid = $1
|
4
|
+
%{<object width="#{options[:width]}" height="#{options[:height]}"><param name="movie" value="http://video.google.com/googleplayer.swf?docid=#{docid}&hl=en&fs=true"></param><param name="wmode" value="transparent"></param><embed src="http://video.google.com/googleplayer.swf?docid=#{docid}" type="application/x-shockwave-flash" wmode="transparent" width="#{options[:width]}" height="#{options[:height]}"></embed></object>}
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
AutoHtml.add_filter(:simple_format) do |text|
|
2
|
+
start_tag = '<p>'
|
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>"
|
8
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
AutoHtml.add_filter(:vimeo).with(:width => 440, :height => 248) do |text, options|
|
2
|
+
text.gsub(/http:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/) do
|
3
|
+
vimeo_id = $2
|
4
|
+
%{<object width="#{options[:width]}" height="#{options[:height]}"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=#{vimeo_id}&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00adef&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=#{vimeo_id}&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00adef&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="#{options[:width]}" height="#{options[:height]}"></embed></object>}
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
AutoHtml.add_filter(:youtube).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}"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/#{youtube_id}" type="application/x-shockwave-flash" wmode="transparent" width="#{options[:width]}" height="#{options[:height]}"></embed></object>}
|
5
|
+
end
|
6
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
module FixtureSetup
|
2
|
+
def setup
|
3
|
+
fixtures_dir = File.dirname(__FILE__) + '/fixtures'
|
4
|
+
connections = YAML.load_file("#{fixtures_dir}/database.yml")
|
5
|
+
ActiveRecord::Base.establish_connection(connections['sqlite3'])
|
6
|
+
ActiveRecord::Migration.verbose = false
|
7
|
+
load "#{fixtures_dir}/schema.rb"
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
create_table "articles", :force => true do |t|
|
3
|
+
t.column "title", :string
|
4
|
+
t.column "body", :text
|
5
|
+
t.column "body_html", :text
|
6
|
+
t.column "body_htmlized", :text
|
7
|
+
t.column "created_at", :datetime
|
8
|
+
t.column "updated_at", :datetime
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require File.dirname(__FILE__) + '/../fixture_setup'
|
3
|
+
|
4
|
+
# store default so we can revert so that other tests use default option
|
5
|
+
default_suffix = AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
|
6
|
+
AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix] = '_htmlized'
|
7
|
+
|
8
|
+
class Article < ActiveRecord::Base
|
9
|
+
auto_html_for :body do
|
10
|
+
simple_format
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class AutoHtmlForTest < Test::Unit::TestCase
|
15
|
+
include FixtureSetup
|
16
|
+
|
17
|
+
def test_transform_after_save
|
18
|
+
@article = Article.new(:body => 'Yo!')
|
19
|
+
@article.save!
|
20
|
+
assert_equal '<p>Yo!</p>', @article.body_htmlized
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# reverting to default so that other tests use default option
|
25
|
+
AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix] = default_suffix
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require File.dirname(__FILE__) + '/../fixture_setup'
|
3
|
+
|
4
|
+
class Article < ActiveRecord::Base
|
5
|
+
auto_html_for :body do
|
6
|
+
html_escape
|
7
|
+
youtube(:width => 400, :height => 250)
|
8
|
+
image
|
9
|
+
link(:target => "_blank", :rel => "nofollow")
|
10
|
+
simple_format
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class AutoHtmlForTest < Test::Unit::TestCase
|
15
|
+
include FixtureSetup
|
16
|
+
|
17
|
+
def test_transform_after_save
|
18
|
+
@article = Article.new(:body => 'Yo!')
|
19
|
+
@article.save!
|
20
|
+
assert_equal '<p>Yo!</p>', @article.body_html
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_transform_after_update
|
24
|
+
@article = Article.create!(:body => 'Yo!')
|
25
|
+
@article.update_attributes(:body => 'http://vukajlija.com')
|
26
|
+
@article.save!
|
27
|
+
assert_equal '<p><a href="http://vukajlija.com" rel="nofollow" target="_blank">http://vukajlija.com</a></p>', @article.body_html
|
28
|
+
end
|
29
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/unit_test_helper'
|
2
|
+
|
3
|
+
class AutoHtmlTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_should_be_nil_no_filters_provided
|
6
|
+
result = auto_html("Hey check out my blog => http://rors.org") { }
|
7
|
+
assert_nil result
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_apply_simple_format_filter
|
11
|
+
result = auto_html("Hey check out my blog => http://rors.org") { simple_format }
|
12
|
+
assert_equal "<p>Hey check out my blog => http://rors.org</p>", result
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_apply_simple_format_and_image_filter
|
16
|
+
result = auto_html("Check the logo: http://rors.org/images/rails.png") { simple_format; image }
|
17
|
+
assert_equal '<p>Check the logo: <img src="http://rors.org/images/rails.png" alt=""/></p>', result
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_apply_simple_format_image_and_link_filter
|
21
|
+
result = auto_html("Check the logo: http://rors.org/images/rails.png. Visit: http://rubyonrails.org") { simple_format; image; link }
|
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
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../unit_test_helper'
|
2
|
+
|
3
|
+
class GoogleVideoTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_transform
|
6
|
+
result = auto_html("http://www.dailymotion.com/en/featured/video/xag4p2_tempsmorttv-episode-01_shortfilms") { dailymotion }
|
7
|
+
assert_equal '<object type="application/x-shockwave-flash" data="http://www.dailymotion.com/swf/xag4p2_tempsmorttv-episode-01_shortfilms&related=0" width="480" height="360"><param name="movie" value="http://www.dailymotion.com/swf/xag4p2_tempsmorttv-episode-01_shortfilms&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><a href="http://www.dailymotion.com/video/xag4p2_tempsmorttv-episode-01_shortfilms?embed=1"><img src="http://www.dailymotion.com/thumbnail/video/xag4p2_tempsmorttv-episode-01_shortfilms" width="480" height="360"/></a></object>', result
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_transform_with_tweaked_width
|
11
|
+
result = auto_html("http://www.dailymotion.com/related/x9cyf6/video/x9tinl_happy-tree-friends-as-you-wish-part_fun") { dailymotion :width => 500 }
|
12
|
+
assert_equal '<object type="application/x-shockwave-flash" data="http://www.dailymotion.com/swf/x9tinl_happy-tree-friends-as-you-wish-part_fun&related=0" width="500" height="360"><param name="movie" value="http://www.dailymotion.com/swf/x9tinl_happy-tree-friends-as-you-wish-part_fun&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><a href="http://www.dailymotion.com/video/x9tinl_happy-tree-friends-as-you-wish-part_fun?embed=1"><img src="http://www.dailymotion.com/thumbnail/video/x9tinl_happy-tree-friends-as-you-wish-part_fun" width="500" height="360"/></a></object>', result
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_transform_with_options
|
16
|
+
result = auto_html("http://www.dailymotion.com/video/xakv5i") { dailymotion(:width => 500, :height => 300) }
|
17
|
+
assert_equal '<object type="application/x-shockwave-flash" data="http://www.dailymotion.com/swf/xakv5i&related=0" width="500" height="300"><param name="movie" value="http://www.dailymotion.com/swf/xakv5i&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><a href="http://www.dailymotion.com/video/xakv5i?embed=1"><img src="http://www.dailymotion.com/thumbnail/video/xakv5i" width="500" height="300"/></a></object>', result
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../unit_test_helper'
|
2
|
+
|
3
|
+
class GoogleVideoTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_transform
|
6
|
+
result = auto_html("http://video.google.com/videoplay?docid=-7533500868750350977&ei=Xin8Sc-KBYeg2ALXkKymAQ&q=office+space&emb=1") { google_video }
|
7
|
+
assert_equal '<object width="650" height="391"><param name="movie" value="http://video.google.com/googleplayer.swf?docid=-7533500868750350977&hl=en&fs=true"></param><param name="wmode" value="transparent"></param><embed src="http://video.google.com/googleplayer.swf?docid=-7533500868750350977" type="application/x-shockwave-flash" wmode="transparent" width="650" height="391"></embed></object>', result
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_transform_with_options
|
11
|
+
result = auto_html("http://video.google.com/videoplay?docid=7442132741322615356") { google_video(:width => 500, :height => 300) }
|
12
|
+
assert_equal '<object width="500" height="300"><param name="movie" value="http://video.google.com/googleplayer.swf?docid=7442132741322615356&hl=en&fs=true"></param><param name="wmode" value="transparent"></param><embed src="http://video.google.com/googleplayer.swf?docid=7442132741322615356" type="application/x-shockwave-flash" wmode="transparent" width="500" height="300"></embed></object>', result
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../unit_test_helper'
|
2
|
+
|
3
|
+
class HtmlEscapeTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_trasform
|
6
|
+
result = auto_html("<script>alert(0)</script>") { html_escape }
|
7
|
+
assert_equal "<script>alert(0)</script>", result
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_trasform2
|
11
|
+
result = auto_html("<div>test</div>") { html_escape }
|
12
|
+
assert_equal "<div>test</div>", result
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../unit_test_helper'
|
2
|
+
|
3
|
+
class ImageTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_transform
|
6
|
+
result = auto_html('http://rors.org/images/rails.png') { image }
|
7
|
+
assert_equal '<img src="http://rors.org/images/rails.png" alt=""/>', result
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_dont_transform
|
11
|
+
result = auto_html('http://blog.phusion.nl/2009/04/16/phusions-one-year-anniversary-gift-phusion-passenger-220/') { image }
|
12
|
+
assert_equal 'http://blog.phusion.nl/2009/04/16/phusions-one-year-anniversary-gift-phusion-passenger-220/', result
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_transform2
|
16
|
+
result = auto_html('http://farm4.static.flickr.com/3459/3270173112_5099d3d730.jpg') { image }
|
17
|
+
assert_equal '<img src="http://farm4.static.flickr.com/3459/3270173112_5099d3d730.jpg" alt=""/>', result
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_transform3
|
21
|
+
result = auto_html('http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG') { image }
|
22
|
+
assert_equal '<img src="http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG" alt=""/>', result
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_transform4
|
26
|
+
result = auto_html('http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG') { image }
|
27
|
+
assert_equal '<img src="http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG" alt=""/>', result
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_transform5
|
31
|
+
result = auto_html('http://farm4.static.flickr.com/3664/3512431377_71b8d002ef.jpg?v=0') { image }
|
32
|
+
assert_equal '<img src="http://farm4.static.flickr.com/3664/3512431377_71b8d002ef.jpg?v=0" alt=""/>', result
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_transform6
|
36
|
+
result = auto_html('Do you like this logo http://rors.org/images/rails.png? Yeah?') { image }
|
37
|
+
assert_equal 'Do you like this logo <img src="http://rors.org/images/rails.png" alt=""/>? Yeah?', result
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_transform7
|
41
|
+
result = auto_html('http://tbn3.google.com/images?q=tbn:vS-jtEi9Xc8K6M:http://upload.wikimedia.org/wikipedia/commons/b/ba/Potturinn.jpeg') { image }
|
42
|
+
assert_equal '<img src="http://tbn3.google.com/images?q=tbn:vS-jtEi9Xc8K6M:http://upload.wikimedia.org/wikipedia/commons/b/ba/Potturinn.jpeg" alt=""/>', result
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../unit_test_helper'
|
2
|
+
|
3
|
+
class LinkTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_transform
|
6
|
+
result = auto_html("http://vukajlija.com") { link }
|
7
|
+
assert_equal '<a href="http://vukajlija.com">http://vukajlija.com</a>', result
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_transform_with_the_slash_at_the_end
|
11
|
+
result = auto_html("http://github.com/") { link }
|
12
|
+
assert_equal '<a href="http://github.com/">http://github.com/</a>', result
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_transform_with_param
|
16
|
+
result = auto_html('http://example.com/abc?query=ruby') { link }
|
17
|
+
assert_equal '<a href="http://example.com/abc?query=ruby">http://example.com/abc?query=ruby</a>', result
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_transform_with_param_and_trailing_dot
|
21
|
+
result = auto_html('http://example.com/abc?query=ruby.') { link }
|
22
|
+
assert_equal '<a href="http://example.com/abc?query=ruby">http://example.com/abc?query=ruby</a>.', result
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_transform_with_anchor_and_trailing_dot
|
26
|
+
result = auto_html('http://example.com/example#id=123.12.') { link }
|
27
|
+
assert_equal '<a href="http://example.com/example#id=123.12">http://example.com/example#id=123.12</a>.', result
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_transform_with_params
|
31
|
+
result = auto_html('http://www.youtube.com/watch?v=s5C5Zk4kobo&feature=related') { link }
|
32
|
+
assert_equal '<a href="http://www.youtube.com/watch?v=s5C5Zk4kobo&feature=related">http://www.youtube.com/watch?v=s5C5Zk4kobo&feature=related</a>', result
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_transform_with_commas
|
36
|
+
result = auto_html('http://www.dw-world.de/dw/article/0,,4708386,00.html?maca=ser-rss-ser-all-1494-rdf') { link }
|
37
|
+
assert_equal '<a href="http://www.dw-world.de/dw/article/0,,4708386,00.html?maca=ser-rss-ser-all-1494-rdf">http://www.dw-world.de/dw/article/0,,4708386,00.html?maca=ser-rss-ser-all-1494-rdf</a>', result
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_transform_complex_url
|
41
|
+
result = auto_html("http://www.google.com/#q=nikola+tesla&ct=tesla09&oi=ddle&fp=Xmf0jJ9P_V0") { link }
|
42
|
+
assert_equal '<a href="http://www.google.com/#q=nikola+tesla&ct=tesla09&oi=ddle&fp=Xmf0jJ9P_V0">http://www.google.com/#q=nikola+tesla&ct=tesla09&oi=ddle&fp=Xmf0jJ9P_V0</a>', result
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_transform_with_options
|
46
|
+
result = auto_html("http://rors.org") { link :rel => "nofollow", :target => "_blank" }
|
47
|
+
assert_equal '<a href="http://rors.org" rel="nofollow" target="_blank">http://rors.org</a>', result
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../unit_test_helper'
|
2
|
+
|
3
|
+
class SanitizeTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_trasform
|
6
|
+
result = auto_html("<script>alert(0)</script>") { sanitize }
|
7
|
+
assert_equal "", result
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_trasform2
|
11
|
+
result = auto_html("<div>test</div>") { sanitize }
|
12
|
+
assert_equal "<div>test</div>", result
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_trasform3
|
16
|
+
result = auto_html("<div>test</div>") { sanitize :tags => %w(div) }
|
17
|
+
assert_equal "<div>test</div>", result
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_trasform4
|
21
|
+
result = auto_html("<div>test</div>") { sanitize :tags => %w(p) }
|
22
|
+
assert_equal "test", result
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_trasform5
|
26
|
+
result = auto_html("<a rel='nofollow'>test</div>") { sanitize :tags => %w(a), :attributes => %w(href)}
|
27
|
+
assert_equal "<a>test", result
|
28
|
+
#
|
29
|
+
# from Rails doc:
|
30
|
+
#
|
31
|
+
# Please note that sanitizing user-provided text does not
|
32
|
+
# guarantee that the resulting markup is valid.
|
33
|
+
#
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../unit_test_helper'
|
2
|
+
|
3
|
+
class SimpleFormatTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_transform
|
6
|
+
result = auto_html('Hey check out my blog => http://rors.org') { simple_format }
|
7
|
+
assert_equal '<p>Hey check out my blog => http://rors.org</p>', result
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_trasform2
|
11
|
+
result = auto_html('Hey check out my code => http://github.com/dejan') { simple_format }
|
12
|
+
assert_equal '<p>Hey check out my code => http://github.com/dejan</p>', result
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../unit_test_helper'
|
2
|
+
|
3
|
+
class VimeoTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_transform_url_with_www
|
6
|
+
result = auto_html('http://www.vimeo.com/3300155') { vimeo }
|
7
|
+
assert_equal '<object width="440" height="248"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=3300155&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00adef&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=3300155&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00adef&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="440" height="248"></embed></object>', result
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_transform_url_without_www
|
11
|
+
result = auto_html('http://vimeo.com/3300155') { vimeo }
|
12
|
+
assert_equal '<object width="440" height="248"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=3300155&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00adef&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=3300155&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00adef&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="440" height="248"></embed></object>', result
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_transform_url_with_params
|
16
|
+
result = auto_html('http://vimeo.com/4635843?pg=embed&sec=') { vimeo }
|
17
|
+
assert_equal '<object width="440" height="248"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=4635843&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00adef&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=4635843&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00adef&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="440" height="248"></embed></object>', result
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_transform_url_with_anchor
|
21
|
+
result = auto_html('http://vimeo.com/4695198#skirt') { vimeo }
|
22
|
+
assert_equal '<object width="440" height="248"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=4695198&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00adef&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=4695198&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00adef&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="440" height="248"></embed></object>', result
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_transform_with_options
|
26
|
+
result = auto_html("http://www.vimeo.com/1472714") { vimeo(:width => 300, :height => 250) }
|
27
|
+
assert_equal '<object width="300" height="250"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1472714&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00adef&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=1472714&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00adef&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="300" height="250"></embed></object>', result
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../unit_test_helper'
|
2
|
+
|
3
|
+
class YouTubeTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_transform
|
6
|
+
result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o') { youtube }
|
7
|
+
assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/BwNrmYRiX_o"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/BwNrmYRiX_o" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250"></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 }
|
12
|
+
assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/3-ewi9saKg8"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/3-ewi9saKg8" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250"></embed></object>', result
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_transform3
|
16
|
+
result = auto_html('http://www.youtube.com/watch?v=Mw8KJ29qph0&feature=related') { youtube }
|
17
|
+
assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/Mw8KJ29qph0"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/Mw8KJ29qph0" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250"></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 }
|
22
|
+
assert_equal '<object width="390" height="250"><param name="movie" value="http://www.youtube.com/v/BwNrmYRiX_o"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/BwNrmYRiX_o" type="application/x-shockwave-flash" wmode="transparent" width="390" height="250"></embed></object>', result
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_transform_with_options
|
26
|
+
result = auto_html('http://www.youtube.com/watch?v=ZA1NoOOoaNw') { youtube(:width => 300, :height => 250) }
|
27
|
+
assert_equal '<object width="300" height="250"><param name="movie" value="http://www.youtube.com/v/ZA1NoOOoaNw"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ZA1NoOOoaNw" type="application/x-shockwave-flash" wmode="transparent" width="300" height="250"></embed></object>', result
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: auto_html
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dejan Simic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-26 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document
|
17
|
+
email: desimic@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- .gitignore
|
26
|
+
- CHANGELOG.rdoc
|
27
|
+
- MIT-LICENCE
|
28
|
+
- README.rdoc
|
29
|
+
- Rakefile
|
30
|
+
- VERSION.yml
|
31
|
+
- auto_html.gemspec
|
32
|
+
- lib/auto_html.rb
|
33
|
+
- lib/auto_html/auto_html_for.rb
|
34
|
+
- lib/auto_html/base.rb
|
35
|
+
- lib/auto_html/builder.rb
|
36
|
+
- lib/auto_html/filter.rb
|
37
|
+
- lib/auto_html/filters/dailymotion.rb
|
38
|
+
- lib/auto_html/filters/google_video.rb
|
39
|
+
- lib/auto_html/filters/html_escape.rb
|
40
|
+
- lib/auto_html/filters/image.rb
|
41
|
+
- lib/auto_html/filters/link.rb
|
42
|
+
- lib/auto_html/filters/sanitize.rb
|
43
|
+
- lib/auto_html/filters/simple_format.rb
|
44
|
+
- lib/auto_html/filters/vimeo.rb
|
45
|
+
- lib/auto_html/filters/youtube.rb
|
46
|
+
- rails/init.rb
|
47
|
+
- test/fixture_setup.rb
|
48
|
+
- test/fixtures/database.yml
|
49
|
+
- test/fixtures/schema.rb
|
50
|
+
- test/functional/auto_html_for_options_test.rb
|
51
|
+
- test/functional/auto_html_for_test.rb
|
52
|
+
- test/test_helper.rb
|
53
|
+
- test/unit/auto_html_test.rb
|
54
|
+
- test/unit/filters/dailymotion_test.rb
|
55
|
+
- test/unit/filters/google_video_test.rb
|
56
|
+
- test/unit/filters/html_escape_test.rb
|
57
|
+
- test/unit/filters/image_test.rb
|
58
|
+
- test/unit/filters/link_test.rb
|
59
|
+
- test/unit/filters/sanitize_test.rb
|
60
|
+
- test/unit/filters/simple_format_test.rb
|
61
|
+
- test/unit/filters/vimeo_test.rb
|
62
|
+
- test/unit/filters/youtube_test.rb
|
63
|
+
- test/unit/unit_test_helper.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/dejan/auto_html
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document
|
92
|
+
test_files:
|
93
|
+
- test/fixture_setup.rb
|
94
|
+
- test/fixtures/schema.rb
|
95
|
+
- test/functional/auto_html_for_options_test.rb
|
96
|
+
- test/functional/auto_html_for_test.rb
|
97
|
+
- test/test_helper.rb
|
98
|
+
- test/unit/auto_html_test.rb
|
99
|
+
- test/unit/filters/dailymotion_test.rb
|
100
|
+
- test/unit/filters/google_video_test.rb
|
101
|
+
- test/unit/filters/html_escape_test.rb
|
102
|
+
- test/unit/filters/image_test.rb
|
103
|
+
- test/unit/filters/link_test.rb
|
104
|
+
- test/unit/filters/sanitize_test.rb
|
105
|
+
- test/unit/filters/simple_format_test.rb
|
106
|
+
- test/unit/filters/vimeo_test.rb
|
107
|
+
- test/unit/filters/youtube_test.rb
|
108
|
+
- test/unit/unit_test_helper.rb
|